Line 0
Link Here
|
|
|
1 |
#include <unistd.h> |
2 |
#include <sys/types.h> |
3 |
#include <sys/stat.h> |
4 |
#include "strerr.h" |
5 |
#include "error.h" |
6 |
#include "wait.h" |
7 |
#include "coe.h" |
8 |
#include "fd.h" |
9 |
#include "env.h" |
10 |
#include "sig.h" |
11 |
#include "str.h" |
12 |
#include "byte.h" |
13 |
#include "pathexec.h" |
14 |
|
15 |
#define FATAL "svscan-start: fatal: " |
16 |
|
17 |
#define DOTS \ |
18 |
"........................................................................" \ |
19 |
"........................................................................" \ |
20 |
"........................................................................" \ |
21 |
"........................................................................" \ |
22 |
"........................................................................" |
23 |
|
24 |
int main(int argc,char **argv) |
25 |
{ |
26 |
int pi[2]; |
27 |
const char *args[5]; |
28 |
char *fn; |
29 |
int child; |
30 |
int r; |
31 |
int wstat; |
32 |
|
33 |
fn = argv[0] && argv[1] ? argv[1] : "/service"; |
34 |
|
35 |
if (pipe(pi) == -1) |
36 |
strerr_die4sys(100,FATAL,"unable to create pipe for svscan ",fn,": "); |
37 |
|
38 |
switch(child = fork()) { |
39 |
case -1: |
40 |
strerr_die4sys(111,FATAL,"unable to fork for readproctitle ",fn,": "); |
41 |
return; |
42 |
case 0: |
43 |
coe(pi[1]); |
44 |
if (fd_move(0,pi[0]) == -1) |
45 |
strerr_die4sys(111,FATAL,"unable to set up descriptors for readproctitle ",fn,": "); |
46 |
|
47 |
sig_block(sig_hangup); |
48 |
sig_block(sig_int); |
49 |
sig_block(sig_alarm); |
50 |
sig_block(sig_term); |
51 |
|
52 |
args[0] = "readproctitle"; |
53 |
args[1] = fn; |
54 |
args[2] = ":"; |
55 |
args[3] = DOTS; |
56 |
args[4] = 0; |
57 |
pathexec_run(*args,args,environ); |
58 |
strerr_die2sys(111,FATAL,"unable to start readproctitle: "); |
59 |
default: |
60 |
sleep(2); |
61 |
for (;;) { |
62 |
r = wait_nohang(&wstat); |
63 |
if (!r) break; |
64 |
if (r == -1) { |
65 |
if (errno == error_intr) continue; /* impossible */ |
66 |
break; |
67 |
} |
68 |
|
69 |
if (child == r) |
70 |
strerr_die2x(111,FATAL,"readproctitle child died"); |
71 |
} |
72 |
} |
73 |
|
74 |
if (fd_move(2,pi[1]) == -1) |
75 |
strerr_die4sys(111,FATAL,"unable to set up descriptors for svscan ",fn,": "); |
76 |
|
77 |
args[0] = "svscan"; |
78 |
args[1] = fn; |
79 |
args[2] = 0; |
80 |
pathexec_run(*args,args,environ); |
81 |
strerr_die4sys(111,FATAL,"unable to start svscan ",fn,": "); |
82 |
} |