diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-01-29 23:43:52 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-01-29 23:43:52 +0000 |
commit | 322661d025626d7a92482fec232d29f4450dd4b0 (patch) | |
tree | 66dcf2c776adea8556d2ebac5e3f7d8a27f05074 /runit | |
parent | 89ef65f02463b27313ff0eba806aa6e4aec10716 (diff) | |
download | busybox-w32-322661d025626d7a92482fec232d29f4450dd4b0.tar.gz busybox-w32-322661d025626d7a92482fec232d29f4450dd4b0.tar.bz2 busybox-w32-322661d025626d7a92482fec232d29f4450dd4b0.zip |
preparatory patch for -Wwrite-strings #6
Diffstat (limited to 'runit')
-rw-r--r-- | runit/sv.c | 72 |
1 files changed, 42 insertions, 30 deletions
diff --git a/runit/sv.c b/runit/sv.c index 6594e1451..6b154c1a8 100644 --- a/runit/sv.c +++ b/runit/sv.c | |||
@@ -7,33 +7,33 @@ | |||
7 | #include "runit_lib.h" | 7 | #include "runit_lib.h" |
8 | 8 | ||
9 | static char *action; | 9 | static char *action; |
10 | static char *acts; | 10 | static const char *acts; |
11 | static char *varservice = "/var/service/"; | 11 | static const char *varservice = "/var/service/"; |
12 | static char **service; | 12 | static char **service; |
13 | static char **servicex; | 13 | static char **servicex; |
14 | static unsigned services; | 14 | static unsigned services; |
15 | static unsigned rc = 0; | 15 | static unsigned rc; |
16 | static unsigned verbose = 0; | 16 | static unsigned verbose; |
17 | static unsigned long waitsec = 7; | 17 | static unsigned long waitsec = 7; |
18 | static unsigned kll = 0; | 18 | static unsigned kll; |
19 | static struct taia tstart, tnow, tdiff; | 19 | static struct taia tstart, tnow, tdiff; |
20 | static struct tai tstatus; | 20 | static struct tai tstatus; |
21 | 21 | ||
22 | static int (*act)(char*) = 0; | 22 | static int (*act)(const char*); |
23 | static int (*cbk)(char*) = 0; | 23 | static int (*cbk)(const char*); |
24 | 24 | ||
25 | static int curdir, fd, r; | 25 | static int curdir, fd, r; |
26 | static char svstatus[20]; | 26 | static char svstatus[20]; |
27 | 27 | ||
28 | #define usage() bb_show_usage() | 28 | #define usage() bb_show_usage() |
29 | 29 | ||
30 | static void fatal_cannot(char *m1) | 30 | static void fatal_cannot(const char *m1) |
31 | { | 31 | { |
32 | bb_perror_msg("fatal: cannot %s", m1); | 32 | bb_perror_msg("fatal: cannot %s", m1); |
33 | _exit(151); | 33 | _exit(151); |
34 | } | 34 | } |
35 | 35 | ||
36 | static void out(char *p, char *m1) | 36 | static void out(const char *p, const char *m1) |
37 | { | 37 | { |
38 | printf("%s%s: %s", p, *service, m1); | 38 | printf("%s%s: %s", p, *service, m1); |
39 | if (errno) { | 39 | if (errno) { |
@@ -51,15 +51,16 @@ static void out(char *p, char *m1) | |||
51 | #define TIMEOUT "timeout: " | 51 | #define TIMEOUT "timeout: " |
52 | #define KILL "kill: " | 52 | #define KILL "kill: " |
53 | 53 | ||
54 | static void fail(char *m1) { ++rc; out(FAIL, m1); } | 54 | static void fail(const char *m1) { ++rc; out(FAIL, m1); } |
55 | static void failx(char *m1) { errno = 0; fail(m1); } | 55 | static void failx(const char *m1) { errno = 0; fail(m1); } |
56 | static void warn_cannot(char *m1) { ++rc; out("warning: cannot ", m1); } | 56 | static void warn_cannot(const char *m1) { ++rc; out("warning: cannot ", m1); } |
57 | static void warnx_cannot(char *m1) { errno = 0; warn_cannot(m1); } | 57 | static void warnx_cannot(const char *m1) { errno = 0; warn_cannot(m1); } |
58 | static void ok(char *m1) { errno = 0; out(OK, m1); } | 58 | static void ok(const char *m1) { errno = 0; out(OK, m1); } |
59 | 59 | ||
60 | static int svstatus_get(void) | 60 | static int svstatus_get(void) |
61 | { | 61 | { |
62 | if ((fd = open_write("supervise/ok")) == -1) { | 62 | fd = open_write("supervise/ok"); |
63 | if (fd == -1) { | ||
63 | if (errno == ENODEV) { | 64 | if (errno == ENODEV) { |
64 | *acts == 'x' ? ok("runsv not running") | 65 | *acts == 'x' ? ok("runsv not running") |
65 | : failx("runsv not running"); | 66 | : failx("runsv not running"); |
@@ -69,7 +70,8 @@ static int svstatus_get(void) | |||
69 | return -1; | 70 | return -1; |
70 | } | 71 | } |
71 | close(fd); | 72 | close(fd); |
72 | if ((fd = open_read("supervise/status")) == -1) { | 73 | fd = open_read("supervise/status"); |
74 | if (fd == -1) { | ||
73 | warn_cannot("open supervise/status"); | 75 | warn_cannot("open supervise/status"); |
74 | return -1; | 76 | return -1; |
75 | } | 77 | } |
@@ -83,7 +85,7 @@ static int svstatus_get(void) | |||
83 | return 1; | 85 | return 1; |
84 | } | 86 | } |
85 | 87 | ||
86 | static unsigned svstatus_print(char *m) | 88 | static unsigned svstatus_print(const char *m) |
87 | { | 89 | { |
88 | int pid; | 90 | int pid; |
89 | int normallyup = 0; | 91 | int normallyup = 0; |
@@ -121,7 +123,7 @@ static unsigned svstatus_print(char *m) | |||
121 | return pid ? 1 : 2; | 123 | return pid ? 1 : 2; |
122 | } | 124 | } |
123 | 125 | ||
124 | static int status(char *unused) | 126 | static int status(const char *unused) |
125 | { | 127 | { |
126 | r = svstatus_get(); | 128 | r = svstatus_get(); |
127 | switch (r) { case -1: case 0: return 0; } | 129 | switch (r) { case -1: case 0: return 0; } |
@@ -156,8 +158,8 @@ static int checkscript(void) | |||
156 | return 0; | 158 | return 0; |
157 | } | 159 | } |
158 | if (!pid) { | 160 | if (!pid) { |
159 | prog[0] = "./check"; | 161 | prog[0] = (char*)"./check"; |
160 | prog[1] = 0; | 162 | prog[1] = NULL; |
161 | close(1); | 163 | close(1); |
162 | execve("check", prog, environ); | 164 | execve("check", prog, environ); |
163 | bb_perror_msg(WARN"cannot run %s/check", *service); | 165 | bb_perror_msg(WARN"cannot run %s/check", *service); |
@@ -171,7 +173,7 @@ static int checkscript(void) | |||
171 | return !wait_exitcode(w); | 173 | return !wait_exitcode(w); |
172 | } | 174 | } |
173 | 175 | ||
174 | static int check(char *a) | 176 | static int check(const char *a) |
175 | { | 177 | { |
176 | unsigned pid; | 178 | unsigned pid; |
177 | 179 | ||
@@ -200,15 +202,18 @@ static int check(char *a) | |||
200 | if ((!pid && tstart.sec.x > tstatus.x) || (pid && svstatus[17] != 'd')) | 202 | if ((!pid && tstart.sec.x > tstatus.x) || (pid && svstatus[17] != 'd')) |
201 | return 0; | 203 | return 0; |
202 | } | 204 | } |
203 | printf(OK); svstatus_print(*service); puts(""); /* will also flush the output */ | 205 | printf(OK); |
206 | svstatus_print(*service); | ||
207 | puts(""); /* will also flush the output */ | ||
204 | return 1; | 208 | return 1; |
205 | } | 209 | } |
206 | 210 | ||
207 | static int control(char *a) | 211 | static int control(const char *a) |
208 | { | 212 | { |
209 | if (svstatus_get() <= 0) return -1; | 213 | if (svstatus_get() <= 0) return -1; |
210 | if (svstatus[17] == *a) return 0; | 214 | if (svstatus[17] == *a) return 0; |
211 | if ((fd = open_write("supervise/control")) == -1) { | 215 | fd = open_write("supervise/control"); |
216 | if (fd == -1) { | ||
212 | if (errno != ENODEV) | 217 | if (errno != ENODEV) |
213 | warn_cannot("open supervise/control"); | 218 | warn_cannot("open supervise/control"); |
214 | else | 219 | else |
@@ -245,15 +250,20 @@ int sv_main(int argc, char **argv) | |||
245 | if (opt & 4) usage(); | 250 | if (opt & 4) usage(); |
246 | if (!(action = *argv++)) usage(); | 251 | if (!(action = *argv++)) usage(); |
247 | --argc; | 252 | --argc; |
248 | service = argv; services = argc; | 253 | service = argv; |
254 | services = argc; | ||
249 | if (!*service) usage(); | 255 | if (!*service) usage(); |
250 | 256 | ||
251 | taia_now(&tnow); tstart = tnow; | 257 | taia_now(&tnow); |
252 | if ((curdir = open_read(".")) == -1) | 258 | tstart = tnow; |
259 | curdir = open_read("."); | ||
260 | if (curdir == -1) | ||
253 | fatal_cannot("open current directory"); | 261 | fatal_cannot("open current directory"); |
254 | 262 | ||
255 | act = &control; acts = "s"; | 263 | act = &control; |
256 | if (verbose) cbk = ✓ | 264 | acts = "s"; |
265 | if (verbose) | ||
266 | cbk = ✓ | ||
257 | switch (*action) { | 267 | switch (*action) { |
258 | case 'x': case 'e': | 268 | case 'x': case 'e': |
259 | acts = "x"; break; | 269 | acts = "x"; break; |
@@ -289,7 +299,9 @@ int sv_main(int argc, char **argv) | |||
289 | cbk = ✓ | 299 | cbk = ✓ |
290 | break; | 300 | break; |
291 | } | 301 | } |
292 | act = &status; cbk = 0; break; | 302 | act = &status; |
303 | cbk = NULL; | ||
304 | break; | ||
293 | case 'r': | 305 | case 'r': |
294 | if (!str_diff(action, "restart")) { | 306 | if (!str_diff(action, "restart")) { |
295 | acts = "tcu"; | 307 | acts = "tcu"; |