From: Guillem Jover Date: Mon, 20 Mar 2006 01:22:43 +0000 (+0000) Subject: Change start-stop-daemon's --exec behaviour again on GNU/Linux to compare X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5fecd4d9e8d51b79eee3509e871838a74fae8702;p=dpkg Change start-stop-daemon's --exec behaviour again on GNU/Linux to compare the referred file pointed by the '/proc//exe' symlink, stripping any ' (deleted)' string and stating the result. Closes: #354867 --- diff --git a/ChangeLog b/ChangeLog index 724fce43..56ca6e44 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2006-03-20 Guillem Jover + + * utils/start-stop-daemon.c [OSLinux] (pid_is_exec): Revert back to + take a struct stat instead of an execname. Get the filename pointed + by the '/proc//exe' symlink, strip any ' (deleted)' string, and + stat that filename comparing the result with the new argument. + 2006-03-15 Guillem Jover * scripts/controllib.pl.in: Rename to ... diff --git a/debian/changelog b/debian/changelog index 689207c6..368884fa 100644 --- a/debian/changelog +++ b/debian/changelog @@ -17,6 +17,9 @@ dpkg (1.13.17~) UNRELEASED; urgency=low * Don't try to compile in SELinux support on GNU/kFreeBSD amd64. * Add new quiet option to dpkg-source to supress warnings. Closes: #355065 * Do not expand architecture aliases anymore in .dsc files. + * Change start-stop-daemon's --exec behaviour again on GNU/Linux to compare + the referred file pointed by the '/proc//exe' symlink, stripping + any ' (deleted)' string and stating the result. Closes: #354867 [ Updated man pages translations ] * Polish (Robert Luberda). Closes: #353782 diff --git a/utils/start-stop-daemon.c b/utils/start-stop-daemon.c index 658b8778..86075fa1 100644 --- a/utils/start-stop-daemon.c +++ b/utils/start-stop-daemon.c @@ -174,9 +174,7 @@ 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) -static int pid_is_exec(pid_t pid, const char *name); -#elif defined(OShpux) +#if defined(OSLinux) || defined(OShpux) static int pid_is_exec(pid_t pid, const struct stat *esb); #endif @@ -611,29 +609,27 @@ parse_options(int argc, char * const *argv) #if defined(OSLinux) static int -pid_is_exec(pid_t pid, const char *name) +pid_is_exec(pid_t pid, const struct stat *esb) { char lname[32]; - char *lcontents; - int lcontlen, nread, res; + char lcontents[_POSIX_PATH_MAX]; + const char deleted[] = " (deleted)"; + int nread; + struct stat sb; - /* 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); + nread = readlink(lname, lcontents, sizeof(lcontents)); + if (nread == -1) return 0; - } - if (nread < lcontlen) - lcontents[nread] = '\0'; - res = (strncmp(lcontents, name, lcontlen) == 0); - free(lcontents); + lcontents[nread] = '\0'; + if (strcmp(lcontents + nread - strlen(deleted), deleted) == 0) + lcontents[nread - strlen(deleted)] = '\0'; + + if (stat(lcontents, &sb) != 0) + return 0; - return res; + return (sb.st_dev == esb->st_dev && sb.st_ino == esb->st_ino); } @@ -763,9 +759,7 @@ pid_is_running(pid_t pid) static void check(pid_t pid) { -#if defined(OSLinux) - if (execname && !pid_is_exec(pid, execname)) -#elif defined(OShpux) +#if defined(OSLinux) || 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 */