From 92aad1df800fad67361b5dc8796da350da48abe0 Mon Sep 17 00:00:00 2001 From: Craig Small Date: Sat, 16 Jun 2012 18:49:27 +1000 Subject: [PATCH] Removed remants of pidof pidof has been in util-linux for a while, but there has been some remaining code in killall which is now removed. --- src/killall.c | 83 +++++++++++---------------------------------------- 1 file changed, 18 insertions(+), 65 deletions(-) diff --git a/src/killall.c b/src/killall.c index 6a6623c..be8eee4 100644 --- a/src/killall.c +++ b/src/killall.c @@ -2,7 +2,7 @@ * killall.c - kill processes by name or list PIDs * * Copyright (C) 1993-2002 Werner Almesberger - * Copyright (C) 2002-2007 Craig Small + * Copyright (C) 2002-2012 Craig Small * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -80,12 +80,9 @@ #define ER_UNKWN -3 #define ER_OOFRA -4 -#define NOT_PIDOF_OPTION if (pidof) usage(NULL) -#define MYNAME ((pidof)?"pidof":"killall") - static int verbose = 0, exact = 0, interactive = 0, reg = 0, quiet = 0, wait_until_dead = 0, process_group = 0, - ignore_case = 0, pidof; + ignore_case = 0; static long younger_than = 0, older_than = 0; static int @@ -131,7 +128,7 @@ uptime() char buf[2048]; FILE* file; if (!(file=fopen( PROC_BASE "/uptime", "r"))) { - fprintf(stderr, "%s: error opening uptime file\n",MYNAME); + fprintf(stderr, "killall: error opening uptime file\n"); exit(1); } savelocale = setlocale(LC_NUMERIC, NULL); @@ -207,7 +204,7 @@ match_process_uid(pid_t pid, uid_t uid) fclose(f); if (re==-1) { - fprintf(stderr, _("%s: Cannot get UID from process status\n"), MYNAME); + fprintf(stderr, _("killall: Cannot get UID from process status\n")); exit(1); } return re; @@ -233,7 +230,7 @@ build_regexp_list(int names, char **namelist) { if (regcomp(®list[i], namelist[i], flag) != 0) { - fprintf(stderr, _("%s: Bad regular expression: %s\n"), MYNAME, namelist[i]); + fprintf(stderr, _("killall: Bad regular expression: %s\n"), namelist[i]); exit (1); } } @@ -444,8 +441,8 @@ kill_all (int signal, int names, char **namelist, struct passwd *pwent) if (exact && !okay) { if (verbose) - fprintf (stderr, _("%s: skipping partial match %s(%d)\n"), - MYNAME, comm, pid_table[i]); + fprintf (stderr, _("killall: skipping partial match %s(%d)\n"), + comm, pid_table[i]); continue; } got_long = okay; @@ -545,8 +542,8 @@ kill_all (int signal, int names, char **namelist, struct passwd *pwent) pgids[i] = id; if (id < 0) { - fprintf (stderr, "%s: getpgid(%d): %s\n", - MYNAME, pid_table[i], strerror (errno)); + fprintf (stderr, "killall: getpgid(%d): %s\n", + pid_table[i], strerror (errno)); } for (j = 0; j < i; j++) if (pgids[j] == id) @@ -556,14 +553,7 @@ kill_all (int signal, int names, char **namelist, struct passwd *pwent) } if (interactive && !ask (comm, id, signal)) continue; - if (pidof) - { - if (found) - putchar (' '); - printf ("%d", id); - found |= 1 << (found_name >= 0 ? found_name : 0); - } - else if (kill (process_group ? -id : id, signal) >= 0) + if (kill (process_group ? -id : id, signal) >= 0) { if (verbose) fprintf (stderr, _("Killed %s(%s%d) with signal %d\n"), got_long ? command : @@ -577,12 +567,10 @@ kill_all (int signal, int names, char **namelist, struct passwd *pwent) fprintf (stderr, "%s(%d): %s\n", got_long ? command : comm, id, strerror (errno)); } - if (!quiet && !pidof) + if (!quiet) for (i = 0; i < names; i++) if (!(found & (1 << i))) fprintf (stderr, _("%s: no process found\n"), namelist[i]); - if (pidof) - putchar ('\n'); if (names) /* killall returns a zero return code if at least one process has * been killed for each listed command. */ @@ -615,20 +603,7 @@ kill_all (int signal, int names, char **namelist, struct passwd *pwent) static void -usage_pidof (void) -{ - fprintf (stderr, _( - "Usage: pidof [ -eg ] NAME...\n" - " pidof -V\n\n" - " -e require exact match for very long names;\n" - " skip if the command line is unavailable\n" - " -g show process group ID instead of process ID\n" - " -V display version information\n\n")); -} - - -static void -usage_killall (const char *msg) +usage (const char *msg) { if (msg != NULL) fprintf(stderr, "%s\n", msg); @@ -665,21 +640,11 @@ usage_killall (const char *msg) } -static void -usage (const char *msg) -{ - if (pidof) - usage_pidof (); - else - usage_killall (msg); - exit (1); -} - void print_version() { - fprintf(stderr, "%s (PSmisc) %s\n", pidof ? "pidof" : "killall", VERSION); + fprintf(stderr, "killall (PSmisc) %s\n", VERSION); fprintf(stderr, _( - "Copyright (C) 1993-2005 Werner Almesberger and Craig Small\n\n")); + "Copyright (C) 1993-2012 Werner Almesberger and Craig Small\n\n")); fprintf(stderr, _( "PSmisc comes with ABSOLUTELY NO WARRANTY.\n" "This is free software, and you are welcome to redistribute it under\n" @@ -749,7 +714,6 @@ main (int argc, char **argv) name++; else name = *argv; - pidof = strcmp (name, "killall"); sig_num = SIGTERM; @@ -767,52 +731,43 @@ main (int argc, char **argv) process_group = 1; break; case 'y': - NOT_PIDOF_OPTION; strncpy(yt, optarg, 16); yt[15] = '\0'; if ( 0 >= (younger_than = parse_time_units(yt) ) ) usage(_("Invalid time format")); break; case 'o': - NOT_PIDOF_OPTION; strncpy(ot, optarg, 16); ot[15] = '\0'; if ( 0 >= (older_than = parse_time_units(ot) ) ) usage(_("Invalid time format")); break; case 'i': - NOT_PIDOF_OPTION; interactive = 1; break; case 'l': - NOT_PIDOF_OPTION; list_signals(); return 0; break; case 'q': - NOT_PIDOF_OPTION; quiet = 1; break; case 'r': - NOT_PIDOF_OPTION; reg = 1; break; case 's': sig_num = get_signal (optarg, "killall"); break; case 'u': - NOT_PIDOF_OPTION; if (!(pwent = getpwnam(optarg))) { fprintf (stderr, _("Cannot find user %s\n"), optarg); exit (1); } break; case 'v': - NOT_PIDOF_OPTION; verbose = 1; break; case 'w': - NOT_PIDOF_OPTION; wait_until_dead = 1; break; case 'I': @@ -820,7 +775,6 @@ main (int argc, char **argv) if (strcmp(argv[optind-1],"-I") == 0 || strncmp(argv[optind-1],"--",2) == 0) { ignore_case = 1; } else { - NOT_PIDOF_OPTION; sig_num = get_signal (argv[optind]+1, "killall"); } break; @@ -830,7 +784,6 @@ main (int argc, char **argv) print_version(); return 0; } - NOT_PIDOF_OPTION; sig_num = get_signal (argv[optind]+1, "killall"); break; #ifdef WITH_SELINUX @@ -870,13 +823,13 @@ main (int argc, char **argv) usage(NULL); if (argc - myoptind > MAX_NAMES) { - fprintf (stderr, _("%s: Maximum number of names is %d\n"), - MYNAME, MAX_NAMES); + fprintf (stderr, _("killall: Maximum number of names is %d\n"), + MAX_NAMES); exit (1); } if (!have_proc_self_stat()) { - fprintf (stderr, _("%s: %s lacks process entries (not mounted ?)\n"), - MYNAME, PROC_BASE); + fprintf (stderr, _("killall: %s lacks process entries (not mounted ?)\n"), + PROC_BASE); exit (1); } argv = argv + myoptind; -- 2.40.0