From: Guillem Jover Date: Mon, 23 Jan 2006 18:38:09 +0000 (+0000) Subject: Change start-stop-daemon's --exec option behaviour on GNU/Linux to X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f992043b37cd1c8bad7d10437069ccbfca26ce4;p=dpkg Change start-stop-daemon's --exec option behaviour on GNU/Linux to compare the filename pointed by '/proc//exe' instead of the inode and device numbers. Thanks to Vasilis Vasaitis . Closes: #337942 --- diff --git a/ChangeLog b/ChangeLog index c858932b..7c7f58fe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2006-01-23 Vasilis Vasaitis + + * utils/start-stop-daemon.c (pid_is_exec) [OSLinux]: Change function + prototype to take a constant string instead of a struct stat. Compare + the filename pointed by the '/proc//exe' symlink, instead of the + stat device and inode numbers. Fix all callers. + 2006-01-23 Frank Lichtenheld * scripts/dpkg-shlibdeps.pl: Rewrite of the script diff --git a/debian/changelog b/debian/changelog index 8db9763d..a1f78f28 100644 --- a/debian/changelog +++ b/debian/changelog @@ -90,6 +90,10 @@ dpkg (1.13.12) experimental; urgency=low * Add support for architecture wildcards, but for now they will only be exposed in debian/control files, not in binary nor source packages. Closes: #291939 + * Change start-stop-daemon's --exec option behaviour on GNU/Linux to + compare the filename pointed by '/proc//exe' instead of the inode + and device numbers. Thanks to Vasilis Vasaitis . + Closes: #337942 -- Frank Lichtenheld Mon, 23 Jan 2006 14:22:59 +0100 diff --git a/utils/start-stop-daemon.c b/utils/start-stop-daemon.c index 343905f8..223b4903 100644 --- a/utils/start-stop-daemon.c +++ b/utils/start-stop-daemon.c @@ -174,7 +174,9 @@ static void check(pid_t pid); static void do_pidfile(const char *name); static void do_stop(int signal_nr, int quietmode, int *n_killed, int *n_notkilled, int retry_nr); -#if defined(OSLinux) || defined(OShpux) +#if defined(OSLinux) +static int pid_is_exec(pid_t pid, const char *name); +#elif defined(OShpux) static int pid_is_exec(pid_t pid, const struct stat *esb); #endif @@ -608,15 +610,29 @@ parse_options(int argc, char * const *argv) #if defined(OSLinux) static int -pid_is_exec(pid_t pid, const struct stat *esb) +pid_is_exec(pid_t pid, const char *name) { - struct stat sb; - char buf[32]; - - sprintf(buf, "/proc/%d/exe", pid); - if (stat(buf, &sb) != 0) + char lname[32]; + char *lcontents; + int lcontlen, nread, res; + + /* Allow one extra character for the link contents, which should + * be enough to determine if the file names are the same. */ + lcontlen = strlen(name) + 1; + lcontents = xmalloc(lcontlen); + sprintf(lname, "/proc/%d/exe", pid); + nread = readlink(lname, lcontents, lcontlen); + if (nread == -1) { + free(lcontents); return 0; - return (sb.st_dev == esb->st_dev && sb.st_ino == esb->st_ino); + } + if (nread < lcontlen) + lcontents[nread] = '\0'; + + res = (strncmp(lcontents, name, lcontlen) == 0); + free(lcontents); + + return res; } @@ -746,7 +762,9 @@ pid_is_running(pid_t pid) static void check(pid_t pid) { -#if defined(OSLinux) || defined(OShpux) +#if defined(OSLinux) + if (execname && !pid_is_exec(pid, execname)) +#elif defined(OShpux) if (execname && !pid_is_exec(pid, &exec_stat)) #elif defined(OSHURD) || defined(OSFreeBSD) || defined(OSNetBSD) /* I will try this to see if it works */