]> err.no Git - dpkg/commitdiff
Make start-stop-daemon fork twice while daemonizing. Closes: #416179
authorGuillem Jover <guillem@debian.org>
Tue, 15 May 2007 02:53:36 +0000 (02:53 +0000)
committerGuillem Jover <guillem@debian.org>
Tue, 15 May 2007 02:53:36 +0000 (02:53 +0000)
ChangeLog
debian/changelog
utils/start-stop-daemon.c

index bcf0c6dcbe963dd1a7c31008418dc32ab125018a..d212e82096a625ebf5a2a3d92c9639dbf8ff90b5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-05-15  Guillem Jover  <guillem@debian.org>
+
+       * utils/start-stop-daemon.c (main): Move daemonizing code to ...
+       (daemonize): ... here. New function. Fork twice.
+
 2007-05-15  Guillem Jover  <guillem@debian.org>
 
        * scripts/update-alternatives.pl: Call fill_missing_slavepaths at the
index d9310ce28bada9dc498fb2d8ee1123aa9a0daf34..dedf4d9e19f5cc991f393bd5d4be1751141875ff 100644 (file)
@@ -19,6 +19,7 @@ dpkg (1.14.3) UNRELEASED; urgency=low
     'Info dir file'. Closes: #420766
   * Document in deb-control.5 that the control file can have '#'-style
     comments. Closes: #406481
+  * Make start-stop-daemon fork twice while daemonizing. Closes: #416179
 
   [ Updated dpkg-dev translations ]
   * French (Frédéric Bothamy). Closes: #423392
index 76c39a074c749a740d4dd890f096c449acb4320f..b0ad886d7ed3136600a84cc53c9d10eb88a4cab0 100644 (file)
@@ -252,6 +252,36 @@ xgettimeofday(struct timeval *tv)
                fatal("gettimeofday failed: %s", strerror(errno));
 }
 
+static void
+daemonize(void)
+{
+       pid_t pid;
+
+       if (quietmode < 0)
+               printf("Detaching to start %s...", startas);
+
+       pid = fork();
+       if (pid < 0)
+               fatal("Unable to do first fork.\n");
+       else if (pid) /* Parent */
+               exit(0);
+
+       /* Create a new session */
+#ifdef HAVE_SETSID
+       setsid();
+#else
+       setpgid(0, 0);
+#endif
+
+       pid = fork();
+       if (pid < 0)
+               fatal("Unable to do second fork.\n");
+       else if (pid) /* Parent */
+               exit(0);
+
+       if (quietmode < 0)
+               printf("done.\n");
+}
 
 static void
 push(struct pid_list **list, pid_t pid)
@@ -1307,19 +1337,7 @@ main(int argc, char **argv)
                printf("Starting %s...\n", startas);
        *--argv = startas;
        if (background) { /* ok, we need to detach this process */
-               int i;
-               if (quietmode < 0)
-                       printf("Detaching to start %s...", startas);
-               i = fork();
-               if (i<0) {
-                       fatal("Unable to fork.\n");
-               }
-               if (i) { /* parent */
-                       if (quietmode < 0)
-                               printf("done.\n");
-                       exit(0);
-               }
-                /* child continues here */
+               daemonize();
 
 #ifdef HAVE_TIOCNOTTY
                tty_fd=open("/dev/tty", O_RDWR);
@@ -1378,13 +1396,6 @@ main(int argc, char **argv)
                 /* now close all extra fds */
                for (i=getdtablesize()-1; i>=3; --i) close(i);
 #endif
-
-               /* create a new session */
-#ifdef HAVE_SETSID
-               setsid();
-#else
-               setpgid(0,0);
-#endif
        }
        execv(startas, argv);
        fatal("Unable to start %s: %s", startas, strerror(errno));