[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#153547: start-stop-daemon: pid_is_exec may fails to achieve its goal



Package: dpkg
Version: 1.10.4
Severity: normal

While looking at start-stop-daemon source to help solving #151996 and
#151992, I noticed this piece of code :

static int
pid_is_exec(pid_t pid, const struct stat *esb)
{
        struct stat sb;
        char buf[32];

        sprintf(buf, "/proc/%d/exe", pid);
        if (stat(buf, &sb) != 0)
                return 0;
        return (sb.st_dev == esb->st_dev && sb.st_ino == esb->st_ino);
}

I guess this is meant to check that the process whose PID is found in
/var/run/foo.pid is actually a process executing the daemon started with
the foo command (using '--exec /usr/bin/foo'). 

There is a case where the test will fail, see for example:

- start-stop-daemon --start --exec /usr/bin/foo --pid-file /var/run/foo.pid
- then for some reason the (inode,dev) of /usr/bin/foo changes.
- then start-stop-daemon --stop --exec /usr/bin/foo --pid-file
/var/run/foo.pid won't stop foo, because it will conclude that the process
which PID is in /var/run/foo.pid is not running foo
 
This inode change happens when the package reinstalled or upgraded.
This maybe not be a problem since '/etc/init.d/foo stop' is called in .prerm
scrit of packages which have init scripts (dh_installinit does that
automatically). Still some packages don't use dh_installinit and don't restart
daemons during .prerm but after (ssh does this, hopefully, it doesn't use
--exec). 

Really, the inode change can happen sometimes (recovering from a backup,
manual operation on file system, etc.), and I feel start-stop-daemon could be
more robust against such cases, perhaps comparing path instead of inodes would
be the solution (maybe symlinks would be problematic ?).

Regards,

-Thomas

( this report is more or less the same as a message I recently posted on
dpkg-dev, but I corrected some points I had wrong ).

-- 
== Thomas Morin   --  GSM: 06 83 20 64 87   --   Tel: 02 98 05 98 54
== thomas.morin@enst-bretagne.fr    --    thomas.morin@tuxfamily.org
== PGP Id:8CEA233D   Key FP:503BF6CFD3AE8719377B832A02FB94E08CEA233D
--



-- 
To UNSUBSCRIBE, email to debian-dpkg-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org



Reply to: