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

s-s-d: Make pid_is_cmd() on the Hurd match on both argv[0] and argv[1]

This is needed to be able to handle the cases of binaries and
interpreted scripts, which cannot be distinguished reliably otherwise.

Reported-by: Mats Erik Andersson <mats.andersson@gisladisker.se>
Guillem Jover лет назад: 14
Родитель
Сommit
33cccfc40e
2 измененных файлов с 22 добавлено и 3 удалено
  1. 3 0
      debian/changelog
  2. 19 3
      utils/start-stop-daemon.c

+ 3 - 0
debian/changelog

@@ -19,6 +19,9 @@ dpkg (1.16.3) UNRELEASED; urgency=low
   * Change start-stop-daemon --exec on GNU/Hurd, FreeBSD, NetBSD, OpenBSD
     and Solaris to check for executables matching device and inode numbers
     instead of filenames.
+  * Change start-stop-daemon --name on GNU/Hurd to check the process' argv[1]
+    in addition to argv[0], to handle both binaries and interpreted scripts.
+    Reported by Mats Erik Andersson <mats.andersson@gisladisker.se>.
 
   [ Helge Kreutzmann ]
   * Fix a typo in man/dpkg-buildflags.1.

+ 19 - 3
utils/start-stop-daemon.c

@@ -1164,15 +1164,31 @@ static bool
 pid_is_cmd(pid_t pid, const char *name)
 {
 	struct proc_stat *ps;
-	const char *process_name;
+	size_t argv0_len;
+	const char *argv0;
+	const char *binary_name;
 
 	ps = get_proc_stat(pid, PSTAT_ARGS);
 	if (ps == NULL)
 		return false;
 
-	process_name = basename(proc_stat_args(ps));
+	argv0 = proc_stat_args(ps);
+	argv0_len = strlen(argv0) + 1;
 
-	return strcmp(process_name, name) == 0;
+	binary_name = basename(argv0);
+	if (strcmp(binary_name, name) == 0)
+		return true;
+
+	/* XXX: This is all kinds of ugly, but on the Hurd there's no way to
+	 * know the command name of a process, so we have to try to match
+	 * also on argv[1] for the case of an interpreted script. */
+	if (proc_stat_args_len(ps) > argv0_len) {
+		const char *script_name = basename(argv0 + argv0_len);
+
+		return strcmp(script_name, name) == 0;
+	}
+
+	return false;
 }
 #elif defined(OShpux)
 static bool