* Mini kill/killall implementation for busybox
*
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
+ * Copyright (C) 1999-2002 by Erik Andersen <andersee@debian.org>
*
* 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
extern int kill_main(int argc, char **argv)
{
- int whichApp, sig = SIGTERM;
+ int whichApp, sig = SIGTERM, quiet;
const char *name;
+ int errors = 0;
#ifdef CONFIG_KILLALL
/* Figure out what we are trying to do here */
whichApp = KILL;
#endif
+ quiet=0;
argc--;
argv++;
/* Parse any options */
while (argc > 0 && **argv == '-') {
while (*++(*argv)) {
switch (**argv) {
- case 'l':
- if(argc>1) {
- for(argv++; *argv; argv++) {
- name = u_signal_names(*argv, &sig, -1);
- if(name!=NULL)
- printf("%s\n", name);
- }
- } else {
- int col = 0;
- for(sig=1; sig < NSIG; sig++) {
- name = u_signal_names(0, &sig, 1);
- if(name==NULL) /* unnamed */
- continue;
- col += printf("%2d) %-16s", sig, name);
- if (col > 60) {
- printf("\n");
- col = 0;
+#ifdef CONFIG_KILLALL
+ case 'q':
+ quiet++;
+ break;
+#endif
+ case 'l':
+ if(argc>1) {
+ for(argv++; *argv; argv++) {
+ name = u_signal_names(*argv, &sig, -1);
+ if(name!=NULL)
+ printf("%s\n", name);
}
- }
- printf("\n");
- }
- return EXIT_SUCCESS;
- case '-':
- show_usage();
- default:
- name = u_signal_names(*argv, &sig, 0);
- if(name==NULL)
- error_msg_and_die( "bad signal name: %s", *argv);
- argc--;
- argv++;
- goto do_it_now;
+ } else {
+ int col = 0;
+ for(sig=1; sig < NSIG; sig++) {
+ name = u_signal_names(0, &sig, 1);
+ if(name==NULL) /* unnamed */
+ continue;
+ col += printf("%2d) %-16s", sig, name);
+ if (col > 60) {
+ printf("\n");
+ col = 0;
}
+ }
+ printf("\n");
+ }
+ return EXIT_SUCCESS;
+ case '-':
+ show_usage();
+ default:
+ name = u_signal_names(*argv, &sig, 0);
+ if(name==NULL)
+ error_msg_and_die( "bad signal name: %s", *argv);
+ argc--;
+ argv++;
+ goto do_it_now;
+ }
argc--;
argv++;
}
}
- do_it_now:
+do_it_now:
if (whichApp == KILL) {
/* Looks like they want to do a kill. Do that */
if (!isdigit(**argv))
perror_msg_and_die( "Bad PID");
pid = strtol(*argv, NULL, 0);
- if (kill(pid, sig) != 0)
- perror_msg_and_die( "Could not kill pid '%d'", pid);
+ if (kill(pid, sig) != 0) {
+ perror_msg( "Could not kill pid '%d'", pid);
+ errors++;
+ }
argv++;
}
+
}
#ifdef CONFIG_KILLALL
else {
- int all_found = TRUE;
pid_t myPid=getpid();
/* Looks like they want to do a killall. Do that */
while (--argc >= 0) {
long* pidList;
- pidList = find_pid_by_name( *argv);
- if (!pidList || *pidList<=0) {
- all_found = FALSE;
- error_msg_and_die( "%s: no process killed", *argv);
- }
-
- for(; pidList && *pidList!=0; pidList++) {
+ pidList = find_pid_by_name(*argv);
+ if (*pidList <= 0) {
+ errors++;
+ if (quiet==0)
+ error_msg( "%s: no process killed", *argv);
+ } else {
+ for(; *pidList!=0; pidList++) {
if (*pidList==myPid)
continue;
- if (kill(*pidList, sig) != 0)
- perror_msg_and_die( "Could not kill pid '%d'", *pidList);
+ if (kill(*pidList, sig) != 0) {
+ errors++;
+ if (quiet==0)
+ perror_msg( "Could not kill pid '%d'", *pidList);
+ }
+ }
}
- /* Note that we don't bother to free the memory
- * allocated in find_pid_by_name(). It will be freed
- * upon exit, so we can save a byte or two */
+ free(pidList);
argv++;
}
- if (! all_found)
- return EXIT_FAILURE;
}
#endif
-
- return EXIT_SUCCESS;
+ return errors;
}