From 77c70646513c5d1ceb9b0da1276b963d27a06fee Mon Sep 17 00:00:00 2001 From: Scott James Remnant Date: Tue, 22 Jun 2004 16:59:38 +0000 Subject: [PATCH] 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. --- ChangeLog | 6 +++ debian/changelog | 2 + utils/start-stop-daemon.c | 110 +++++++++++++++++++++++--------------- 3 files changed, 74 insertions(+), 44 deletions(-) diff --git a/ChangeLog b/ChangeLog index 337bace4..74faabba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Fri Jun 18 11:49:21 BST 2004 Ognyan Kulev + + * 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 * archtable: Requested the technical committee to make the mentioned diff --git a/debian/changelog b/debian/changelog index 4c8ad72e..e37f5057 100644 --- a/debian/changelog +++ b/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: diff --git a/utils/start-stop-daemon.c b/utils/start-stop-daemon.c index 7fc8f6b6..67360889 100644 --- a/utils/start-stop-daemon.c +++ b/utils/start-stop-daemon.c @@ -89,9 +89,6 @@ #ifdef HAVE_ERROR_H # include #endif -#ifdef HURD_IHASH_H - #include -#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 */ -- 2.39.5