2002-02-02 04:17:29 +05:30
|
|
|
/*
|
2012-03-02 17:59:36 +05:30
|
|
|
* skill.c - send a signal to process
|
|
|
|
* Copyright 1998-2002 by Albert Cahalan
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
2002-02-02 04:17:29 +05:30
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-02 17:59:36 +05:30
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2002-02-02 04:17:29 +05:30
|
|
|
*/
|
2012-03-02 17:59:36 +05:30
|
|
|
|
2011-10-23 00:02:29 +05:30
|
|
|
#include <ctype.h>
|
2002-02-02 04:17:29 +05:30
|
|
|
#include <dirent.h>
|
|
|
|
#include <errno.h>
|
2011-10-19 01:08:15 +05:30
|
|
|
#include <fcntl.h>
|
2011-10-23 00:02:29 +05:30
|
|
|
#include <getopt.h>
|
2011-10-19 01:08:15 +05:30
|
|
|
#include <limits.h>
|
|
|
|
#include <pwd.h>
|
2002-02-02 04:17:29 +05:30
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
2011-10-09 05:58:17 +05:30
|
|
|
|
|
|
|
#include "c.h"
|
2012-03-23 18:02:24 +05:30
|
|
|
#include "fileutils.h"
|
2013-04-16 21:37:10 +05:30
|
|
|
#include "nsutils.h"
|
2011-10-19 01:08:15 +05:30
|
|
|
#include "strutils.h"
|
2011-10-09 05:58:17 +05:30
|
|
|
#include "nls.h"
|
2011-10-10 00:59:26 +05:30
|
|
|
#include "xalloc.h"
|
2002-12-09 12:30:07 +05:30
|
|
|
#include "proc/pwcache.h"
|
2002-10-11 04:10:35 +05:30
|
|
|
#include "proc/sig.h"
|
|
|
|
#include "proc/devname.h"
|
2016-06-18 03:47:45 +05:30
|
|
|
#include "proc/procps.h" /* char *pwcache_get_user(uid_t uid) */
|
2013-04-16 21:37:10 +05:30
|
|
|
#include "proc/readproc.h"
|
2011-10-15 16:38:03 +05:30
|
|
|
#include "proc/version.h" /* procps_version */
|
2012-04-18 01:11:26 +05:30
|
|
|
#include "rpmatch.h"
|
2002-02-02 04:17:29 +05:30
|
|
|
|
2011-10-19 01:08:15 +05:30
|
|
|
#define DEFAULT_NICE 4
|
|
|
|
|
2011-10-16 19:44:21 +05:30
|
|
|
struct run_time_conf_t {
|
|
|
|
int fast;
|
|
|
|
int interactive;
|
|
|
|
int verbose;
|
|
|
|
int warnings;
|
|
|
|
int noaction;
|
|
|
|
int debugging;
|
|
|
|
};
|
2013-04-16 21:37:10 +05:30
|
|
|
static int tty_count, uid_count, cmd_count, pid_count, namespace_count;
|
2002-02-02 04:17:29 +05:30
|
|
|
static int *ttys;
|
|
|
|
static uid_t *uids;
|
2002-11-27 14:06:03 +05:30
|
|
|
static const char **cmds;
|
2002-02-02 04:17:29 +05:30
|
|
|
static int *pids;
|
2013-04-16 21:37:10 +05:30
|
|
|
static char **namespaces;
|
|
|
|
static int ns_pid;
|
|
|
|
static proc_t ns_task;
|
2002-02-02 04:17:29 +05:30
|
|
|
|
|
|
|
#define ENLIST(thing,addme) do{ \
|
2011-10-10 00:59:26 +05:30
|
|
|
if(!thing##s) thing##s = xmalloc(sizeof(*thing##s)*saved_argc); \
|
2002-02-02 04:17:29 +05:30
|
|
|
thing##s[thing##_count++] = addme; \
|
|
|
|
}while(0)
|
|
|
|
|
|
|
|
static int my_pid;
|
|
|
|
static int saved_argc;
|
|
|
|
|
|
|
|
static int sig_or_pri;
|
|
|
|
|
2011-10-16 18:43:22 +05:30
|
|
|
enum {
|
|
|
|
PROG_UNKNOWN,
|
|
|
|
PROG_KILL,
|
|
|
|
PROG_SKILL,
|
|
|
|
PROG_SNICE
|
|
|
|
};
|
|
|
|
static int program = PROG_UNKNOWN;
|
2002-02-02 04:17:29 +05:30
|
|
|
|
2011-10-15 16:38:03 +05:30
|
|
|
static void display_kill_version(void)
|
|
|
|
{
|
|
|
|
fprintf(stdout, PROCPS_NG_VERSION);
|
|
|
|
}
|
2002-02-02 04:17:29 +05:30
|
|
|
|
2013-04-16 21:37:10 +05:30
|
|
|
static int ns_flags = 0x3f;
|
|
|
|
static int parse_namespaces(char *optarg)
|
|
|
|
{
|
|
|
|
char *ptr = optarg, *tmp;
|
|
|
|
int len, id;
|
|
|
|
|
|
|
|
ns_flags = 0;
|
|
|
|
while (1) {
|
|
|
|
if (strchr(ptr, ',') == NULL) {
|
|
|
|
len = -1;
|
|
|
|
tmp = strdup(ptr);
|
|
|
|
} else {
|
|
|
|
len = strchr(ptr, ',') - ptr;
|
|
|
|
tmp = strndup(ptr, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
id = get_ns_id(tmp);
|
|
|
|
if (id == -1) {
|
|
|
|
fprintf(stderr, "%s is not a valid namespace\n", tmp);
|
|
|
|
free(tmp);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
ns_flags |= (1 << id);
|
|
|
|
ENLIST(namespace, tmp);
|
|
|
|
|
|
|
|
if (len == -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ptr+= len + 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-10-15 16:38:03 +05:30
|
|
|
/* kill or nice a process */
|
2011-10-16 19:44:21 +05:30
|
|
|
static void hurt_proc(int tty, int uid, int pid, const char *restrict const cmd,
|
|
|
|
struct run_time_conf_t *run_time)
|
2011-10-15 16:38:03 +05:30
|
|
|
{
|
|
|
|
int failed;
|
|
|
|
char dn_buf[1000];
|
|
|
|
dev_to_tty(dn_buf, 999, tty, pid, ABBREV_DEV);
|
2011-10-16 19:44:21 +05:30
|
|
|
if (run_time->interactive) {
|
2011-11-13 17:53:17 +05:30
|
|
|
char *buf;
|
|
|
|
size_t len = 0;
|
2011-10-15 16:38:03 +05:30
|
|
|
fprintf(stderr, "%-8s %-8s %5d %-16.16s ? ",
|
2016-06-18 03:47:45 +05:30
|
|
|
(char *)dn_buf, pwcache_get_user(uid), pid, cmd);
|
2011-11-13 17:53:17 +05:30
|
|
|
fflush (stdout);
|
2012-05-20 15:52:01 +05:30
|
|
|
if (getline(&buf, &len, stdin) == -1)
|
|
|
|
return;
|
2011-11-13 17:53:17 +05:30
|
|
|
if (rpmatch(buf) < 1) {
|
|
|
|
free(buf);
|
2011-10-15 16:38:03 +05:30
|
|
|
return;
|
2011-11-13 17:53:17 +05:30
|
|
|
}
|
|
|
|
free(buf);
|
2011-10-15 16:38:03 +05:30
|
|
|
}
|
|
|
|
/* do the actual work */
|
2011-10-23 00:02:29 +05:30
|
|
|
errno = 0;
|
2011-10-15 16:38:03 +05:30
|
|
|
if (program == PROG_SKILL)
|
|
|
|
failed = kill(pid, sig_or_pri);
|
|
|
|
else
|
|
|
|
failed = setpriority(PRIO_PROCESS, pid, sig_or_pri);
|
2011-10-23 00:02:29 +05:30
|
|
|
if ((run_time->warnings && failed) || run_time->debugging || run_time->verbose) {
|
2011-10-15 16:38:03 +05:30
|
|
|
fprintf(stderr, "%-8s %-8s %5d %-16.16s ",
|
2016-06-18 03:47:45 +05:30
|
|
|
(char *)dn_buf, pwcache_get_user(uid), pid, cmd);
|
2011-10-15 16:38:03 +05:30
|
|
|
perror("");
|
|
|
|
return;
|
|
|
|
}
|
2011-10-16 19:44:21 +05:30
|
|
|
if (run_time->interactive)
|
2011-10-15 16:38:03 +05:30
|
|
|
return;
|
2011-10-16 19:44:21 +05:30
|
|
|
if (run_time->noaction) {
|
2011-10-15 16:38:03 +05:30
|
|
|
printf("%d\n", pid);
|
|
|
|
return;
|
|
|
|
}
|
2002-10-04 04:38:14 +05:30
|
|
|
}
|
2002-02-02 04:17:29 +05:30
|
|
|
|
2011-10-15 16:38:03 +05:30
|
|
|
/* check one process */
|
2011-10-16 19:44:21 +05:30
|
|
|
static void check_proc(int pid, struct run_time_conf_t *run_time)
|
2011-10-15 16:38:03 +05:30
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
struct stat statbuf;
|
2013-04-16 21:37:10 +05:30
|
|
|
proc_t task;
|
2011-10-15 16:38:03 +05:30
|
|
|
char *tmp;
|
|
|
|
int tty;
|
|
|
|
int fd;
|
|
|
|
int i;
|
2011-10-19 02:11:25 +05:30
|
|
|
if (pid == my_pid || pid == 0)
|
2011-10-15 16:38:03 +05:30
|
|
|
return;
|
|
|
|
/* pid (cmd) state ppid pgrp session tty */
|
|
|
|
sprintf(buf, "/proc/%d/stat", pid);
|
|
|
|
fd = open(buf, O_RDONLY);
|
|
|
|
if (fd == -1) {
|
|
|
|
/* process exited maybe */
|
2011-10-22 13:17:46 +05:30
|
|
|
if (run_time->warnings)
|
2012-01-24 11:10:28 +05:30
|
|
|
xwarn(_("cannot open file %s"), buf);
|
2011-10-15 16:38:03 +05:30
|
|
|
return;
|
|
|
|
}
|
|
|
|
fstat(fd, &statbuf);
|
|
|
|
if (uids) {
|
|
|
|
/* check the EUID */
|
|
|
|
i = uid_count;
|
|
|
|
while (i--)
|
|
|
|
if (uids[i] == statbuf.st_uid)
|
|
|
|
break;
|
|
|
|
if (i == -1)
|
|
|
|
goto closure;
|
|
|
|
}
|
2014-01-29 16:58:02 +05:30
|
|
|
if (read(fd, buf, 128) <= 0)
|
|
|
|
goto closure;
|
2011-10-15 16:38:03 +05:30
|
|
|
buf[127] = '\0';
|
|
|
|
tmp = strrchr(buf, ')');
|
|
|
|
*tmp++ = '\0';
|
|
|
|
i = 5;
|
|
|
|
while (i--)
|
|
|
|
while (*tmp++ != ' ')
|
|
|
|
/* scan to find tty */ ;
|
|
|
|
tty = atoi(tmp);
|
|
|
|
if (ttys) {
|
|
|
|
i = tty_count;
|
|
|
|
while (i--)
|
|
|
|
if (ttys[i] == tty)
|
|
|
|
break;
|
|
|
|
if (i == -1)
|
|
|
|
goto closure;
|
|
|
|
}
|
|
|
|
tmp = strchr(buf, '(') + 1;
|
|
|
|
if (cmds) {
|
|
|
|
i = cmd_count;
|
|
|
|
/* fast comparison trick -- useful? */
|
|
|
|
while (i--)
|
|
|
|
if (cmds[i][0] == *tmp && !strcmp(cmds[i], tmp))
|
|
|
|
break;
|
|
|
|
if (i == -1)
|
|
|
|
goto closure;
|
|
|
|
}
|
2013-04-16 21:37:10 +05:30
|
|
|
if (ns_pid) {
|
|
|
|
if (ns_read(pid, &task))
|
|
|
|
goto closure;
|
|
|
|
for (i = 0; i < NUM_NS; i++) {
|
|
|
|
if (ns_flags & (1 << i)) {
|
|
|
|
if (task.ns[i] != ns_task.ns[i])
|
|
|
|
goto closure;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-10-15 16:38:03 +05:30
|
|
|
/* This is where we kill/nice something. */
|
|
|
|
/* for debugging purposes?
|
|
|
|
fprintf(stderr, "PID %d, UID %d, TTY %d,%d, COMM %s\n",
|
|
|
|
pid, statbuf.st_uid, tty >> 8, tty & 0xf, tmp);
|
|
|
|
*/
|
2011-10-16 19:44:21 +05:30
|
|
|
hurt_proc(tty, statbuf.st_uid, pid, tmp, run_time);
|
2011-10-15 16:38:03 +05:30
|
|
|
closure:
|
|
|
|
/* kill/nice _first_ to avoid PID reuse */
|
|
|
|
close(fd);
|
2002-02-02 04:17:29 +05:30
|
|
|
}
|
|
|
|
|
2011-10-15 16:38:03 +05:30
|
|
|
/* debug function */
|
|
|
|
static void show_lists(void)
|
|
|
|
{
|
|
|
|
int i;
|
2002-02-02 04:17:29 +05:30
|
|
|
|
2012-01-22 05:53:10 +05:30
|
|
|
fprintf(stderr, "signal: %d\n", sig_or_pri);
|
2011-10-19 02:11:25 +05:30
|
|
|
|
2012-01-22 05:53:10 +05:30
|
|
|
fprintf(stderr, "%d TTY: ", tty_count);
|
2011-10-15 16:38:03 +05:30
|
|
|
if (ttys) {
|
|
|
|
i = tty_count;
|
|
|
|
while (i--) {
|
|
|
|
fprintf(stderr, "%d,%d%c", (ttys[i] >> 8) & 0xff,
|
|
|
|
ttys[i] & 0xff, i ? ' ' : '\n');
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
fprintf(stderr, "\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
|
2012-01-22 05:53:10 +05:30
|
|
|
fprintf(stderr, "%d UID: ", uid_count);
|
2011-10-15 16:38:03 +05:30
|
|
|
if (uids) {
|
|
|
|
i = uid_count;
|
|
|
|
while (i--)
|
|
|
|
fprintf(stderr, "%d%c", uids[i], i ? ' ' : '\n');
|
|
|
|
} else
|
|
|
|
fprintf(stderr, "\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
|
2012-01-22 05:53:10 +05:30
|
|
|
fprintf(stderr, "%d PID: ", pid_count);
|
2011-10-15 16:38:03 +05:30
|
|
|
if (pids) {
|
|
|
|
i = pid_count;
|
|
|
|
while (i--)
|
|
|
|
fprintf(stderr, "%d%c", pids[i], i ? ' ' : '\n');
|
|
|
|
} else
|
|
|
|
fprintf(stderr, "\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
|
2012-01-22 05:53:10 +05:30
|
|
|
fprintf(stderr, "%d CMD: ", cmd_count);
|
2011-10-15 16:38:03 +05:30
|
|
|
if (cmds) {
|
|
|
|
i = cmd_count;
|
|
|
|
while (i--)
|
|
|
|
fprintf(stderr, "%s%c", cmds[i], i ? ' ' : '\n');
|
|
|
|
} else
|
|
|
|
fprintf(stderr, "\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
}
|
|
|
|
|
2011-10-15 16:38:03 +05:30
|
|
|
/* iterate over all PIDs */
|
2011-10-16 19:44:21 +05:30
|
|
|
static void iterate(struct run_time_conf_t *run_time)
|
2011-10-15 16:38:03 +05:30
|
|
|
{
|
|
|
|
int pid;
|
|
|
|
DIR *d;
|
|
|
|
struct dirent *de;
|
|
|
|
if (pids) {
|
|
|
|
pid = pid_count;
|
|
|
|
while (pid--)
|
2011-10-16 19:44:21 +05:30
|
|
|
check_proc(pids[pid], run_time);
|
2011-10-15 16:38:03 +05:30
|
|
|
return;
|
|
|
|
}
|
2002-02-02 04:17:29 +05:30
|
|
|
#if 0
|
2011-10-15 16:38:03 +05:30
|
|
|
/* could setuid() and kill -1 to have the kernel wipe out a user */
|
2011-10-16 19:44:21 +05:30
|
|
|
if (!ttys && !cmds && !pids && !run_time->interactive) {
|
2011-10-15 16:38:03 +05:30
|
|
|
}
|
2002-02-02 04:17:29 +05:30
|
|
|
#endif
|
2011-10-15 16:38:03 +05:30
|
|
|
d = opendir("/proc");
|
2011-10-22 22:31:21 +05:30
|
|
|
if (!d)
|
2012-01-03 13:18:43 +05:30
|
|
|
xerr(EXIT_FAILURE, "/proc");
|
2011-10-15 16:38:03 +05:30
|
|
|
while ((de = readdir(d))) {
|
|
|
|
if (de->d_name[0] > '9')
|
|
|
|
continue;
|
|
|
|
if (de->d_name[0] < '1')
|
|
|
|
continue;
|
|
|
|
pid = atoi(de->d_name);
|
|
|
|
if (pid)
|
2011-10-16 19:44:21 +05:30
|
|
|
check_proc(pid, run_time);
|
2011-10-15 16:38:03 +05:30
|
|
|
}
|
|
|
|
closedir(d);
|
2002-02-02 04:17:29 +05:30
|
|
|
}
|
|
|
|
|
2011-10-15 16:38:03 +05:30
|
|
|
/* kill help */
|
2011-10-22 22:36:06 +05:30
|
|
|
static void __attribute__ ((__noreturn__)) kill_usage(FILE * out)
|
2011-10-02 03:54:52 +05:30
|
|
|
{
|
2011-10-22 22:36:06 +05:30
|
|
|
fputs(USAGE_HEADER, out);
|
|
|
|
fprintf(out,
|
2011-12-17 23:02:47 +05:30
|
|
|
_(" %s [options] <pid> [...]\n"), program_invocation_short_name);
|
2011-10-22 22:36:06 +05:30
|
|
|
fputs(USAGE_OPTIONS, out);
|
2013-12-28 03:55:39 +05:30
|
|
|
fputs(_(" <pid> [...] send signal to every <pid> listed\n"), out);
|
|
|
|
fputs(_(" -<signal>, -s, --signal <signal>\n"
|
|
|
|
" specify the <signal> to be sent\n"), out);
|
|
|
|
fputs(_(" -l, --list=[<signal>] list all signal names, or convert one to a name\n"), out);
|
|
|
|
fputs(_(" -L, --table list all signal names in a nice table\n"), out);
|
2011-10-22 22:36:06 +05:30
|
|
|
fputs(USAGE_SEPARATOR, out);
|
2011-10-22 23:34:30 +05:30
|
|
|
fputs(USAGE_HELP, out);
|
|
|
|
fputs(USAGE_VERSION, out);
|
|
|
|
fprintf(out, USAGE_MAN_TAIL("kill(1)"));
|
2011-10-22 22:36:06 +05:30
|
|
|
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
|
2002-02-02 04:17:29 +05:30
|
|
|
}
|
|
|
|
|
2011-10-16 18:49:16 +05:30
|
|
|
/* skill and snice help */
|
2011-10-22 22:36:06 +05:30
|
|
|
static void __attribute__ ((__noreturn__)) skillsnice_usage(FILE * out)
|
2011-10-16 18:49:16 +05:30
|
|
|
{
|
2011-10-22 22:36:06 +05:30
|
|
|
fputs(USAGE_HEADER, out);
|
2011-10-16 18:49:16 +05:30
|
|
|
|
|
|
|
if (program == PROG_SKILL) {
|
2011-10-22 22:36:06 +05:30
|
|
|
fprintf(out,
|
2011-12-17 23:02:47 +05:30
|
|
|
_(" %s [signal] [options] <expression>\n"),
|
2011-10-16 18:49:16 +05:30
|
|
|
program_invocation_short_name);
|
|
|
|
} else {
|
2011-10-22 22:36:06 +05:30
|
|
|
fprintf(out,
|
2011-12-17 23:02:47 +05:30
|
|
|
_(" %s [new priority] [options] <expression>\n"),
|
2011-10-16 18:49:16 +05:30
|
|
|
program_invocation_short_name);
|
|
|
|
}
|
2011-10-22 22:36:06 +05:30
|
|
|
fputs(USAGE_OPTIONS, out);
|
2013-12-28 03:55:39 +05:30
|
|
|
fputs(_(" -f, --fast fast mode (not implemented)\n"), out);
|
|
|
|
fputs(_(" -i, --interactive interactive\n"), out);
|
|
|
|
fputs(_(" -l, --list list all signal names\n"), out);
|
|
|
|
fputs(_(" -L, --table list all signal names in a nice table\n"), out);
|
2014-02-02 12:43:01 +05:30
|
|
|
fputs(_(" -n, --no-action do not actually kill processes; just print what would happen\n"), out);
|
2013-12-28 03:55:39 +05:30
|
|
|
fputs(_(" -v, --verbose explain what is being done\n"), out);
|
|
|
|
fputs(_(" -w, --warnings enable warnings (not implemented)\n"), out);
|
2011-10-22 23:34:30 +05:30
|
|
|
fputs(USAGE_SEPARATOR, out);
|
2011-12-28 02:16:16 +05:30
|
|
|
fputs(_("Expression can be: terminal, user, pid, command.\n"
|
2013-12-28 03:55:39 +05:30
|
|
|
"The options below may be used to ensure correct interpretation.\n"), out);
|
|
|
|
fputs(_(" -c, --command <command> expression is a command name\n"), out);
|
|
|
|
fputs(_(" -p, --pid <pid> expression is a process id number\n"), out);
|
|
|
|
fputs(_(" -t, --tty <tty> expression is a terminal\n"), out);
|
|
|
|
fputs(_(" -u, --user <username> expression is a username\n"), out);
|
2011-10-22 23:34:30 +05:30
|
|
|
fputs(USAGE_SEPARATOR, out);
|
2013-12-28 03:55:39 +05:30
|
|
|
fputs(_("Alternatively, expression can be:\n"), out);
|
|
|
|
fputs(_(" --ns <pid> match the processes that belong to the same\n"
|
|
|
|
" namespace as <pid>\n"), out);
|
|
|
|
fputs(_(" --nslist <ns,...> list which namespaces will be considered for\n"
|
2014-02-02 12:43:01 +05:30
|
|
|
" the --ns option; available namespaces are\n:"
|
|
|
|
" ipc, mnt, net, pid, user, uts\n"), out);
|
2013-04-16 21:37:10 +05:30
|
|
|
|
|
|
|
fputs(USAGE_SEPARATOR, out);
|
|
|
|
fputs(USAGE_SEPARATOR, out);
|
2011-10-22 23:34:30 +05:30
|
|
|
fputs(USAGE_HELP, out);
|
|
|
|
fputs(USAGE_VERSION, out);
|
2011-10-16 18:49:16 +05:30
|
|
|
if (program == PROG_SKILL) {
|
2011-10-22 22:36:06 +05:30
|
|
|
fprintf(out,
|
2011-10-16 18:49:16 +05:30
|
|
|
_("\n"
|
|
|
|
"The default signal is TERM. Use -l or -L to list available signals.\n"
|
|
|
|
"Particularly useful signals include HUP, INT, KILL, STOP, CONT, and 0.\n"
|
|
|
|
"Alternate signals may be specified in three ways: -SIGKILL -KILL -9\n"));
|
2011-10-22 22:36:06 +05:30
|
|
|
fprintf(out, USAGE_MAN_TAIL("skill(1)"));
|
2011-10-16 18:49:16 +05:30
|
|
|
} else {
|
2011-10-22 22:36:06 +05:30
|
|
|
fprintf(out,
|
2011-10-16 18:49:16 +05:30
|
|
|
_("\n"
|
|
|
|
"The default priority is +4. (snice +4 ...)\n"
|
|
|
|
"Priority numbers range from +20 (slowest) to -20 (fastest).\n"
|
|
|
|
"Negative priority numbers are restricted to administrative users.\n"));
|
2011-10-22 22:36:06 +05:30
|
|
|
fprintf(out, USAGE_MAN_TAIL("snice(1)"));
|
2011-10-16 18:49:16 +05:30
|
|
|
}
|
2011-10-22 22:36:06 +05:30
|
|
|
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
|
2011-10-16 18:49:16 +05:30
|
|
|
}
|
|
|
|
|
2012-11-02 23:20:54 +05:30
|
|
|
static int skill_sig_option(int *argc, char **argv)
|
2011-10-23 00:02:29 +05:30
|
|
|
{
|
2015-06-05 10:37:49 +05:30
|
|
|
int i;
|
2011-10-23 00:02:29 +05:30
|
|
|
int signo = -1;
|
2015-06-05 10:37:49 +05:30
|
|
|
for (i = 1; i < *argc; i++) {
|
2011-10-23 00:02:29 +05:30
|
|
|
if (argv[i][0] == '-') {
|
|
|
|
signo = signal_name_to_number(argv[i] + 1);
|
|
|
|
if (-1 < signo) {
|
2015-06-05 10:37:49 +05:30
|
|
|
memmove(argv + i, argv + i + 1,
|
|
|
|
sizeof(char *) * (*argc - i));
|
|
|
|
(*argc)--;
|
2011-10-23 00:02:29 +05:30
|
|
|
return signo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return signo;
|
|
|
|
}
|
|
|
|
|
2011-10-15 16:38:03 +05:30
|
|
|
/* kill */
|
2011-10-16 19:44:21 +05:30
|
|
|
static void __attribute__ ((__noreturn__))
|
2011-10-23 00:02:29 +05:30
|
|
|
kill_main(int argc, char **argv)
|
2011-10-15 16:38:03 +05:30
|
|
|
{
|
2011-10-22 15:50:35 +05:30
|
|
|
int signo, i;
|
2012-10-02 17:26:38 +05:30
|
|
|
int loop = 1;
|
2011-10-22 15:50:35 +05:30
|
|
|
long pid;
|
|
|
|
int exitvalue = EXIT_SUCCESS;
|
2017-02-07 16:35:18 +05:30
|
|
|
char *sig_option;
|
2011-10-22 15:50:35 +05:30
|
|
|
|
|
|
|
static const struct option longopts[] = {
|
|
|
|
{"list", optional_argument, NULL, 'l'},
|
|
|
|
{"table", no_argument, NULL, 'L'},
|
|
|
|
{"signal", required_argument, NULL, 's'},
|
|
|
|
{"help", no_argument, NULL, 'h'},
|
|
|
|
{"version", no_argument, NULL, 'V'},
|
|
|
|
{NULL, 0, NULL, 0}
|
|
|
|
};
|
|
|
|
|
2011-12-07 17:57:21 +05:30
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
bindtextdomain(PACKAGE, LOCALEDIR);
|
|
|
|
textdomain(PACKAGE);
|
2012-03-23 18:02:24 +05:30
|
|
|
atexit(close_stdout);
|
2011-12-07 17:57:21 +05:30
|
|
|
|
2011-10-15 16:38:03 +05:30
|
|
|
if (argc < 2)
|
2011-10-22 22:36:06 +05:30
|
|
|
kill_usage(stderr);
|
2002-02-02 04:17:29 +05:30
|
|
|
|
2011-10-22 15:50:35 +05:30
|
|
|
signo = skill_sig_option(&argc, argv);
|
|
|
|
if (signo < 0)
|
|
|
|
signo = SIGTERM;
|
2002-02-02 04:17:29 +05:30
|
|
|
|
2012-10-02 17:26:38 +05:30
|
|
|
opterr=0; /* suppress errors on -123 */
|
2017-02-07 17:07:36 +05:30
|
|
|
while (loop == 1 && (i = getopt_long(argc, argv, "l::Ls:hV", longopts, NULL)) != -1)
|
2011-10-22 15:50:35 +05:30
|
|
|
switch (i) {
|
|
|
|
case 'l':
|
2017-02-07 16:35:18 +05:30
|
|
|
sig_option = NULL;
|
|
|
|
if (optarg) {
|
|
|
|
sig_option = optarg;
|
2017-02-07 17:07:36 +05:30
|
|
|
} else if (argv[optind] != NULL && argv[optind][0] != '-') {
|
|
|
|
sig_option = argv[optind];
|
2017-02-07 16:35:18 +05:30
|
|
|
}
|
|
|
|
if (sig_option) {
|
2011-10-22 21:37:18 +05:30
|
|
|
char *s;
|
2017-02-07 16:35:18 +05:30
|
|
|
s = strtosig(sig_option);
|
2011-10-22 21:37:18 +05:30
|
|
|
if (s)
|
|
|
|
printf("%s\n", s);
|
|
|
|
else
|
2012-01-03 13:18:43 +05:30
|
|
|
xwarnx(_("unknown signal name %s"),
|
2017-02-07 16:35:18 +05:30
|
|
|
sig_option);
|
2011-10-22 21:37:18 +05:30
|
|
|
free(s);
|
2011-10-22 15:50:35 +05:30
|
|
|
} else {
|
|
|
|
unix_print_signals();
|
|
|
|
}
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
case 'L':
|
2011-10-15 16:38:03 +05:30
|
|
|
pretty_print_signals();
|
2011-10-22 15:50:35 +05:30
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
case 's':
|
|
|
|
signo = signal_name_to_number(optarg);
|
|
|
|
break;
|
|
|
|
case 'h':
|
2011-10-22 22:36:06 +05:30
|
|
|
kill_usage(stdout);
|
2011-10-22 15:50:35 +05:30
|
|
|
case 'V':
|
|
|
|
display_kill_version();
|
|
|
|
exit(EXIT_SUCCESS);
|
2012-10-02 17:26:38 +05:30
|
|
|
case '?':
|
|
|
|
if (!isdigit(optopt)) {
|
|
|
|
xwarnx(_("invalid argument %c"), optopt);
|
|
|
|
kill_usage(stderr);
|
2014-01-29 16:58:02 +05:30
|
|
|
} else {
|
|
|
|
/* Special case for signal digit negative
|
|
|
|
* PIDs */
|
2016-04-13 00:32:28 +05:30
|
|
|
pid = atoi(argv[optind]);
|
2014-01-29 16:58:02 +05:30
|
|
|
if (kill((pid_t)pid, signo) != 0)
|
|
|
|
exitvalue = EXIT_FAILURE;
|
|
|
|
exit(exitvalue);
|
2012-10-02 17:26:38 +05:30
|
|
|
}
|
|
|
|
loop=0;
|
|
|
|
break;
|
2011-10-22 15:50:35 +05:30
|
|
|
default:
|
2011-10-22 22:36:06 +05:30
|
|
|
kill_usage(stderr);
|
2011-10-15 16:38:03 +05:30
|
|
|
}
|
2011-10-22 15:50:35 +05:30
|
|
|
|
2015-06-05 10:37:49 +05:30
|
|
|
argc -= optind;
|
2011-10-22 15:50:35 +05:30
|
|
|
argv += optind;
|
|
|
|
|
2015-06-05 10:57:03 +05:30
|
|
|
if (argc < 1)
|
|
|
|
kill_usage(stderr);
|
|
|
|
|
2011-10-22 15:50:35 +05:30
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
pid = strtol_or_err(argv[i], _("failed to parse argument"));
|
|
|
|
if (!kill((pid_t) pid, signo))
|
2011-10-15 16:38:03 +05:30
|
|
|
continue;
|
2016-07-02 10:48:29 +05:30
|
|
|
error(0, errno, "(%ld)", pid);
|
2011-10-22 15:50:35 +05:30
|
|
|
exitvalue = EXIT_FAILURE;
|
|
|
|
continue;
|
2011-10-15 16:38:03 +05:30
|
|
|
}
|
2011-10-22 15:50:35 +05:30
|
|
|
|
2011-10-15 16:38:03 +05:30
|
|
|
exit(exitvalue);
|
2002-02-02 04:17:29 +05:30
|
|
|
}
|
2011-10-22 15:50:35 +05:30
|
|
|
|
2002-02-02 04:17:29 +05:30
|
|
|
#if 0
|
2011-10-15 16:38:03 +05:30
|
|
|
static void _skillsnice_usage(int line)
|
|
|
|
{
|
2012-01-14 03:08:47 +05:30
|
|
|
fprintf(stderr, _("something at line %d\n"), line);
|
2011-10-22 22:36:06 +05:30
|
|
|
skillsnice_usage(stderr);
|
2002-02-02 04:17:29 +05:30
|
|
|
}
|
2011-10-15 16:38:03 +05:30
|
|
|
|
2002-02-02 04:17:29 +05:30
|
|
|
#define skillsnice_usage() _skillsnice_usage(__LINE__)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define NEXTARG (argc?( argc--, ((argptr=*++argv)) ):NULL)
|
|
|
|
|
2011-10-15 16:38:03 +05:30
|
|
|
/* common skill/snice argument parsing code */
|
2011-10-16 19:44:21 +05:30
|
|
|
|
2012-11-02 23:20:54 +05:30
|
|
|
static int snice_prio_option(int *argc, char **argv)
|
2011-10-19 01:08:15 +05:30
|
|
|
{
|
|
|
|
int i = 1, nargs = *argc;
|
|
|
|
long prio = DEFAULT_NICE;
|
|
|
|
|
|
|
|
while (i < nargs) {
|
|
|
|
if ((argv[i][0] == '-' || argv[i][0] == '+')
|
|
|
|
&& isdigit(argv[i][1])) {
|
|
|
|
prio = strtol_or_err(argv[i],
|
|
|
|
_("failed to parse argument"));
|
|
|
|
if (prio < INT_MIN || INT_MAX < prio)
|
2012-01-03 13:18:43 +05:30
|
|
|
xerrx(EXIT_FAILURE,
|
2011-10-19 01:08:15 +05:30
|
|
|
_("priority %lu out of range"), prio);
|
|
|
|
nargs--;
|
|
|
|
if (nargs - i)
|
|
|
|
memmove(argv + i, argv + i + 1,
|
|
|
|
sizeof(char *) * (nargs - i));
|
|
|
|
} else
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
*argc = nargs;
|
|
|
|
return (int)prio;
|
|
|
|
}
|
|
|
|
|
2011-10-15 16:38:03 +05:30
|
|
|
static void skillsnice_parse(int argc,
|
2011-10-19 02:11:25 +05:30
|
|
|
char **argv, struct run_time_conf_t *run_time)
|
2011-10-15 16:38:03 +05:30
|
|
|
{
|
|
|
|
int signo = -1;
|
2011-10-19 02:11:25 +05:30
|
|
|
int prino = DEFAULT_NICE;
|
|
|
|
int ch, i;
|
|
|
|
|
2013-04-16 21:37:10 +05:30
|
|
|
enum {
|
|
|
|
NS_OPTION = CHAR_MAX + 1,
|
|
|
|
NSLIST_OPTION,
|
|
|
|
};
|
|
|
|
|
2011-10-19 02:11:25 +05:30
|
|
|
static const struct option longopts[] = {
|
|
|
|
{"command", required_argument, NULL, 'c'},
|
|
|
|
{"debug", no_argument, NULL, 'd'},
|
|
|
|
{"fast", no_argument, NULL, 'f'},
|
|
|
|
{"interactive", no_argument, NULL, 'i'},
|
|
|
|
{"list", no_argument, NULL, 'l'},
|
|
|
|
{"no-action", no_argument, NULL, 'n'},
|
|
|
|
{"pid", required_argument, NULL, 'p'},
|
|
|
|
{"table", no_argument, NULL, 'L'},
|
|
|
|
{"tty", required_argument, NULL, 't'},
|
|
|
|
{"user", required_argument, NULL, 'u'},
|
2013-04-16 21:37:10 +05:30
|
|
|
{"ns", required_argument, NULL, NS_OPTION},
|
|
|
|
{"nslist", required_argument, NULL, NSLIST_OPTION},
|
2011-10-19 02:11:25 +05:30
|
|
|
{"verbose", no_argument, NULL, 'v'},
|
|
|
|
{"warnings", no_argument, NULL, 'w'},
|
|
|
|
{"help", no_argument, NULL, 'h'},
|
|
|
|
{"version", no_argument, NULL, 'V'},
|
|
|
|
{NULL, 0, NULL, 0}
|
|
|
|
};
|
|
|
|
|
2011-10-15 16:38:03 +05:30
|
|
|
if (argc < 2)
|
2011-10-22 22:36:06 +05:30
|
|
|
skillsnice_usage(stderr);
|
2011-10-19 01:08:15 +05:30
|
|
|
|
2011-10-19 02:11:25 +05:30
|
|
|
sig_or_pri = -1;
|
|
|
|
|
2011-10-19 01:33:25 +05:30
|
|
|
if (program == PROG_SNICE)
|
|
|
|
prino = snice_prio_option(&argc, argv);
|
2011-10-19 02:11:25 +05:30
|
|
|
else if (program == PROG_SKILL) {
|
2011-10-19 01:33:25 +05:30
|
|
|
signo = skill_sig_option(&argc, argv);
|
2015-06-05 10:37:49 +05:30
|
|
|
if (-1 < signo)
|
2011-10-19 02:11:25 +05:30
|
|
|
sig_or_pri = signo;
|
|
|
|
}
|
2011-10-19 01:08:15 +05:30
|
|
|
|
2011-10-19 02:11:25 +05:30
|
|
|
pid_count = 0;
|
|
|
|
|
|
|
|
while ((ch =
|
|
|
|
getopt_long(argc, argv, "c:dfilnp:Lt:u:vwhV", longopts,
|
|
|
|
NULL)) != -1)
|
|
|
|
switch (ch) {
|
|
|
|
case 'c':
|
|
|
|
ENLIST(cmd, optarg);
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
run_time->debugging = 1;
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
run_time->fast = 1;
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
run_time->interactive = 1;
|
|
|
|
break;
|
|
|
|
case 'l':
|
2011-10-15 16:38:03 +05:30
|
|
|
unix_print_signals();
|
2011-10-19 02:11:25 +05:30
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
case 'n':
|
|
|
|
run_time->noaction = 1;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
ENLIST(pid,
|
|
|
|
strtol_or_err(optarg,
|
|
|
|
_("failed to parse argument")));
|
|
|
|
pid_count++;
|
|
|
|
break;
|
|
|
|
case 'L':
|
|
|
|
pretty_print_signals();
|
|
|
|
exit(EXIT_SUCCESS);
|
2011-10-15 16:38:03 +05:30
|
|
|
case 't':
|
2011-10-19 02:11:25 +05:30
|
|
|
{
|
2011-10-15 16:38:03 +05:30
|
|
|
struct stat sbuf;
|
|
|
|
char path[32];
|
2011-10-19 02:11:25 +05:30
|
|
|
snprintf(path, 32, "/dev/%s", optarg);
|
2011-10-15 16:38:03 +05:30
|
|
|
if (stat(path, &sbuf) >= 0
|
|
|
|
&& S_ISCHR(sbuf.st_mode)) {
|
|
|
|
ENLIST(tty, sbuf.st_rdev);
|
|
|
|
}
|
|
|
|
}
|
2011-10-19 02:11:25 +05:30
|
|
|
break;
|
2011-10-15 16:38:03 +05:30
|
|
|
case 'u':
|
2011-10-19 02:11:25 +05:30
|
|
|
{
|
2011-10-15 16:38:03 +05:30
|
|
|
struct passwd *passwd_data;
|
2011-10-23 00:02:29 +05:30
|
|
|
passwd_data = getpwnam(optarg);
|
2011-10-15 16:38:03 +05:30
|
|
|
if (passwd_data) {
|
|
|
|
ENLIST(uid, passwd_data->pw_uid);
|
|
|
|
}
|
|
|
|
}
|
2011-10-19 02:11:25 +05:30
|
|
|
break;
|
2013-04-16 21:37:10 +05:30
|
|
|
case NS_OPTION:
|
|
|
|
ns_pid = atoi(optarg);
|
|
|
|
if (ns_pid == 0) {
|
2013-09-12 22:42:12 +05:30
|
|
|
xwarnx(_("invalid pid number %s"), optarg);
|
2013-04-16 21:37:10 +05:30
|
|
|
kill_usage(stderr);
|
|
|
|
}
|
|
|
|
if (ns_read(ns_pid, &ns_task)) {
|
|
|
|
xwarnx(_("error reading reference namespace "
|
|
|
|
"information"));
|
|
|
|
kill_usage(stderr);
|
2013-09-12 22:42:12 +05:30
|
|
|
}
|
2013-04-16 21:37:10 +05:30
|
|
|
|
|
|
|
break;
|
|
|
|
case NSLIST_OPTION:
|
|
|
|
if (parse_namespaces(optarg)) {
|
|
|
|
xwarnx(_("invalid namespace list"));
|
|
|
|
kill_usage(stderr);
|
|
|
|
}
|
|
|
|
break;
|
2011-10-19 02:11:25 +05:30
|
|
|
case 'v':
|
|
|
|
run_time->verbose = 1;
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
run_time->warnings = 1;
|
|
|
|
break;
|
|
|
|
case 'h':
|
2011-10-22 22:36:06 +05:30
|
|
|
skillsnice_usage(stdout);
|
2011-10-19 02:11:25 +05:30
|
|
|
case 'V':
|
|
|
|
display_kill_version();
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
default:
|
2011-10-22 22:36:06 +05:30
|
|
|
skillsnice_usage(stderr);
|
2011-10-19 02:11:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
for (i = 0; i < argc; i++) {
|
2012-02-10 03:23:29 +05:30
|
|
|
long num;
|
|
|
|
char *end = NULL;
|
|
|
|
errno = 0;
|
|
|
|
num = strtol(argv[0], &end, 10);
|
|
|
|
if (errno == 0 && argv[0] != end && end != NULL && *end == '\0') {
|
|
|
|
ENLIST(pid, num);
|
|
|
|
pid_count++;
|
|
|
|
} else {
|
|
|
|
ENLIST(cmd, argv[0]);
|
|
|
|
}
|
2011-10-19 02:11:25 +05:30
|
|
|
argv++;
|
2011-10-15 16:38:03 +05:30
|
|
|
}
|
2011-10-19 02:11:25 +05:30
|
|
|
|
|
|
|
/* No more arguments to process. Must sanity check. */
|
2013-04-16 21:37:10 +05:30
|
|
|
if (!tty_count && !uid_count && !cmd_count && !pid_count && !ns_pid)
|
2012-01-03 13:18:43 +05:30
|
|
|
xerrx(EXIT_FAILURE, _("no process selection criteria"));
|
2011-10-19 02:11:25 +05:30
|
|
|
if ((run_time->fast | run_time->interactive | run_time->
|
|
|
|
verbose | run_time->warnings | run_time->noaction) & ~1)
|
2012-01-03 13:18:43 +05:30
|
|
|
xerrx(EXIT_FAILURE, _("general flags may not be repeated"));
|
2011-10-19 02:11:25 +05:30
|
|
|
if (run_time->interactive
|
|
|
|
&& (run_time->verbose | run_time->fast | run_time->noaction))
|
2012-01-03 13:18:43 +05:30
|
|
|
xerrx(EXIT_FAILURE, _("-i makes no sense with -v, -f, and -n"));
|
2011-10-19 02:11:25 +05:30
|
|
|
if (run_time->verbose && (run_time->interactive | run_time->fast))
|
2012-01-03 13:18:43 +05:30
|
|
|
xerrx(EXIT_FAILURE, _("-v makes no sense with -i and -f"));
|
2011-10-16 19:44:21 +05:30
|
|
|
if (run_time->noaction) {
|
2011-10-15 16:38:03 +05:30
|
|
|
program = PROG_SKILL;
|
|
|
|
/* harmless */
|
2011-10-19 02:11:25 +05:30
|
|
|
sig_or_pri = 0;
|
2011-10-15 16:38:03 +05:30
|
|
|
}
|
2011-10-19 02:11:25 +05:30
|
|
|
if (program == PROG_SNICE)
|
2011-10-15 16:38:03 +05:30
|
|
|
sig_or_pri = prino;
|
2011-10-19 02:11:25 +05:30
|
|
|
else if (sig_or_pri < 0)
|
|
|
|
sig_or_pri = SIGTERM;
|
2002-02-02 04:17:29 +05:30
|
|
|
}
|
|
|
|
|
2011-10-15 16:38:03 +05:30
|
|
|
/* main body */
|
2011-10-19 01:08:15 +05:30
|
|
|
int main(int argc, char ** argv)
|
2011-10-15 16:38:03 +05:30
|
|
|
{
|
2013-02-20 23:01:48 +05:30
|
|
|
#ifdef HAVE_PROGRAM_INVOCATION_NAME
|
|
|
|
program_invocation_name = program_invocation_short_name;
|
|
|
|
#endif
|
2011-10-16 19:44:21 +05:30
|
|
|
struct run_time_conf_t run_time;
|
|
|
|
memset(&run_time, 0, sizeof(struct run_time_conf_t));
|
2011-10-15 16:38:03 +05:30
|
|
|
my_pid = getpid();
|
2011-10-16 18:43:22 +05:30
|
|
|
|
|
|
|
if (strcmp(program_invocation_short_name, "kill") == 0 ||
|
|
|
|
strcmp(program_invocation_short_name, "lt-kill") == 0)
|
2011-10-15 16:38:03 +05:30
|
|
|
program = PROG_KILL;
|
2011-10-16 18:43:22 +05:30
|
|
|
else if (strcmp(program_invocation_short_name, "skill") == 0 ||
|
|
|
|
strcmp(program_invocation_short_name, "lt-skill") == 0)
|
2011-10-15 16:38:03 +05:30
|
|
|
program = PROG_SKILL;
|
2011-10-16 18:43:22 +05:30
|
|
|
else if (strcmp(program_invocation_short_name, "snice") == 0 ||
|
|
|
|
strcmp(program_invocation_short_name, "lt-snice") == 0)
|
2011-10-15 16:38:03 +05:30
|
|
|
program = PROG_SNICE;
|
2017-08-31 01:45:15 +05:30
|
|
|
#ifdef __CYGWIN__
|
|
|
|
else if (strcmp(program_invocation_short_name, "prockill") == 0 ||
|
|
|
|
strcmp(program_invocation_short_name, "lt-prockill") == 0)
|
|
|
|
program = PROG_KILL;
|
|
|
|
#endif
|
2011-10-16 18:43:22 +05:30
|
|
|
|
2011-10-15 16:38:03 +05:30
|
|
|
switch (program) {
|
|
|
|
case PROG_SNICE:
|
|
|
|
case PROG_SKILL:
|
|
|
|
setpriority(PRIO_PROCESS, my_pid, -20);
|
2011-10-16 19:44:21 +05:30
|
|
|
skillsnice_parse(argc, argv, &run_time);
|
|
|
|
if (run_time.debugging)
|
|
|
|
show_lists();
|
|
|
|
iterate(&run_time);
|
2011-10-15 16:38:03 +05:30
|
|
|
break;
|
|
|
|
case PROG_KILL:
|
2011-10-23 00:02:29 +05:30
|
|
|
kill_main(argc, argv);
|
2011-10-15 16:38:03 +05:30
|
|
|
break;
|
|
|
|
default:
|
2014-03-03 16:28:56 +05:30
|
|
|
fprintf(stderr, _("skill: \"%s\" is not supported\n"),
|
2011-10-16 18:43:22 +05:30
|
|
|
program_invocation_short_name);
|
|
|
|
fprintf(stderr, USAGE_MAN_TAIL("skill(1)"));
|
2011-10-22 22:31:21 +05:30
|
|
|
return EXIT_FAILURE;
|
2011-10-15 16:38:03 +05:30
|
|
|
}
|
2011-10-22 22:31:21 +05:30
|
|
|
return EXIT_SUCCESS;
|
2002-02-02 04:17:29 +05:30
|
|
|
}
|