rc_find_pids now returns RC_PIDLIST instead of a NULL terminated array.
This commit is contained in:
17
src/rc/rc.c
17
src/rc/rc.c
@@ -99,12 +99,7 @@ static RC_HOOK hook_out = 0;
|
||||
|
||||
struct termios *termios_orig = NULL;
|
||||
|
||||
typedef struct piditem
|
||||
{
|
||||
pid_t pid;
|
||||
LIST_ENTRY(piditem) entries;
|
||||
} PIDITEM;
|
||||
LIST_HEAD(, piditem) service_pids;
|
||||
RC_PIDLIST service_pids;
|
||||
|
||||
static void clean_failed(void)
|
||||
{
|
||||
@@ -138,8 +133,8 @@ static void clean_failed(void)
|
||||
static void cleanup(void)
|
||||
{
|
||||
if (applet && strcmp(applet, "rc") == 0) {
|
||||
PIDITEM *p1 = LIST_FIRST(&service_pids);
|
||||
PIDITEM *p2;
|
||||
RC_PID *p1 = LIST_FIRST(&service_pids);
|
||||
RC_PID *p2;
|
||||
|
||||
if (hook_out)
|
||||
rc_plugin_run(hook_out, runlevel);
|
||||
@@ -410,14 +405,14 @@ static int get_ksoftlevel(char *buffer, int buffer_len)
|
||||
|
||||
static void add_pid(pid_t pid)
|
||||
{
|
||||
PIDITEM *p = xmalloc(sizeof(*p));
|
||||
RC_PID *p = xmalloc(sizeof(*p));
|
||||
p->pid = pid;
|
||||
LIST_INSERT_HEAD(&service_pids, p, entries);
|
||||
}
|
||||
|
||||
static void remove_pid(pid_t pid)
|
||||
{
|
||||
PIDITEM *p;
|
||||
RC_PID *p;
|
||||
|
||||
LIST_FOREACH(p, &service_pids, entries)
|
||||
if (p->pid == pid) {
|
||||
@@ -437,7 +432,7 @@ static void handle_signal(int sig)
|
||||
int serrno = errno;
|
||||
char signame[10] = { '\0' };
|
||||
pid_t pid;
|
||||
PIDITEM *pi;
|
||||
RC_PID *pi;
|
||||
int status = 0;
|
||||
struct winsize ws;
|
||||
sigset_t sset;
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user