diff options
-rw-r--r-- | debianutils/start_stop_daemon.c | 18 | ||||
-rw-r--r-- | include/libbb.h | 5 | ||||
-rw-r--r-- | libbb/pidfile.c | 5 | ||||
-rw-r--r-- | networking/ifupdown.c | 4 | ||||
-rw-r--r-- | networking/udhcp/dhcpc.c | 2 |
5 files changed, 20 insertions, 14 deletions
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c index d8a0d7d46..cf792709c 100644 --- a/debianutils/start_stop_daemon.c +++ b/debianutils/start_stop_daemon.c | |||
@@ -14,6 +14,8 @@ | |||
14 | #include <getopt.h> | 14 | #include <getopt.h> |
15 | #include <sys/resource.h> | 15 | #include <sys/resource.h> |
16 | 16 | ||
17 | /* Override ENABLE_FEATURE_PIDFILE */ | ||
18 | #define WANT_PIDFILE 1 | ||
17 | #include "libbb.h" | 19 | #include "libbb.h" |
18 | 20 | ||
19 | static int signal_nr = 15; | 21 | static int signal_nr = 15; |
@@ -46,7 +48,7 @@ static int pid_is_exec(pid_t pid, const char *name) | |||
46 | n = strcmp(execbuf, name); | 48 | n = strcmp(execbuf, name); |
47 | if (ENABLE_FEATURE_CLEAN_UP) | 49 | if (ENABLE_FEATURE_CLEAN_UP) |
48 | free(execbuf); | 50 | free(execbuf); |
49 | return ~n; /* nonzero (true) if execbuf == name */ | 51 | return !n; /* nonzero (true) if execbuf == name */ |
50 | } | 52 | } |
51 | 53 | ||
52 | static int pid_is_user(int pid, int uid) | 54 | static int pid_is_user(int pid, int uid) |
@@ -301,10 +303,14 @@ int start_stop_daemon_main(int argc, char **argv) | |||
301 | pid_t pid = vfork(); | 303 | pid_t pid = vfork(); |
302 | if (pid < 0) /* error */ | 304 | if (pid < 0) /* error */ |
303 | bb_perror_msg_and_die("vfork"); | 305 | bb_perror_msg_and_die("vfork"); |
304 | if (pid == 0) /* parent */ | 306 | if (pid != 0) { |
305 | return 0; | 307 | /* parent */ |
308 | /* why _exit? the child may have changed the stack, | ||
309 | * so "return 0" may do bad things */ | ||
310 | _exit(0); | ||
306 | } | 311 | } |
307 | /* child */ | 312 | /* child */ |
313 | setsid(); /* detach from controlling tty */ | ||
308 | /* Redirect stdio to /dev/null, close extra FDs. | 314 | /* Redirect stdio to /dev/null, close extra FDs. |
309 | * We do not actually daemonize because of DAEMON_ONLY_SANITIZE */ | 315 | * We do not actually daemonize because of DAEMON_ONLY_SANITIZE */ |
310 | bb_daemonize_or_rexec( | 316 | bb_daemonize_or_rexec( |
@@ -316,11 +322,7 @@ int start_stop_daemon_main(int argc, char **argv) | |||
316 | } | 322 | } |
317 | if (opt & OPT_MAKEPID) { | 323 | if (opt & OPT_MAKEPID) { |
318 | /* user wants _us_ to make the pidfile */ | 324 | /* user wants _us_ to make the pidfile */ |
319 | FILE *pidf = xfopen(pidfile, "w"); | 325 | write_pidfile(pidfile); |
320 | |||
321 | pid_t pidt = getpid(); | ||
322 | fprintf(pidf, "%d\n", pidt); | ||
323 | fclose(pidf); | ||
324 | } | 326 | } |
325 | if (opt & OPT_c) { | 327 | if (opt & OPT_c) { |
326 | struct bb_uidgid_t ugid; | 328 | struct bb_uidgid_t ugid; |
diff --git a/include/libbb.h b/include/libbb.h index 547b8f798..1cbcb41e4 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -619,8 +619,9 @@ llist_t *llist_rev(llist_t *list); | |||
619 | * llist_t *llist_add_to(llist_t *old_head, void *data) | 619 | * llist_t *llist_add_to(llist_t *old_head, void *data) |
620 | * etc does not result in smaller code... */ | 620 | * etc does not result in smaller code... */ |
621 | 621 | ||
622 | 622 | /* start_stop_daemon and (udhcpc with ifupdown) are special - they want to | |
623 | #if ENABLE_FEATURE_PIDFILE | 623 | * create pidfiles regardless of FEATURE_PIDFILE. */ |
624 | #if ENABLE_FEATURE_PIDFILE || defined(WANT_PIDFILE) | ||
624 | int write_pidfile(const char *path); | 625 | int write_pidfile(const char *path); |
625 | #define remove_pidfile(f) ((void)unlink(f)) | 626 | #define remove_pidfile(f) ((void)unlink(f)) |
626 | #else | 627 | #else |
diff --git a/libbb/pidfile.c b/libbb/pidfile.c index 79c3108fc..50af91f4e 100644 --- a/libbb/pidfile.c +++ b/libbb/pidfile.c | |||
@@ -6,9 +6,11 @@ | |||
6 | * | 6 | * |
7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
8 | */ | 8 | */ |
9 | |||
10 | /* Override ENABLE_FEATURE_PIDFILE */ | ||
11 | #define WANT_PIDFILE 1 | ||
9 | #include "libbb.h" | 12 | #include "libbb.h" |
10 | 13 | ||
11 | #if ENABLE_FEATURE_PIDFILE | ||
12 | int write_pidfile(const char *path) | 14 | int write_pidfile(const char *path) |
13 | { | 15 | { |
14 | int pid_fd; | 16 | int pid_fd; |
@@ -26,4 +28,3 @@ int write_pidfile(const char *path) | |||
26 | close(pid_fd); | 28 | close(pid_fd); |
27 | return 1; | 29 | return 1; |
28 | } | 30 | } |
29 | #endif | ||
diff --git a/networking/ifupdown.c b/networking/ifupdown.c index a15e1411e..040bbe389 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c | |||
@@ -536,8 +536,8 @@ static int manual_up_down(struct interface_defn_t *ifd, execfn *exec) | |||
536 | static int bootp_up(struct interface_defn_t *ifd, execfn *exec) | 536 | static int bootp_up(struct interface_defn_t *ifd, execfn *exec) |
537 | { | 537 | { |
538 | return execute("bootpc[[ --bootfile %bootfile%]] --dev %iface%" | 538 | return execute("bootpc[[ --bootfile %bootfile%]] --dev %iface%" |
539 | "[[ --server %server%]][[ --hwaddr %hwaddr%]] " | 539 | "[[ --server %server%]][[ --hwaddr %hwaddr%]]" |
540 | "--returniffail --serverbcast", ifd, exec); | 540 | " --returniffail --serverbcast", ifd, exec); |
541 | } | 541 | } |
542 | 542 | ||
543 | static int ppp_up(struct interface_defn_t *ifd, execfn *exec) | 543 | static int ppp_up(struct interface_defn_t *ifd, execfn *exec) |
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index b84a6785a..4bb90c2da 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -11,6 +11,8 @@ | |||
11 | #include <getopt.h> | 11 | #include <getopt.h> |
12 | #include <syslog.h> | 12 | #include <syslog.h> |
13 | 13 | ||
14 | /* Override ENABLE_FEATURE_PIDFILE - ifupdown needs our pidfile to always exist */ | ||
15 | #define WANT_PIDFILE 1 | ||
14 | #include "common.h" | 16 | #include "common.h" |
15 | #include "dhcpd.h" | 17 | #include "dhcpd.h" |
16 | #include "dhcpc.h" | 18 | #include "dhcpc.h" |