Browse Source

s-s-d: Use the new process executable support in GNU/Hurd

This gives the actual executable name instead of having to look into
argv[0], which is not really correct, as the program doing execve()
can set that to anything it likes.

We have to check for the name being NULL or empty due to an initial
implementation bug.
Guillem Jover 7 years ago
parent
commit
10b38de76c
2 changed files with 15 additions and 0 deletions
  1. 3 0
      debian/changelog
  2. 12 0
      utils/start-stop-daemon.c

+ 3 - 0
debian/changelog

@@ -1,6 +1,9 @@
 dpkg (1.18.19) UNRELEASED; urgency=medium
 
   [ Guillem Jover ]
+  * Portability:
+    - On GNU/Hurd try to use the new process executable name attribute from
+      libps, to properly match on start-stop-daemon --exec.
   * Perl modules:
     - Fix Debian architecture wildcard parsing so that matching four-tuple
       matchings work. Missed in dpkg 1.18.11.

+ 12 - 0
utils/start-stop-daemon.c

@@ -1422,7 +1422,19 @@ pid_is_exec(pid_t pid, const struct stat *esb)
 	if (ps == NULL)
 		return false;
 
+	/* On old Hurd systems we have to use the argv[0] value, because
+	 * there is nothing better. */
 	filename = proc_stat_args(ps);
+#ifdef PSTAT_EXE
+	/* On new Hurd systems we can use the correct value, as long
+	 * as it's not NULL nor empty, as it was the case on the first
+	 * implementation. */
+	if (proc_stat_set_flags(ps, PSTAT_EXE) == 0 &&
+	    proc_stat_flags(ps) & PSTAT_EXE &&
+	    proc_stat_exe(ps) != NULL &&
+	    proc_stat_exe(ps)[0] != '\0')
+		filename = proc_stat_exe(ps);
+#endif
 
 	if (stat(filename, &sb) != 0)
 		return false;