[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#133640: A fix



tag 133640 patch
thanks

Here is a patch to fix the problem.  I am not sure that it is the best
fix as I do not completely understand the internal interfaces.

What I have gathered is that do_procinit is a misnomer.  From
examining the other implementations (for OpenBSD, Linux and SunOS
based systems), I conclude that it is only used to verify that the
/proc filesystem is mounted and is not in fact an initialization
routine.  I reach this later conclusion based on the fact that it is
not consistently called.

My solution is to empty do_procinit (the Hurd implementation does not
depend on it) and introduce a new constructor (do_libpsinit) to
initialize some structures that we use for libps.  This fixes the
reported segmentation fault.

In fixing the segmentation fault, I ran across two other bugs in the
Hurd implementation: pid_is_user throws a fatal error if the pid does
not exist as does pid_is_cmd.  Instead, they should just return
failure.  The attached patch also fixes this.

Thanks.

--- start-stop-daemon.c.orig	Sat Feb 23 16:18:02 2002
+++ start-stop-daemon.c	Sat Feb 23 16:45:46 2002
@@ -628,9 +628,10 @@ pid_is_user(pid_t pid, uid_t uid)
 		return 0;
 	return (sb.st_uid == uid);
 	pstat = proc_stat_list_pid_proc_stat (procset, pid);
-	if (pstat == NULL)
-		fatal ("Error getting process information: NULL proc_stat struct");
-	proc_stat_set_flags (pstat, PSTAT_PID | PSTAT_OWNER_UID);
+	if (pstat)
+		proc_stat_set_flags (pstat, PSTAT_PID | PSTAT_OWNER_UID);
+	else
+		return 1;
 	return (pstat->owner_uid == uid);
 }
 
@@ -639,9 +640,10 @@ pid_is_cmd(pid_t pid, const char *name)
 {
 	struct proc_stat *pstat;
 	pstat = proc_stat_list_pid_proc_stat (procset, pid);
-	if (pstat == NULL)
-		fatal ("Error getting process information: NULL proc_stat struct");
-	proc_stat_set_flags (pstat, PSTAT_PID | PSTAT_ARGS);
+	if (pstat)
+		proc_stat_set_flags (pstat, PSTAT_PID | PSTAT_ARGS);
+	else
+		return 1;
 	return (!strcmp (name, pstat->args));
 }
 #endif /* OSHURD */
@@ -722,6 +724,14 @@ check_all (void *ptr)
 
 static void
 do_procinit(void)
+{
+        /* Nothing to do. */
+}
+
+static void do_libpsinit(void)  __attribute__ ((constructor));
+
+static void
+do_libpsinit(void)
 {
 	struct ps_context *context;
 	error_t err;



Reply to: