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

Patches applied:

 * scott@netsplit.com--2004/dpkg--devo--1.10--patch-28
   restore amd64 support with that name

 * scott@netsplit.com--2004/dpkg--devo--1.10--patch-29
   fix s-s-d on the hurd

* archtable: Requested the technical committee to make the mentioned
decision -- we're going with amd64 (that'll please my boss :-)
* scripts/dpkg-architecture.pl: Likewise.
* utils/start-stop-daemon.c: Moved pid_is_running inside OSHURD sentry,
provided Hurd version.  Removed dependency on C99 code and replaced
constructor with an init function.
Scott James Remnant лет назад: 22
Родитель
Сommit
77c7064651
3 измененных файлов с 74 добавлено и 44 удалено
  1. 6 0
      ChangeLog
  2. 2 0
      debian/changelog
  3. 66 44
      utils/start-stop-daemon.c

+ 6 - 0
ChangeLog

@@ -1,3 +1,9 @@
+Fri Jun 18 11:49:21 BST 2004 Ognyan Kulev <ogi@fmi.uni-sofia.bg>
+
+  * utils/start-stop-daemon.c: Moved pid_is_running inside OSHURD sentry,
+  provided Hurd version.  Removed dependency on C99 code and replaced
+  constructor with an init function.
+
 Fri Jun 18 06:34:43 BST 2004 Scott James Remnant <scott@netsplit.com>
 
   * archtable: Requested the technical committee to make the mentioned

+ 2 - 0
debian/changelog

@@ -1,5 +1,7 @@
 dpkg (1.10.23) unstable; urgency=low
 
+  * Updated hurd start-stop-daemon support.  Closes: #133640, #254180.
+
   * Architecture Support:
     - Renamed x86-64 to amd64.  Closes: #252346, #254598.
   * Documentation:

+ 66 - 44
utils/start-stop-daemon.c

@@ -89,9 +89,6 @@
 #ifdef HAVE_ERROR_H
 #  include <error.h>
 #endif
-#ifdef HURD_IHASH_H
-  #include <hurd/ihash.h>
-#endif
 
 static int testmode = 0;
 static int quietmode = 0;
@@ -121,7 +118,7 @@ static int nicelevel = 0;
 
 static struct stat exec_stat;
 #if defined(OSHURD)
-static struct proc_stat_list *procset;
+static struct proc_stat_list *procset = NULL;
 #endif
 
 
@@ -638,38 +635,70 @@ pid_is_cmd(pid_t pid, const char *name)
 
 
 #if defined(OSHURD)
+static void
+init_procset(void)
+{
+	struct ps_context *context;
+	error_t err;
+
+	err = ps_context_create(getproc(), &context);
+	if (err)
+		error(1, err, "ps_context_create");
+
+	err = proc_stat_list_create(context, &procset);
+	if (err)
+		error(1, err, "proc_stat_list_create");
+
+	err = proc_stat_list_add_all(procset, 0, 0);
+	if (err)
+		error(1, err, "proc_stat_list_add_all");
+}
+
+static struct proc_stat *
+get_proc_stat (pid_t pid, ps_flags_t flags)
+{
+	struct proc_stat *ps;
+	ps_flags_t wanted_flags = PSTAT_PID | flags;
+
+	if (!procset)
+		init_procset();
+
+	ps = proc_stat_list_pid_proc_stat(procset, pid);
+	if (!ps)
+		return NULL;
+	if (proc_stat_set_flags(ps, wanted_flags))
+		return NULL;
+	if ((proc_stat_flags(ps) & wanted_flags) != wanted_flags)
+		return NULL;
+
+	return ps;
+}
+
 static int
 pid_is_user(pid_t pid, uid_t uid)
 {
-	struct stat sb;
-	char buf[32];
-	struct proc_stat *pstat;
+	struct proc_stat *ps;
 
-	sprintf(buf, "/proc/%d", pid);
-	if (stat(buf, &sb) != 0)
-		return 0;
-	return (sb.st_uid == uid);
-	pstat = proc_stat_list_pid_proc_stat (procset, pid);
-	if (pstat)
-		proc_stat_set_flags (pstat, PSTAT_PID | PSTAT_OWNER_UID);
-	else
-		return 1;
-	return (pstat->owner_uid == uid);
+	ps = get_proc_stat(pid, PSTAT_OWNER_UID);
+	return ps && proc_stat_owner_uid(ps) == uid;
 }
 
 static int
 pid_is_cmd(pid_t pid, const char *name)
 {
-	struct proc_stat *pstat;
-	pstat = proc_stat_list_pid_proc_stat (procset, pid);
-	if (pstat)
-		proc_stat_set_flags (pstat, PSTAT_PID | PSTAT_ARGS);
-	else
-		return 1;
-	return (!strcmp (name, pstat->args));
+	struct proc_stat *ps;
+
+	ps = get_proc_stat(pid, PSTAT_ARGS);
+	return ps && !strcmp(proc_stat_args(ps), name);
+}
+
+static int
+pid_is_running(pid_t pid)
+{
+	return get_proc_stat(pid, 0) != NULL;
 }
-#endif /* OSHURD */
 
+#else /* !OSHURD */
 
 static int
 pid_is_running(pid_t pid)
@@ -687,6 +716,8 @@ pid_is_running(pid_t pid)
 	return 1;
 }
 
+#endif /* OSHURD */
+
 static void
 check(pid_t pid)
 {
@@ -753,29 +784,20 @@ do_procinit(void)
 
 
 #if defined(OSHURD)
+static int
+check_proc_stat (struct proc_stat *ps)
+{
+	check(ps->pid);
+	return 0;
+}
+
 static void
 do_procinit(void)
 {
-	struct ps_context *context;
-	error_t err;
-
-	err = ps_context_create(getproc(), &context);
-	if (err)
-		error(1, err, "ps_context_create");
+	if (!procset)
+		init_procset();
 
-	err = proc_stat_list_create(context, &procset);
-	if (err)
-		error(1, err, "proc_stat_list_create");
-
-	err = proc_stat_list_add_all(procset, 0, 0);
-	if (err)
-		error(1, err, "proc_stat_list_add_all");
-
-	/* Check all pids */
-	HURD_IHASH_ITERATE (&context->procs, ptr) {
-		struct proc_stat *pstat = ptr;
-		check(pstat->pid);
-	}
+	proc_stat_list_for_each (procset, check_proc_stat);
 }
 #endif /* OSHURD */