summaryrefslogtreecommitdiff
path: root/src/rc/start-stop-daemon.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2008-03-17 09:59:52 +0000
committerRoy Marples <roy@marples.name>2008-03-17 09:59:52 +0000
commit50a7697bf207e4919ce893bfc1604fd3a9d807de (patch)
tree1a9c9debaa4d5d862f42c8015826d35b0ce26d7c /src/rc/start-stop-daemon.c
parent40930d7d0a613aaf6fa124a5963afcae0c30ce7a (diff)
downloadopenrc-50a7697bf207e4919ce893bfc1604fd3a9d807de.tar.gz
openrc-50a7697bf207e4919ce893bfc1604fd3a9d807de.tar.bz2
openrc-50a7697bf207e4919ce893bfc1604fd3a9d807de.tar.xz
rc_find_pids now returns RC_PIDLIST instead of a NULL terminated array.
Diffstat (limited to 'src/rc/start-stop-daemon.c')
-rw-r--r--src/rc/start-stop-daemon.c50
1 files changed, 32 insertions, 18 deletions
diff --git a/src/rc/start-stop-daemon.c b/src/rc/start-stop-daemon.c
index bfb737a..9b1c109 100644
--- a/src/rc/start-stop-daemon.c
+++ b/src/rc/start-stop-daemon.c
@@ -73,6 +73,15 @@ static struct pam_conv conv = { NULL, NULL};
#include "rc.h"
#include "rc-misc.h"
+/* Some libc implementations don't define this */
+#ifndef LIST_FOREACH_SAFE
+#define LIST_FOREACH_SAFE(var, head, field, tvar) \
+ for ((var) = LIST_FIRST((head)); \
+ (var) && ((tvar) = LIST_NEXT((var), field), 1); \
+ (var) = (tvar))
+#endif
+
+
typedef struct scheduleitem
{
enum
@@ -301,11 +310,12 @@ static int do_stop(const char *const *argv, const char *cmd,
const char *pidfile, uid_t uid,int sig,
bool quiet, bool verbose, bool test)
{
- pid_t *pids;
+ RC_PIDLIST *pids;
+ RC_PID *pi;
+ RC_PID *np;
bool killed;
int nkilled = 0;
pid_t pid = 0;
- int i;
if (pidfile) {
if ((pid = get_pid(pidfile, quiet)) == -1)
@@ -317,27 +327,31 @@ static int do_stop(const char *const *argv, const char *cmd,
if (! pids)
return 0;
- for (i = 0; pids[i]; i++) {
+ LIST_FOREACH_SAFE(pi, pids, entries, np) {
if (test) {
if (! quiet)
- einfo("Would send signal %d to PID %d", sig, pids[i]);
+ einfo("Would send signal %d to PID %d",
+ sig, pi->pid);
nkilled++;
- continue;
- }
-
- if (verbose)
- ebegin("Sending signal %d to PID %d", sig, pids[i]);
- errno = 0;
- killed = (kill(pids[i], sig) == 0 || errno == ESRCH ? true : false);
- if (verbose)
- eend(killed ? 0 : 1, "%s: failed to send signal %d to PID %d: %s",
- applet, sig, pids[i], strerror(errno));
- if (! killed) {
- nkilled = -1;
} else {
- if (nkilled != -1)
- nkilled++;
+ if (verbose)
+ ebegin("Sending signal %d to PID %d",
+ sig, pi->pid);
+ errno = 0;
+ killed = (kill(pi->pid, sig) == 0 ||
+ errno == ESRCH ? true : false);
+ if (verbose)
+ eend(killed ? 0 : 1,
+ "%s: failed to send signal %d to PID %d: %s",
+ applet, sig, pi->pid, strerror(errno));
+ if (! killed) {
+ nkilled = -1;
+ } else {
+ if (nkilled != -1)
+ nkilled++;
+ }
}
+ free(pi);
}
free(pids);