Fix indentation. Support killall -q, for pcmcia-cs
-Erik
This commit is contained in:
parent
f2f26e7fdd
commit
80cd3cfdbc
@ -38,7 +38,7 @@ static const int KILLALL = 1;
|
|||||||
|
|
||||||
extern int kill_main(int argc, char **argv)
|
extern int kill_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int whichApp, sig = SIGTERM;
|
int whichApp, sig = SIGTERM, quiet;
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
#ifdef CONFIG_KILLALL
|
#ifdef CONFIG_KILLALL
|
||||||
@ -48,6 +48,7 @@ extern int kill_main(int argc, char **argv)
|
|||||||
whichApp = KILL;
|
whichApp = KILL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
quiet=0;
|
||||||
argc--;
|
argc--;
|
||||||
argv++;
|
argv++;
|
||||||
/* Parse any options */
|
/* Parse any options */
|
||||||
@ -57,44 +58,49 @@ extern int kill_main(int argc, char **argv)
|
|||||||
while (argc > 0 && **argv == '-') {
|
while (argc > 0 && **argv == '-') {
|
||||||
while (*++(*argv)) {
|
while (*++(*argv)) {
|
||||||
switch (**argv) {
|
switch (**argv) {
|
||||||
case 'l':
|
#ifdef CONFIG_KILLALL
|
||||||
if(argc>1) {
|
case 'q':
|
||||||
for(argv++; *argv; argv++) {
|
quiet++;
|
||||||
name = u_signal_names(*argv, &sig, -1);
|
break;
|
||||||
if(name!=NULL)
|
#endif
|
||||||
printf("%s\n", name);
|
case 'l':
|
||||||
}
|
if(argc>1) {
|
||||||
} else {
|
for(argv++; *argv; argv++) {
|
||||||
int col = 0;
|
name = u_signal_names(*argv, &sig, -1);
|
||||||
for(sig=1; sig < NSIG; sig++) {
|
if(name!=NULL)
|
||||||
name = u_signal_names(0, &sig, 1);
|
printf("%s\n", name);
|
||||||
if(name==NULL) /* unnamed */
|
|
||||||
continue;
|
|
||||||
col += printf("%2d) %-16s", sig, name);
|
|
||||||
if (col > 60) {
|
|
||||||
printf("\n");
|
|
||||||
col = 0;
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
printf("\n");
|
int col = 0;
|
||||||
}
|
for(sig=1; sig < NSIG; sig++) {
|
||||||
return EXIT_SUCCESS;
|
name = u_signal_names(0, &sig, 1);
|
||||||
case '-':
|
if(name==NULL) /* unnamed */
|
||||||
show_usage();
|
continue;
|
||||||
default:
|
col += printf("%2d) %-16s", sig, name);
|
||||||
name = u_signal_names(*argv, &sig, 0);
|
if (col > 60) {
|
||||||
if(name==NULL)
|
printf("\n");
|
||||||
error_msg_and_die( "bad signal name: %s", *argv);
|
col = 0;
|
||||||
argc--;
|
|
||||||
argv++;
|
|
||||||
goto do_it_now;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
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--;
|
argc--;
|
||||||
argv++;
|
argv++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
do_it_now:
|
do_it_now:
|
||||||
|
|
||||||
if (whichApp == KILL) {
|
if (whichApp == KILL) {
|
||||||
/* Looks like they want to do a kill. Do that */
|
/* Looks like they want to do a kill. Do that */
|
||||||
@ -104,8 +110,9 @@ extern int kill_main(int argc, char **argv)
|
|||||||
if (!isdigit(**argv))
|
if (!isdigit(**argv))
|
||||||
perror_msg_and_die( "Bad PID");
|
perror_msg_and_die( "Bad PID");
|
||||||
pid = strtol(*argv, NULL, 0);
|
pid = strtol(*argv, NULL, 0);
|
||||||
if (kill(pid, sig) != 0)
|
if (kill(pid, sig) != 0) {
|
||||||
perror_msg_and_die( "Could not kill pid '%d'", pid);
|
perror_msg_and_die( "Could not kill pid '%d'", pid);
|
||||||
|
}
|
||||||
argv++;
|
argv++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -120,14 +127,23 @@ extern int kill_main(int argc, char **argv)
|
|||||||
pidList = find_pid_by_name( *argv);
|
pidList = find_pid_by_name( *argv);
|
||||||
if (!pidList || *pidList<=0) {
|
if (!pidList || *pidList<=0) {
|
||||||
all_found = FALSE;
|
all_found = FALSE;
|
||||||
error_msg_and_die( "%s: no process killed", *argv);
|
if (quiet) {
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
} else {
|
||||||
|
error_msg_and_die( "%s: no process killed", *argv);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(; pidList && *pidList!=0; pidList++) {
|
for(; pidList && *pidList!=0; pidList++) {
|
||||||
if (*pidList==myPid)
|
if (*pidList==myPid)
|
||||||
continue;
|
continue;
|
||||||
if (kill(*pidList, sig) != 0)
|
if (kill(*pidList, sig) != 0) {
|
||||||
perror_msg_and_die( "Could not kill pid '%d'", *pidList);
|
if (quiet) {
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
} else {
|
||||||
|
perror_msg_and_die( "Could not kill pid '%d'", *pidList);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* Note that we don't bother to free the memory
|
/* Note that we don't bother to free the memory
|
||||||
* allocated in find_pid_by_name(). It will be freed
|
* allocated in find_pid_by_name(). It will be freed
|
||||||
|
Loading…
Reference in New Issue
Block a user