aboutsummaryrefslogtreecommitdiff
path: root/debianutils/start_stop_daemon.c
diff options
context:
space:
mode:
authorJérémie Koenig <jk@jk.fr.eu.org>2010-03-26 19:08:53 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-03-26 19:08:53 +0100
commitfbedacfc8caa1ec8f14e664a881cb0a93c8f8712 (patch)
tree6c08780bbaad6320149930bdbcfbee5a2eed9f5d /debianutils/start_stop_daemon.c
parent35fdb1bc9cb82fa5630c2d40ae49110ecd7c88ea (diff)
downloadbusybox-w32-fbedacfc8caa1ec8f14e664a881cb0a93c8f8712.tar.gz
busybox-w32-fbedacfc8caa1ec8f14e664a881cb0a93c8f8712.tar.bz2
busybox-w32-fbedacfc8caa1ec8f14e664a881cb0a93c8f8712.zip
Hurd compat fixes. Mostly dealing with absent PATH_MAX
Signed-off-by: Jérémie Koenig <jk@jk.fr.eu.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'debianutils/start_stop_daemon.c')
-rw-r--r--debianutils/start_stop_daemon.c33
1 files changed, 19 insertions, 14 deletions
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c
index dfc72f01a..0a0802575 100644
--- a/debianutils/start_stop_daemon.c
+++ b/debianutils/start_stop_daemon.c
@@ -89,16 +89,17 @@ enum {
89#define TEST (option_mask32 & OPT_TEST) 89#define TEST (option_mask32 & OPT_TEST)
90 90
91struct globals { 91struct globals {
92 struct pid_list *found; 92 struct pid_list *found_procs;
93 char *userspec; 93 char *userspec;
94 char *cmdname; 94 char *cmdname;
95 char *execname; 95 char *execname;
96 char *pidfile; 96 char *pidfile;
97 char *execname_cmpbuf;
98 unsigned execname_sizeof;
97 int user_id; 99 int user_id;
98 smallint signal_nr; 100 smallint signal_nr;
99} FIX_ALIASING; 101} FIX_ALIASING;
100#define G (*(struct globals*)&bb_common_bufsiz1) 102#define G (*(struct globals*)&bb_common_bufsiz1)
101#define found (G.found )
102#define userspec (G.userspec ) 103#define userspec (G.userspec )
103#define cmdname (G.cmdname ) 104#define cmdname (G.cmdname )
104#define execname (G.execname ) 105#define execname (G.execname )
@@ -118,7 +119,7 @@ struct globals {
118static int pid_is_exec(pid_t pid) 119static int pid_is_exec(pid_t pid)
119{ 120{
120 struct stat st; 121 struct stat st;
121 char buf[sizeof("/proc//exe") + sizeof(int)*3]; 122 char buf[sizeof("/proc/%u/exe") + sizeof(int)*3];
122 123
123 sprintf(buf, "/proc/%u/exe", (unsigned)pid); 124 sprintf(buf, "/proc/%u/exe", (unsigned)pid);
124 if (stat(buf, &st) < 0) 125 if (stat(buf, &st) < 0)
@@ -133,13 +134,13 @@ static int pid_is_exec(pid_t pid)
133static int pid_is_exec(pid_t pid) 134static int pid_is_exec(pid_t pid)
134{ 135{
135 ssize_t bytes; 136 ssize_t bytes;
136 char buf[PATH_MAX]; 137 char buf[sizeof("/proc/%u/cmdline") + sizeof(int)*3];
137 138
138 sprintf(buf, "/proc/%u/cmdline", (unsigned)pid); 139 sprintf(buf, "/proc/%u/cmdline", (unsigned)pid);
139 bytes = open_read_close(buf, buf, sizeof(buf) - 1); 140 bytes = open_read_close(buf, G.execname_cmpbuf, G.execname_sizeof);
140 if (bytes > 0) { 141 if (bytes > 0) {
141 buf[bytes] = '\0'; 142 G.execname_cmpbuf[bytes] = '\0';
142 return strcmp(buf, execname) == 0; 143 return strcmp(execname, G.execname_cmpbuf) == 0;
143 } 144 }
144 return 0; 145 return 0;
145} 146}
@@ -194,9 +195,9 @@ static void check(int pid)
194 return; 195 return;
195 } 196 }
196 p = xmalloc(sizeof(*p)); 197 p = xmalloc(sizeof(*p));
197 p->next = found; 198 p->next = G.found_procs;
198 p->pid = pid; 199 p->pid = pid;
199 found = p; 200 G.found_procs = p;
200} 201}
201 202
202static void do_pidfile(void) 203static void do_pidfile(void)
@@ -266,13 +267,13 @@ static int do_stop(void)
266 bb_error_msg_and_die("internal error, please report"); 267 bb_error_msg_and_die("internal error, please report");
267 } 268 }
268 269
269 if (!found) { 270 if (!G.found_procs) {
270 if (!QUIET) 271 if (!QUIET)
271 printf("no %s found; none killed\n", what); 272 printf("no %s found; none killed\n", what);
272 killed = -1; 273 killed = -1;
273 goto ret; 274 goto ret;
274 } 275 }
275 for (p = found; p; p = p->next) { 276 for (p = G.found_procs; p; p = p->next) {
276 if (TEST || kill(p->pid, signal_nr) == 0) { 277 if (TEST || kill(p->pid, signal_nr) == 0) {
277 killed++; 278 killed++;
278 } else { 279 } else {
@@ -282,7 +283,7 @@ static int do_stop(void)
282 } 283 }
283 if (!QUIET && killed) { 284 if (!QUIET && killed) {
284 printf("stopped %s (pid", what); 285 printf("stopped %s (pid", what);
285 for (p = found; p; p = p->next) 286 for (p = G.found_procs; p; p = p->next)
286 if (p->pid) 287 if (p->pid)
287 printf(" %u", (unsigned)p->pid); 288 printf(" %u", (unsigned)p->pid);
288 puts(")"); 289 puts(")");
@@ -365,6 +366,10 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv)
365 startas = execname; 366 startas = execname;
366 if (!execname) /* in case -a is given and -x is not */ 367 if (!execname) /* in case -a is given and -x is not */
367 execname = startas; 368 execname = startas;
369 if (execname) {
370 G.execname_sizeof = strlen(execname) + 1;
371 G.execname_cmpbuf = xmalloc(G.execname_sizeof + 1);
372 }
368 373
369// IF_FEATURE_START_STOP_DAEMON_FANCY( 374// IF_FEATURE_START_STOP_DAEMON_FANCY(
370// if (retry_arg) 375// if (retry_arg)
@@ -386,9 +391,9 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv)
386 return (opt & OPT_OKNODO) ? 0 : (i <= 0); 391 return (opt & OPT_OKNODO) ? 0 : (i <= 0);
387 } 392 }
388 393
389 if (found) { 394 if (G.found_procs) {
390 if (!QUIET) 395 if (!QUIET)
391 printf("%s is already running\n%u\n", execname, (unsigned)found->pid); 396 printf("%s is already running\n%u\n", execname, (unsigned)G.found_procs->pid);
392 return !(opt & OPT_OKNODO); 397 return !(opt & OPT_OKNODO);
393 } 398 }
394 399