-extern int kill_main (int argc, char **argv)
-{
- int had_error = 0;
- int sig = SIGTERM;
-
-
-
- if (argv[1][0] == '-') {
- if (argv[1][1] >= '0' && argv[1][1] <= '9') {
- sig = atoi (&argv[1][1]);
- if (sig < 0 || sig >= NSIG)
- goto end;
- } else {
- const struct signal_name *s = signames;
- for (;;) {
- if (strcmp (s->name, &argv[1][1]) == 0) {
- sig = s->number;
- break;
+ /* Parse any options */
+ if (argc < 2)
+ bb_show_usage();
+
+ if(argv[1][0] != '-'){
+ argv++;
+ argc--;
+ goto do_it_now;
+ }
+
+ /* The -l option, which prints out signal names. */
+ if(argv[1][1]=='l' && argv[1][2]=='\0'){
+ if(argc==2) {
+ /* Print the whole signal list */
+ int col = 0;
+ for(signo=1; signo < NSIG; signo++) {
+ name = u_signal_names(0, &signo, 1);
+ if(name==NULL) /* unnamed */
+ continue;
+ col += printf("%2d) %-16s", signo, name);
+ if (col > 60) {
+ printf("\n");
+ col = 0;
+ }
+ }
+ printf("\n");
+
+ } else {
+ for(argv++; *argv; argv++) {
+ name = u_signal_names(*argv, &signo, -1);
+ if(name!=NULL)
+ printf("%s\n", name);
+ }
+ }
+ /* If they specified -l, were all done */
+ return EXIT_SUCCESS;
+ }
+
+ /* The -q quiet option */
+ if(argv[1][1]=='q' && argv[1][2]=='\0'){
+ quiet++;
+ argv++;
+ argc--;
+ if(argc<2 || argv[1][0] != '-'){
+ goto do_it_now;
+ }
+ }
+
+ if(!u_signal_names(argv[1]+1, &signo, 0))
+ bb_error_msg_and_die( "bad signal name '%s'", argv[1]+1);
+ argv+=2;
+ argc-=2;
+
+do_it_now:
+
+ if (whichApp == KILL) {
+ /* Looks like they want to do a kill. Do that */
+ while (--argc >= 0) {
+ int pid;
+
+ if (!isdigit(**argv))
+ bb_error_msg_and_die( "Bad PID '%s'", *argv);
+ pid = strtol(*argv, NULL, 0);
+ if (kill(pid, signo) != 0) {
+ bb_perror_msg( "Could not kill pid '%d'", pid);
+ errors++;
+ }
+ argv++;