Package: dpkg
Version: 1.13.25
User: [EMAIL PROTECTED]
Usertags: s-s-d
Tags: patch

It's my current understanding that the --pidfile option will test that
a pidfile exists, and s-s-d will exit if on some iteration (with
--retry) the file has been removed.  However this is problemsome if it
sends a signal to a daemon, which responds by removing the pidfile
early on, then continuing to clean up for substantial amount of time.
When s-s-d exits, it should either ensure that no process matches, or
fail.  In the case of the --pidfile condition, I think "pidfile"
should be a static int, and non-existence of the specified pidfile
shouldn't cause s-s-d to exit if the static pid value is nonzero (if
it's not the first try) and the other conditions are met.  I think
it's okay to not track previous content of the pidfile.

Test the attached patch with:
cd /tmp
sh -c 'echo $$ >pidfile; trap "rm pidfile; sleep 4; exit" INT; while sleep 1; 
do :; done'
time ./start-stop-daemon --stop --verbose --pidfile ./pidfile --signal INT 
--retry 10


diff -ru 0/debian/changelog 1/debian/changelog
--- 0/debian/changelog  2008-01-07 05:13:14.000000000 -0500
+++ 1/debian/changelog  2008-01-15 10:25:31.000000000 -0500
@@ -1,3 +1,11 @@
+dpkg (1.14.15-0.1) unstable; urgency=low
+
+  * Non-maintainer upload.
+  * [S-S-D] Continue retrying if the pidfile doesn't exist but the process
+    still exists.
+
+ -- Justin Pryzby <[EMAIL PROTECTED]>  Tue, 15 Jan 2008 10:24:26 -0500
+
 dpkg (1.14.15) unstable; urgency=low
 
   [ Raphael Hertzog ]
diff -ru 0/utils/start-stop-daemon.c 1/utils/start-stop-daemon.c
--- 0/utils/start-stop-daemon.c 2008-01-07 03:19:15.000000000 -0500
+++ 1/utils/start-stop-daemon.c 2008-01-15 10:35:36.000000000 -0500
@@ -833,16 +833,21 @@
 do_pidfile(const char *name)
 {
        FILE *f;
-       pid_t pid;
+       static pid_t pid;
 
        f = fopen(name, "r");
-       if (f) {
-               if (fscanf(f, "%d", &pid) == 1)
-                       check(pid);
-               fclose(f);
-       } else if (errno != ENOENT)
+       if (f==NULL && errno != ENOENT) {
                fatal("open pidfile %s: %s", name, strerror(errno));
+       } else if (f!=NULL) {
+               if (fscanf(f, "%d", &pid)!=1 || pid==0) return;
+       }
+
+       /* The daemon may remove the pidfile quickly after receiving
+        * the first signal, but if the previously-read pid is still
+        * running, s-s-d might continue retrying. */
+       check(pid);
 
+       if (f!=NULL) fclose(f);
 }
 
 /* WTA: this  needs to be an autoconf check for /proc/pid existance.



-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to