start_stop_daemon: NOMMU fixes, round 2 by Alex Landau <landau_alex@yahoo.com>
authorDenis Vlasenko <vda.linux@googlemail.com>
Thu, 2 Aug 2007 10:14:29 +0000 (10:14 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Thu, 2 Aug 2007 10:14:29 +0000 (10:14 -0000)
dhcpc: fixed "ifupdown + udhcpc_without_pidpile_creation" bug

debianutils/start_stop_daemon.c
include/libbb.h
libbb/pidfile.c
networking/ifupdown.c
networking/udhcp/dhcpc.c

index d8a0d7d46adb697aafad746fd97ae07469c16e31..cf792709c4aa35036d6c0949b4000e7a182b9164 100644 (file)
@@ -14,6 +14,8 @@
 #include <getopt.h>
 #include <sys/resource.h>
 
+/* Override ENABLE_FEATURE_PIDFILE */
+#define WANT_PIDFILE 1
 #include "libbb.h"
 
 static int signal_nr = 15;
@@ -46,7 +48,7 @@ static int pid_is_exec(pid_t pid, const char *name)
        n = strcmp(execbuf, name);
        if (ENABLE_FEATURE_CLEAN_UP)
                free(execbuf);
-       return ~n; /* nonzero (true) if execbuf == name */
+       return !n; /* nonzero (true) if execbuf == name */
 }
 
 static int pid_is_user(int pid, int uid)
@@ -301,10 +303,14 @@ int start_stop_daemon_main(int argc, char **argv)
                pid_t pid = vfork();
                if (pid < 0) /* error */
                        bb_perror_msg_and_die("vfork");
-               if (pid == 0) /* parent */
-                       return 0;
+               if (pid != 0) {
+                       /* parent */
+                       /* why _exit? the child may have changed the stack,
+                        * so "return 0" may do bad things */
+                       _exit(0);
                }
                /* child */
+               setsid(); /* detach from controlling tty */
                /* Redirect stdio to /dev/null, close extra FDs.
                 * We do not actually daemonize because of DAEMON_ONLY_SANITIZE */
                bb_daemonize_or_rexec(
@@ -316,11 +322,7 @@ int start_stop_daemon_main(int argc, char **argv)
        }
        if (opt & OPT_MAKEPID) {
                /* user wants _us_ to make the pidfile */
-               FILE *pidf = xfopen(pidfile, "w");
-
-               pid_t pidt = getpid();
-               fprintf(pidf, "%d\n", pidt);
-               fclose(pidf);
+               write_pidfile(pidfile);
        }
        if (opt & OPT_c) {
                struct bb_uidgid_t ugid;
index 547b8f798181f1796a42ac270b52c81d5581eefc..1cbcb41e4fbcf245dba2a4dcf8bed391ab0f2daf 100644 (file)
@@ -619,8 +619,9 @@ llist_t *llist_rev(llist_t *list);
  *   llist_t *llist_add_to(llist_t *old_head, void *data)
  * etc does not result in smaller code... */
 
-
-#if ENABLE_FEATURE_PIDFILE
+/* start_stop_daemon and (udhcpc with ifupdown) are special - they want to
+ * create pidfiles regardless of FEATURE_PIDFILE. */
+#if ENABLE_FEATURE_PIDFILE || defined(WANT_PIDFILE)
 int write_pidfile(const char *path);
 #define remove_pidfile(f) ((void)unlink(f))
 #else
index 79c3108fc20c1f9ff2361fc937e624333c9d231b..50af91f4eed7dad886f8ab8eec62d0b9558e1775 100644 (file)
@@ -6,9 +6,11 @@
  *
  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  */
+
+/* Override ENABLE_FEATURE_PIDFILE */
+#define WANT_PIDFILE 1
 #include "libbb.h"
 
-#if ENABLE_FEATURE_PIDFILE
 int write_pidfile(const char *path)
 {
        int pid_fd;
@@ -26,4 +28,3 @@ int write_pidfile(const char *path)
        close(pid_fd);
        return 1;
 }
-#endif
index a15e1411e95416fa946aec4dd042be9ec7d22181..040bbe38965cbee39050ac3a3df736aae0475d5b 100644 (file)
@@ -536,8 +536,8 @@ static int manual_up_down(struct interface_defn_t *ifd, execfn *exec)
 static int bootp_up(struct interface_defn_t *ifd, execfn *exec)
 {
        return execute("bootpc[[ --bootfile %bootfile%]] --dev %iface%"
-                       "[[ --server %server%]][[ --hwaddr %hwaddr%]] "
-                       "--returniffail --serverbcast", ifd, exec);
+                       "[[ --server %server%]][[ --hwaddr %hwaddr%]]"
+                       " --returniffail --serverbcast", ifd, exec);
 }
 
 static int ppp_up(struct interface_defn_t *ifd, execfn *exec)
index b84a6785ae117922142256a2bf99b5bbadbc8e58..4bb90c2daf4ac2578d84e615bdc0312c8c8c99f9 100644 (file)
@@ -11,6 +11,8 @@
 #include <getopt.h>
 #include <syslog.h>
 
+/* Override ENABLE_FEATURE_PIDFILE - ifupdown needs our pidfile to always exist */
+#define WANT_PIDFILE 1
 #include "common.h"
 #include "dhcpd.h"
 #include "dhcpc.h"