2000-08-27 00:46:25 +00:00
|
|
|
/*-
|
2017-11-27 15:37:16 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2000-08-27 00:46:25 +00:00
|
|
|
* Copyright (c) 2000 Peter Wemm <peter@FreeBSD.org>
|
|
|
|
* Copyright (c) 2000 Paul Saab <ps@FreeBSD.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2002-06-30 05:25:07 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2000-08-27 00:46:25 +00:00
|
|
|
#include <sys/param.h>
|
2003-04-09 03:04:12 +00:00
|
|
|
#include <sys/jail.h>
|
2000-08-27 00:46:25 +00:00
|
|
|
#include <sys/stat.h>
|
2009-05-27 14:30:26 +00:00
|
|
|
#include <sys/uio.h>
|
2000-08-27 00:46:25 +00:00
|
|
|
#include <sys/user.h>
|
|
|
|
#include <sys/sysctl.h>
|
2009-12-13 03:14:06 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <dirent.h>
|
2009-06-24 18:18:35 +00:00
|
|
|
#include <jail.h>
|
2014-12-17 07:10:48 +00:00
|
|
|
#include <stdint.h>
|
2000-08-27 00:46:25 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <regex.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
2004-07-15 07:26:20 +00:00
|
|
|
#include <locale.h>
|
2000-08-27 00:46:25 +00:00
|
|
|
|
2000-08-28 22:09:38 +00:00
|
|
|
static void __dead2
|
2000-08-27 00:46:25 +00:00
|
|
|
usage(void)
|
|
|
|
{
|
|
|
|
|
2013-06-30 20:27:31 +00:00
|
|
|
fprintf(stderr, "usage: killall [-delmsqvz] [-help] [-I] [-j jail]\n");
|
2003-04-09 03:04:12 +00:00
|
|
|
fprintf(stderr,
|
2004-01-18 17:49:25 +00:00
|
|
|
" [-u user] [-t tty] [-c cmd] [-SIGNAL] [cmd]...\n");
|
2000-08-27 00:46:25 +00:00
|
|
|
fprintf(stderr, "At least one option or argument to specify processes must be given.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
printsig(FILE *fp)
|
|
|
|
{
|
|
|
|
const char *const * p;
|
|
|
|
int cnt;
|
|
|
|
int offset = 0;
|
|
|
|
|
|
|
|
for (cnt = NSIG, p = sys_signame + 1; --cnt; ++p) {
|
2011-03-06 19:50:47 +00:00
|
|
|
offset += fprintf(fp, "%s ", *p);
|
2000-08-27 00:46:25 +00:00
|
|
|
if (offset >= 75 && cnt > 1) {
|
|
|
|
offset = 0;
|
|
|
|
fprintf(fp, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(fp, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nosig(char *name)
|
|
|
|
{
|
|
|
|
|
|
|
|
warnx("unknown signal %s; valid signals:", name);
|
|
|
|
printsig(stderr);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int ac, char **av)
|
|
|
|
{
|
2014-01-17 04:16:39 +00:00
|
|
|
char **saved_av;
|
2012-06-30 16:20:01 +00:00
|
|
|
struct kinfo_proc *procs, *newprocs;
|
2000-08-27 00:46:25 +00:00
|
|
|
struct stat sb;
|
2000-08-27 02:12:29 +00:00
|
|
|
struct passwd *pw;
|
2000-08-27 00:46:25 +00:00
|
|
|
regex_t rgx;
|
2019-10-02 16:08:01 +00:00
|
|
|
regmatch_t pmatch;
|
2012-06-27 00:50:25 +00:00
|
|
|
int i, j, ch;
|
2000-08-27 00:46:25 +00:00
|
|
|
char buf[256];
|
2012-06-27 00:50:25 +00:00
|
|
|
char first;
|
2000-08-27 00:46:25 +00:00
|
|
|
char *user = NULL;
|
|
|
|
char *tty = NULL;
|
|
|
|
char *cmd = NULL;
|
2013-06-30 20:27:31 +00:00
|
|
|
int qflag = 0;
|
2000-08-27 00:46:25 +00:00
|
|
|
int vflag = 0;
|
|
|
|
int sflag = 0;
|
|
|
|
int dflag = 0;
|
2004-01-26 11:11:36 +00:00
|
|
|
int eflag = 0;
|
2012-06-27 00:50:25 +00:00
|
|
|
int Iflag = 0;
|
2003-04-09 03:04:12 +00:00
|
|
|
int jflag = 0;
|
2000-08-27 00:46:25 +00:00
|
|
|
int mflag = 0;
|
2002-04-14 22:25:57 +00:00
|
|
|
int zflag = 0;
|
2000-08-27 00:46:25 +00:00
|
|
|
uid_t uid = 0;
|
|
|
|
dev_t tdev = 0;
|
2004-01-22 20:56:06 +00:00
|
|
|
pid_t mypid;
|
2000-08-27 00:46:25 +00:00
|
|
|
char thiscmd[MAXCOMLEN + 1];
|
|
|
|
pid_t thispid;
|
|
|
|
uid_t thisuid;
|
|
|
|
dev_t thistdev;
|
|
|
|
int sig = SIGTERM;
|
2000-08-27 02:12:29 +00:00
|
|
|
const char *const *p;
|
2000-08-27 00:46:25 +00:00
|
|
|
char *ep;
|
|
|
|
int errors = 0;
|
2003-04-09 03:04:12 +00:00
|
|
|
int jid;
|
2001-05-16 11:13:16 +00:00
|
|
|
int mib[4];
|
2000-08-27 00:46:25 +00:00
|
|
|
size_t miblen;
|
|
|
|
int st, nprocs;
|
|
|
|
size_t size;
|
|
|
|
int matched;
|
|
|
|
int killed = 0;
|
|
|
|
|
2004-07-15 07:26:20 +00:00
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
|
2000-08-27 00:46:25 +00:00
|
|
|
av++;
|
|
|
|
ac--;
|
|
|
|
|
|
|
|
while (ac > 0) {
|
|
|
|
if (strcmp(*av, "-l") == 0) {
|
|
|
|
printsig(stdout);
|
|
|
|
exit(0);
|
|
|
|
}
|
2000-08-28 22:09:38 +00:00
|
|
|
if (strcmp(*av, "-help") == 0)
|
|
|
|
usage();
|
2000-08-27 00:46:25 +00:00
|
|
|
if (**av == '-') {
|
|
|
|
++*av;
|
|
|
|
switch (**av) {
|
2003-04-09 03:04:12 +00:00
|
|
|
case 'j':
|
|
|
|
++*av;
|
2007-11-09 15:14:08 +00:00
|
|
|
if (**av == '\0') {
|
2003-04-09 03:04:12 +00:00
|
|
|
++av;
|
2007-11-09 15:14:08 +00:00
|
|
|
--ac;
|
|
|
|
}
|
2003-04-09 03:04:12 +00:00
|
|
|
jflag++;
|
2007-11-09 15:14:08 +00:00
|
|
|
if (*av == NULL)
|
2009-05-27 14:30:26 +00:00
|
|
|
errx(1, "must specify jail");
|
2009-06-24 18:18:35 +00:00
|
|
|
jid = jail_getid(*av);
|
|
|
|
if (jid < 0)
|
|
|
|
errx(1, "%s", jail_errmsg);
|
2003-04-09 03:04:12 +00:00
|
|
|
if (jail_attach(jid) == -1)
|
2009-05-27 14:30:26 +00:00
|
|
|
err(1, "jail_attach(%d)", jid);
|
2003-04-09 03:04:12 +00:00
|
|
|
break;
|
2000-08-27 00:46:25 +00:00
|
|
|
case 'u':
|
|
|
|
++*av;
|
2007-11-09 15:14:08 +00:00
|
|
|
if (**av == '\0') {
|
2000-08-27 00:46:25 +00:00
|
|
|
++av;
|
2007-11-09 15:14:08 +00:00
|
|
|
--ac;
|
|
|
|
}
|
|
|
|
if (*av == NULL)
|
|
|
|
errx(1, "must specify user");
|
2000-08-27 00:46:25 +00:00
|
|
|
user = *av;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
++*av;
|
2007-11-09 15:14:08 +00:00
|
|
|
if (**av == '\0') {
|
2000-08-27 00:46:25 +00:00
|
|
|
++av;
|
2007-11-09 15:14:08 +00:00
|
|
|
--ac;
|
|
|
|
}
|
|
|
|
if (*av == NULL)
|
|
|
|
errx(1, "must specify tty");
|
2000-08-27 00:46:25 +00:00
|
|
|
tty = *av;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
++*av;
|
2007-11-09 15:14:08 +00:00
|
|
|
if (**av == '\0') {
|
2000-08-27 00:46:25 +00:00
|
|
|
++av;
|
2007-11-09 15:14:08 +00:00
|
|
|
--ac;
|
|
|
|
}
|
|
|
|
if (*av == NULL)
|
|
|
|
errx(1, "must specify procname");
|
2000-08-27 00:46:25 +00:00
|
|
|
cmd = *av;
|
|
|
|
break;
|
2013-06-30 20:27:31 +00:00
|
|
|
case 'q':
|
|
|
|
qflag++;
|
|
|
|
break;
|
2000-08-27 00:46:25 +00:00
|
|
|
case 'v':
|
|
|
|
vflag++;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
sflag++;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
dflag++;
|
|
|
|
break;
|
2004-01-26 11:11:36 +00:00
|
|
|
case 'e':
|
|
|
|
eflag++;
|
|
|
|
break;
|
2000-08-27 00:46:25 +00:00
|
|
|
case 'm':
|
|
|
|
mflag++;
|
|
|
|
break;
|
2002-04-14 22:25:57 +00:00
|
|
|
case 'z':
|
|
|
|
zflag++;
|
|
|
|
break;
|
2000-08-27 00:46:25 +00:00
|
|
|
default:
|
2014-01-17 04:16:39 +00:00
|
|
|
saved_av = av;
|
2004-07-15 07:33:56 +00:00
|
|
|
if (isalpha((unsigned char)**av)) {
|
2011-02-04 16:40:50 +00:00
|
|
|
if (strncasecmp(*av, "SIG", 3) == 0)
|
2000-08-27 00:46:25 +00:00
|
|
|
*av += 3;
|
|
|
|
for (sig = NSIG, p = sys_signame + 1;
|
|
|
|
--sig; ++p)
|
|
|
|
if (strcasecmp(*p, *av) == 0) {
|
|
|
|
sig = p - sys_signame;
|
|
|
|
break;
|
|
|
|
}
|
2014-01-17 04:16:39 +00:00
|
|
|
if (!sig) {
|
|
|
|
if (**saved_av == 'I') {
|
|
|
|
av = saved_av;
|
|
|
|
Iflag = 1;
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
nosig(*av);
|
|
|
|
}
|
2004-07-15 07:33:56 +00:00
|
|
|
} else if (isdigit((unsigned char)**av)) {
|
2000-08-27 00:46:25 +00:00
|
|
|
sig = strtol(*av, &ep, 10);
|
|
|
|
if (!*av || *ep)
|
|
|
|
errx(1, "illegal signal number: %s", *av);
|
2004-07-29 18:36:35 +00:00
|
|
|
if (sig < 0 || sig >= NSIG)
|
2000-08-27 00:46:25 +00:00
|
|
|
nosig(*av);
|
|
|
|
} else
|
|
|
|
nosig(*av);
|
|
|
|
}
|
|
|
|
++av;
|
|
|
|
--ac;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-09 03:04:12 +00:00
|
|
|
if (user == NULL && tty == NULL && cmd == NULL && !jflag && ac == 0)
|
2000-08-27 00:46:25 +00:00
|
|
|
usage();
|
|
|
|
|
|
|
|
if (tty) {
|
|
|
|
if (strncmp(tty, "/dev/", 5) == 0)
|
|
|
|
snprintf(buf, sizeof(buf), "%s", tty);
|
|
|
|
else if (strncmp(tty, "tty", 3) == 0)
|
|
|
|
snprintf(buf, sizeof(buf), "/dev/%s", tty);
|
|
|
|
else
|
|
|
|
snprintf(buf, sizeof(buf), "/dev/tty%s", tty);
|
|
|
|
if (stat(buf, &sb) < 0)
|
|
|
|
err(1, "stat(%s)", buf);
|
|
|
|
if (!S_ISCHR(sb.st_mode))
|
|
|
|
errx(1, "%s: not a character device", buf);
|
|
|
|
tdev = sb.st_rdev;
|
|
|
|
if (dflag)
|
2014-12-17 07:10:48 +00:00
|
|
|
printf("ttydev:0x%jx\n", (uintmax_t)tdev);
|
2000-08-27 00:46:25 +00:00
|
|
|
}
|
|
|
|
if (user) {
|
2001-06-12 15:58:31 +00:00
|
|
|
uid = strtol(user, &ep, 10);
|
2002-03-30 16:24:03 +00:00
|
|
|
if (*user == '\0' || *ep != '\0') { /* was it a number? */
|
2001-06-12 15:58:31 +00:00
|
|
|
pw = getpwnam(user);
|
|
|
|
if (pw == NULL)
|
|
|
|
errx(1, "user %s does not exist", user);
|
|
|
|
uid = pw->pw_uid;
|
|
|
|
if (dflag)
|
|
|
|
printf("uid:%d\n", uid);
|
|
|
|
}
|
2000-08-27 00:46:25 +00:00
|
|
|
} else {
|
|
|
|
uid = getuid();
|
|
|
|
if (uid != 0) {
|
|
|
|
pw = getpwuid(uid);
|
|
|
|
if (pw)
|
|
|
|
user = pw->pw_name;
|
|
|
|
if (dflag)
|
|
|
|
printf("uid:%d\n", uid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
size = 0;
|
|
|
|
mib[0] = CTL_KERN;
|
|
|
|
mib[1] = KERN_PROC;
|
|
|
|
|
2003-09-07 09:13:44 +00:00
|
|
|
if (user) {
|
2004-01-26 11:11:36 +00:00
|
|
|
mib[2] = eflag ? KERN_PROC_UID : KERN_PROC_RUID;
|
2000-08-27 00:46:25 +00:00
|
|
|
mib[3] = uid;
|
2003-09-27 08:14:37 +00:00
|
|
|
miblen = 4;
|
2003-09-07 09:13:44 +00:00
|
|
|
} else if (tty) {
|
2000-08-27 00:46:25 +00:00
|
|
|
mib[2] = KERN_PROC_TTY;
|
|
|
|
mib[3] = tdev;
|
2003-09-27 08:14:37 +00:00
|
|
|
miblen = 4;
|
2012-06-30 16:21:51 +00:00
|
|
|
} else {
|
|
|
|
mib[2] = KERN_PROC_PROC;
|
|
|
|
mib[3] = 0;
|
|
|
|
miblen = 3;
|
2000-08-27 00:46:25 +00:00
|
|
|
}
|
|
|
|
|
2012-06-30 16:20:01 +00:00
|
|
|
procs = NULL;
|
2000-08-27 00:46:25 +00:00
|
|
|
st = sysctl(mib, miblen, NULL, &size, NULL, 0);
|
|
|
|
do {
|
|
|
|
size += size / 10;
|
|
|
|
newprocs = realloc(procs, size);
|
2012-06-30 16:20:01 +00:00
|
|
|
if (newprocs == NULL) {
|
|
|
|
free(procs);
|
|
|
|
err(1, "could not reallocate memory");
|
2000-08-27 00:46:25 +00:00
|
|
|
}
|
|
|
|
procs = newprocs;
|
|
|
|
st = sysctl(mib, miblen, procs, &size, NULL, 0);
|
|
|
|
} while (st == -1 && errno == ENOMEM);
|
|
|
|
if (st == -1)
|
|
|
|
err(1, "could not sysctl(KERN_PROC)");
|
|
|
|
if (size % sizeof(struct kinfo_proc) != 0) {
|
2004-07-15 07:30:15 +00:00
|
|
|
fprintf(stderr, "proc size mismatch (%zu total, %zu chunks)\n",
|
2000-08-27 00:46:25 +00:00
|
|
|
size, sizeof(struct kinfo_proc));
|
2012-06-30 16:23:08 +00:00
|
|
|
fprintf(stderr, "userland out of sync with kernel\n");
|
2000-08-27 00:46:25 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
nprocs = size / sizeof(struct kinfo_proc);
|
|
|
|
if (dflag)
|
|
|
|
printf("nprocs %d\n", nprocs);
|
2004-01-22 20:56:06 +00:00
|
|
|
mypid = getpid();
|
2000-08-27 00:46:25 +00:00
|
|
|
|
|
|
|
for (i = 0; i < nprocs; i++) {
|
2012-06-30 16:36:22 +00:00
|
|
|
if (procs[i].ki_stat == SZOMB && !zflag)
|
2002-04-14 22:25:57 +00:00
|
|
|
continue;
|
2000-12-12 23:31:44 +00:00
|
|
|
thispid = procs[i].ki_pid;
|
2008-11-19 00:14:15 +00:00
|
|
|
strlcpy(thiscmd, procs[i].ki_comm, sizeof(thiscmd));
|
2000-12-12 23:31:44 +00:00
|
|
|
thistdev = procs[i].ki_tdev;
|
2004-01-26 11:11:36 +00:00
|
|
|
if (eflag)
|
|
|
|
thisuid = procs[i].ki_uid; /* effective uid */
|
|
|
|
else
|
|
|
|
thisuid = procs[i].ki_ruid; /* real uid */
|
2000-08-27 00:46:25 +00:00
|
|
|
|
2004-01-22 20:56:06 +00:00
|
|
|
if (thispid == mypid)
|
|
|
|
continue;
|
2000-08-27 00:46:25 +00:00
|
|
|
matched = 1;
|
|
|
|
if (user) {
|
|
|
|
if (thisuid != uid)
|
|
|
|
matched = 0;
|
|
|
|
}
|
|
|
|
if (tty) {
|
|
|
|
if (thistdev != tdev)
|
|
|
|
matched = 0;
|
|
|
|
}
|
|
|
|
if (cmd) {
|
|
|
|
if (mflag) {
|
|
|
|
if (regcomp(&rgx, cmd,
|
|
|
|
REG_EXTENDED|REG_NOSUB) != 0) {
|
|
|
|
mflag = 0;
|
|
|
|
warnx("%s: illegal regexp", cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mflag) {
|
2019-10-02 16:08:01 +00:00
|
|
|
pmatch.rm_so = 0;
|
|
|
|
pmatch.rm_eo = strlen(thiscmd);
|
|
|
|
if (regexec(&rgx, thiscmd, 0, &pmatch,
|
2000-08-27 00:46:25 +00:00
|
|
|
REG_STARTEND) != 0)
|
|
|
|
matched = 0;
|
|
|
|
regfree(&rgx);
|
|
|
|
} else {
|
2001-02-14 21:56:03 +00:00
|
|
|
if (strncmp(thiscmd, cmd, MAXCOMLEN) != 0)
|
2000-08-27 00:46:25 +00:00
|
|
|
matched = 0;
|
|
|
|
}
|
|
|
|
}
|
2003-04-09 03:04:12 +00:00
|
|
|
if (jflag && thispid == getpid())
|
|
|
|
matched = 0;
|
2000-08-27 00:46:25 +00:00
|
|
|
if (matched == 0)
|
|
|
|
continue;
|
2001-01-21 01:03:31 +00:00
|
|
|
if (ac > 0)
|
|
|
|
matched = 0;
|
2000-08-27 00:46:25 +00:00
|
|
|
for (j = 0; j < ac; j++) {
|
|
|
|
if (mflag) {
|
|
|
|
if (regcomp(&rgx, av[j],
|
|
|
|
REG_EXTENDED|REG_NOSUB) != 0) {
|
|
|
|
mflag = 0;
|
|
|
|
warnx("%s: illegal regexp", av[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mflag) {
|
2019-10-02 16:08:01 +00:00
|
|
|
pmatch.rm_so = 0;
|
|
|
|
pmatch.rm_eo = strlen(thiscmd);
|
|
|
|
if (regexec(&rgx, thiscmd, 0, &pmatch,
|
2000-08-27 00:46:25 +00:00
|
|
|
REG_STARTEND) == 0)
|
|
|
|
matched = 1;
|
|
|
|
regfree(&rgx);
|
|
|
|
} else {
|
|
|
|
if (strcmp(thiscmd, av[j]) == 0)
|
|
|
|
matched = 1;
|
|
|
|
}
|
|
|
|
if (matched)
|
|
|
|
break;
|
|
|
|
}
|
2012-06-27 00:50:25 +00:00
|
|
|
if (matched != 0 && Iflag) {
|
|
|
|
printf("Send signal %d to %s (pid %d uid %d)? ",
|
|
|
|
sig, thiscmd, thispid, thisuid);
|
|
|
|
fflush(stdout);
|
|
|
|
first = ch = getchar();
|
|
|
|
while (ch != '\n' && ch != EOF)
|
|
|
|
ch = getchar();
|
|
|
|
if (first != 'y' && first != 'Y')
|
|
|
|
matched = 0;
|
|
|
|
}
|
2000-08-27 00:46:25 +00:00
|
|
|
if (matched == 0)
|
|
|
|
continue;
|
|
|
|
if (dflag)
|
2014-12-17 07:10:48 +00:00
|
|
|
printf("sig:%d, cmd:%s, pid:%d, dev:0x%jx uid:%d\n",
|
|
|
|
sig, thiscmd, thispid, (uintmax_t)thistdev,
|
|
|
|
thisuid);
|
2000-08-27 00:46:25 +00:00
|
|
|
|
|
|
|
if (vflag || sflag)
|
2011-03-06 19:50:47 +00:00
|
|
|
printf("kill -%s %d\n", sys_signame[sig], thispid);
|
2000-08-27 00:46:25 +00:00
|
|
|
|
|
|
|
killed++;
|
|
|
|
if (!dflag && !sflag) {
|
|
|
|
if (kill(thispid, sig) < 0 /* && errno != ESRCH */ ) {
|
2002-05-20 07:17:22 +00:00
|
|
|
warn("warning: kill -%s %d",
|
2011-03-06 19:50:47 +00:00
|
|
|
sys_signame[sig], thispid);
|
2000-08-27 00:46:25 +00:00
|
|
|
errors = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (killed == 0) {
|
2013-06-30 20:27:31 +00:00
|
|
|
if (!qflag)
|
|
|
|
fprintf(stderr, "No matching processes %swere found\n",
|
|
|
|
getuid() != 0 ? "belonging to you " : "");
|
2000-08-27 00:46:25 +00:00
|
|
|
errors = 1;
|
|
|
|
}
|
|
|
|
exit(errors);
|
|
|
|
}
|