31 |
31 |
# define OSHurd
|
32 |
32 |
#elif defined(__sun)
|
33 |
33 |
# define OSsunos
|
|
34 |
# include <procfs.h>
|
34 |
35 |
#elif defined(OPENBSD) || defined(__OpenBSD__)
|
35 |
36 |
# define OSOpenBSD
|
36 |
37 |
#elif defined(hpux)
|
... | ... | |
396 |
397 |
if (fp == NULL)
|
397 |
398 |
fatal("unable to open pidfile '%s' for writing", filename);
|
398 |
399 |
|
399 |
|
fprintf(fp, "%d\n", pid);
|
|
400 |
fprintf(fp, "%d\n", (int)pid);
|
400 |
401 |
|
401 |
402 |
if (fclose(fp))
|
402 |
403 |
fatal("unable to close pidfile '%s'", filename);
|
... | ... | |
1184 |
1185 |
|
1185 |
1186 |
return (sb.st_dev == esb->st_dev && sb.st_ino == esb->st_ino);
|
1186 |
1187 |
}
|
|
1188 |
#elif defined(OSsunos)
|
|
1189 |
static bool
|
|
1190 |
pid_is_exec(pid_t pid, const struct stat *esb)
|
|
1191 |
{
|
|
1192 |
DIR *procdir;
|
|
1193 |
struct dirent *entry;
|
|
1194 |
char name[_POSIX_PATH_MAX + 1];
|
|
1195 |
struct stat sb;
|
|
1196 |
|
|
1197 |
sprintf(name, "/proc/%d/object", (int)pid);
|
|
1198 |
procdir = opendir(name);
|
|
1199 |
if (!procdir)
|
|
1200 |
return false;
|
|
1201 |
|
|
1202 |
while ((entry = readdir(procdir)) != NULL) {
|
|
1203 |
sprintf(name, "/proc/%d/object/%s", (int)pid, entry->d_name);
|
|
1204 |
if (stat(name, &sb) != 0)
|
|
1205 |
continue;
|
|
1206 |
if (sb.st_dev == esb->st_dev && sb.st_ino == esb->st_ino)
|
|
1207 |
break;
|
|
1208 |
}
|
|
1209 |
closedir(procdir);
|
|
1210 |
|
|
1211 |
return (entry != NULL);
|
|
1212 |
}
|
1187 |
1213 |
#elif defined(OSHurd)
|
1188 |
1214 |
static bool
|
1189 |
1215 |
pid_is_exec(pid_t pid, const struct stat *esb)
|
... | ... | |
1305 |
1331 |
|
1306 |
1332 |
return proc_ppid == ppid;
|
1307 |
1333 |
}
|
|
1334 |
#elif defined(OSsunos)
|
|
1335 |
static bool
|
|
1336 |
pid_is_child(pid_t pid, pid_t ppid)
|
|
1337 |
{
|
|
1338 |
psinfo_t ps;
|
|
1339 |
char buf[32];
|
|
1340 |
FILE *f;
|
|
1341 |
|
|
1342 |
sprintf(buf, "/proc/%d/psinfo", (int)pid);
|
|
1343 |
f = fopen(buf, "r");
|
|
1344 |
if (!f)
|
|
1345 |
return false;
|
|
1346 |
if (fread(&ps, sizeof(ps), 1, f) != 1)
|
|
1347 |
ps.pr_ppid = 0;
|
|
1348 |
fclose(f);
|
|
1349 |
|
|
1350 |
return ps.pr_ppid == ppid;
|
|
1351 |
}
|
1308 |
1352 |
#elif defined(OSHurd)
|
1309 |
1353 |
static bool
|
1310 |
1354 |
pid_is_child(pid_t pid, pid_t ppid)
|
... | ... | |
1372 |
1416 |
return false;
|
1373 |
1417 |
return (sb.st_uid == uid);
|
1374 |
1418 |
}
|
|
1419 |
#elif defined(OSsunos)
|
|
1420 |
static bool
|
|
1421 |
pid_is_user(pid_t pid, uid_t uid)
|
|
1422 |
{
|
|
1423 |
struct stat sb;
|
|
1424 |
char buf[32];
|
|
1425 |
|
|
1426 |
sprintf(buf, "/proc/%d", (int)pid);
|
|
1427 |
if (stat(buf, &sb) != 0)
|
|
1428 |
return false;
|
|
1429 |
return (sb.st_uid == uid);
|
|
1430 |
}
|
1375 |
1431 |
#elif defined(OSHurd)
|
1376 |
1432 |
static bool
|
1377 |
1433 |
pid_is_user(pid_t pid, uid_t uid)
|
... | ... | |
1436 |
1492 |
|
1437 |
1493 |
return strcmp(comm, name) == 0;
|
1438 |
1494 |
}
|
|
1495 |
#elif defined(OSsunos)
|
|
1496 |
static bool
|
|
1497 |
pid_is_cmd(pid_t pid, const char *name)
|
|
1498 |
{
|
|
1499 |
psinfo_t ps;
|
|
1500 |
char buf[32];
|
|
1501 |
FILE *f;
|
|
1502 |
|
|
1503 |
sprintf(buf, "/proc/%d/psinfo", (int)pid);
|
|
1504 |
f = fopen(buf, "r");
|
|
1505 |
if (!f)
|
|
1506 |
return false;
|
|
1507 |
if (fread(&ps, sizeof(ps), 1, f) != 1)
|
|
1508 |
ps.pr_fname[0] = '\0';
|
|
1509 |
fclose(f);
|
|
1510 |
|
|
1511 |
return (!strcmp(name, ps.pr_fname));
|
|
1512 |
}
|
1439 |
1513 |
#elif defined(OSHurd)
|
1440 |
1514 |
static bool
|
1441 |
1515 |
pid_is_cmd(pid_t pid, const char *name)
|
... | ... | |
1522 |
1596 |
else if (errno == ESRCH)
|
1523 |
1597 |
return false;
|
1524 |
1598 |
else
|
1525 |
|
fatal("error checking pid %u status", pid);
|
|
1599 |
fatal("error checking pid %u status", (unsigned)pid);
|
1526 |
1600 |
}
|
1527 |
1601 |
#endif
|
1528 |
1602 |
|
... | ... | |
1592 |
1666 |
while ((entry = readdir(procdir)) != NULL) {
|
1593 |
1667 |
enum status_code pid_status;
|
1594 |
1668 |
|
1595 |
|
if (sscanf(entry->d_name, "%d", &pid) != 1)
|
|
1669 |
if (sscanf(entry->d_name, "%d", (int*)&pid) != 1)
|
1596 |
1670 |
continue;
|
1597 |
1671 |
foundany++;
|
1598 |
1672 |
|
... | ... | |
1834 |
1908 |
if (testmode) {
|
1835 |
1909 |
if (quietmode <= 0)
|
1836 |
1910 |
printf("Would send signal %d to %d.\n",
|
1837 |
|
sig_num, p->pid);
|
|
1911 |
sig_num, (int)p->pid);
|
1838 |
1912 |
(*n_killed)++;
|
1839 |
1913 |
} else if (kill(p->pid, sig_num) == 0) {
|
1840 |
1914 |
pid_list_push(&killed, p->pid);
|
... | ... | |
1842 |
1916 |
} else {
|
1843 |
1917 |
if (sig_num)
|
1844 |
1918 |
warning("failed to kill %d: %s\n",
|
1845 |
|
p->pid, strerror(errno));
|
|
1919 |
(int)p->pid, strerror(errno));
|
1846 |
1920 |
(*n_notkilled)++;
|
1847 |
1921 |
}
|
1848 |
1922 |
}
|
... | ... | |
1858 |
1932 |
|
1859 |
1933 |
printf("Stopped %s (pid", what_stop);
|
1860 |
1934 |
for (p = killed; p; p = p->next)
|
1861 |
|
printf(" %d", p->pid);
|
|
1935 |
printf(" %d", (int)p->pid);
|
1862 |
1936 |
putchar(')');
|
1863 |
1937 |
if (retry_nr > 0)
|
1864 |
1938 |
printf(", retry #%d", retry_nr);
|