Bug #166 » start-stop-daemon.patch
| dpkg-1.17.9/utils/start-stop-daemon.c 2014-04-30 05:57:25.000000000 +0000 → dpkg-1.17.9.netgear1/utils/start-stop-daemon.c 2014-05-22 17:51:12.000000000 +0000 | ||
|---|---|---|
|
# define OSHurd
|
||
|
#elif defined(__sun)
|
||
|
# define OSsunos
|
||
|
# include <procfs.h>
|
||
|
#elif defined(OPENBSD) || defined(__OpenBSD__)
|
||
|
# define OSOpenBSD
|
||
|
#elif defined(hpux)
|
||
| ... | ... | |
|
if (fp == NULL)
|
||
|
fatal("unable to open pidfile '%s' for writing", filename);
|
||
|
fprintf(fp, "%d\n", pid);
|
||
|
fprintf(fp, "%d\n", (int)pid);
|
||
|
if (fclose(fp))
|
||
|
fatal("unable to close pidfile '%s'", filename);
|
||
| ... | ... | |
|
return (sb.st_dev == esb->st_dev && sb.st_ino == esb->st_ino);
|
||
|
}
|
||
|
#elif defined(OSsunos)
|
||
|
static bool
|
||
|
pid_is_exec(pid_t pid, const struct stat *esb)
|
||
|
{
|
||
|
DIR *procdir;
|
||
|
struct dirent *entry;
|
||
|
char name[_POSIX_PATH_MAX + 1];
|
||
|
struct stat sb;
|
||
|
sprintf(name, "/proc/%d/object", (int)pid);
|
||
|
procdir = opendir(name);
|
||
|
if (!procdir)
|
||
|
return false;
|
||
|
while ((entry = readdir(procdir)) != NULL) {
|
||
|
sprintf(name, "/proc/%d/object/%s", (int)pid, entry->d_name);
|
||
|
if (stat(name, &sb) != 0)
|
||
|
continue;
|
||
|
if (sb.st_dev == esb->st_dev && sb.st_ino == esb->st_ino)
|
||
|
break;
|
||
|
}
|
||
|
closedir(procdir);
|
||
|
return (entry != NULL);
|
||
|
}
|
||
|
#elif defined(OSHurd)
|
||
|
static bool
|
||
|
pid_is_exec(pid_t pid, const struct stat *esb)
|
||
| ... | ... | |
|
return proc_ppid == ppid;
|
||
|
}
|
||
|
#elif defined(OSsunos)
|
||
|
static bool
|
||
|
pid_is_child(pid_t pid, pid_t ppid)
|
||
|
{
|
||
|
psinfo_t ps;
|
||
|
char buf[32];
|
||
|
FILE *f;
|
||
|
sprintf(buf, "/proc/%d/psinfo", (int)pid);
|
||
|
f = fopen(buf, "r");
|
||
|
if (!f)
|
||
|
return false;
|
||
|
if (fread(&ps, sizeof(ps), 1, f) != 1)
|
||
|
ps.pr_ppid = 0;
|
||
|
fclose(f);
|
||
|
return ps.pr_ppid == ppid;
|
||
|
}
|
||
|
#elif defined(OSHurd)
|
||
|
static bool
|
||
|
pid_is_child(pid_t pid, pid_t ppid)
|
||
| ... | ... | |
|
return false;
|
||
|
return (sb.st_uid == uid);
|
||
|
}
|
||
|
#elif defined(OSsunos)
|
||
|
static bool
|
||
|
pid_is_user(pid_t pid, uid_t uid)
|
||
|
{
|
||
|
struct stat sb;
|
||
|
char buf[32];
|
||
|
sprintf(buf, "/proc/%d", (int)pid);
|
||
|
if (stat(buf, &sb) != 0)
|
||
|
return false;
|
||
|
return (sb.st_uid == uid);
|
||
|
}
|
||
|
#elif defined(OSHurd)
|
||
|
static bool
|
||
|
pid_is_user(pid_t pid, uid_t uid)
|
||
| ... | ... | |
|
return strcmp(comm, name) == 0;
|
||
|
}
|
||
|
#elif defined(OSsunos)
|
||
|
static bool
|
||
|
pid_is_cmd(pid_t pid, const char *name)
|
||
|
{
|
||
|
psinfo_t ps;
|
||
|
char buf[32];
|
||
|
FILE *f;
|
||
|
sprintf(buf, "/proc/%d/psinfo", (int)pid);
|
||
|
f = fopen(buf, "r");
|
||
|
if (!f)
|
||
|
return false;
|
||
|
if (fread(&ps, sizeof(ps), 1, f) != 1)
|
||
|
ps.pr_fname[0] = '\0';
|
||
|
fclose(f);
|
||
|
return (!strcmp(name, ps.pr_fname));
|
||
|
}
|
||
|
#elif defined(OSHurd)
|
||
|
static bool
|
||
|
pid_is_cmd(pid_t pid, const char *name)
|
||
| ... | ... | |
|
else if (errno == ESRCH)
|
||
|
return false;
|
||
|
else
|
||
|
fatal("error checking pid %u status", pid);
|
||
|
fatal("error checking pid %u status", (unsigned)pid);
|
||
|
}
|
||
|
#endif
|
||
| ... | ... | |
|
while ((entry = readdir(procdir)) != NULL) {
|
||
|
enum status_code pid_status;
|
||
|
if (sscanf(entry->d_name, "%d", &pid) != 1)
|
||
|
if (sscanf(entry->d_name, "%d", (int*)&pid) != 1)
|
||
|
continue;
|
||
|
foundany++;
|
||
| ... | ... | |
|
if (testmode) {
|
||
|
if (quietmode <= 0)
|
||
|
printf("Would send signal %d to %d.\n",
|
||
|
sig_num, p->pid);
|
||
|
sig_num, (int)p->pid);
|
||
|
(*n_killed)++;
|
||
|
} else if (kill(p->pid, sig_num) == 0) {
|
||
|
pid_list_push(&killed, p->pid);
|
||
| ... | ... | |
|
} else {
|
||
|
if (sig_num)
|
||
|
warning("failed to kill %d: %s\n",
|
||
|
p->pid, strerror(errno));
|
||
|
(int)p->pid, strerror(errno));
|
||
|
(*n_notkilled)++;
|
||
|
}
|
||
|
}
|
||
| ... | ... | |
|
printf("Stopped %s (pid", what_stop);
|
||
|
for (p = killed; p; p = p->next)
|
||
|
printf(" %d", p->pid);
|
||
|
printf(" %d", (int)p->pid);
|
||
|
putchar(')');
|
||
|
if (retry_nr > 0)
|
||
|
printf(", retry #%d", retry_nr);
|
||