Просмотр исходного кода

Change start-stop-daemon's --exec behaviour again on GNU/Linux to compare
the referred file pointed by the '/proc/<pid>/exe' symlink, stripping
any ' (deleted)' string and stating the result. Closes: #354867

Guillem Jover лет назад: 20
Родитель
Сommit
5fecd4d9e8
3 измененных файлов с 26 добавлено и 22 удалено
  1. 7 0
      ChangeLog
  2. 3 0
      debian/changelog
  3. 16 22
      utils/start-stop-daemon.c

+ 7 - 0
ChangeLog

@@ -1,3 +1,10 @@
+2006-03-20  Guillem Jover  <guillem@debian.org>
+
+	* 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/<pid>/exe' symlink, strip any ' (deleted)' string, and
+	stat that filename comparing the result with the new argument.
+
 2006-03-15  Guillem Jover  <guillem@debian.org>
 
 	* scripts/controllib.pl.in: Rename to ...

+ 3 - 0
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/<pid>/exe' symlink, stripping
+    any ' (deleted)' string and stating the result. Closes: #354867
 
   [ Updated man pages translations ]
   * Polish (Robert Luberda). Closes: #353782

+ 16 - 22
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 */