Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/procps/kill.c


Ignore:
Timestamp:
Jan 1, 2014, 12:47:38 AM (10 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.21.1
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi-busybox/procps/kill.c

    r2725 r3232  
    88 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    99 */
     10
     11//usage:#define kill_trivial_usage
     12//usage:       "[-l] [-SIG] PID..."
     13//usage:#define kill_full_usage "\n\n"
     14//usage:       "Send a signal (default: TERM) to given PIDs\n"
     15//usage:     "\n    -l  List all signal names and numbers"
     16/* //usage:  "\n    -s SIG  Yet another way of specifying SIG" */
     17//usage:
     18//usage:#define kill_example_usage
     19//usage:       "$ ps | grep apache\n"
     20//usage:       "252 root     root     S [apache]\n"
     21//usage:       "263 www-data www-data S [apache]\n"
     22//usage:       "264 www-data www-data S [apache]\n"
     23//usage:       "265 www-data www-data S [apache]\n"
     24//usage:       "266 www-data www-data S [apache]\n"
     25//usage:       "267 www-data www-data S [apache]\n"
     26//usage:       "$ kill 252\n"
     27//usage:
     28//usage:#define killall_trivial_usage
     29//usage:       "[-l] [-q] [-SIG] PROCESS_NAME..."
     30//usage:#define killall_full_usage "\n\n"
     31//usage:       "Send a signal (default: TERM) to given processes\n"
     32//usage:     "\n    -l  List all signal names and numbers"
     33/* //usage:  "\n    -s SIG  Yet another way of specifying SIG" */
     34//usage:     "\n    -q  Don't complain if no processes were killed"
     35//usage:
     36//usage:#define killall_example_usage
     37//usage:       "$ killall apache\n"
     38//usage:
     39//usage:#define killall5_trivial_usage
     40//usage:       "[-l] [-SIG] [-o PID]..."
     41//usage:#define killall5_full_usage "\n\n"
     42//usage:       "Send a signal (default: TERM) to all processes outside current session\n"
     43//usage:     "\n    -l  List all signal names and numbers"
     44//usage:     "\n    -o PID  Don't signal this PID"
     45/* //usage:  "\n    -s SIG  Yet another way of specifying SIG" */
    1046
    1147#include "libbb.h"
     
    128164        sid = getsid(pid);
    129165        /* Stop all processes */
    130         kill(-1, SIGSTOP);
     166        if (signo != SIGSTOP && signo != SIGCONT)
     167            kill(-1, SIGSTOP);
    131168        /* Signal all processes except those in our session */
    132         while ((p = procps_scan(p, PSSCAN_PID|PSSCAN_SID))) {
     169        while ((p = procps_scan(p, PSSCAN_PID|PSSCAN_SID)) != NULL) {
    133170            int i;
    134171
    135172            if (p->sid == (unsigned)sid
    136173             || p->pid == (unsigned)pid
    137              || p->pid == 1)
     174             || p->pid == 1
     175            ) {
    138176                continue;
     177            }
    139178
    140179            /* All remaining args must be -o PID options.
     
    166205 resume:
    167206        /* And let them continue */
    168         kill(-1, SIGCONT);
     207        if (signo != SIGSTOP && signo != SIGCONT)
     208            kill(-1, SIGCONT);
    169209        return ret;
    170210    }
     
    207247    /* Looks like they want to do a kill. Do that */
    208248    while (arg) {
    209         /* Support shell 'space' trick */
    210         if (arg[0] == ' ')
    211             arg++;
     249#if ENABLE_ASH || ENABLE_HUSH
     250        /*
     251         * We need to support shell's "hack formats" of
     252         * " -PRGP_ID" (yes, with a leading space)
     253         * and " PID1 PID2 PID3" (with degenerate case "")
     254         */
     255        while (*arg != '\0') {
     256            char *end;
     257            if (*arg == ' ')
     258                arg++;
     259            pid = bb_strtoi(arg, &end, 10);
     260            if (errno && (errno != EINVAL || *end != ' ')) {
     261                bb_error_msg("invalid number '%s'", arg);
     262                errors++;
     263                break;
     264            }
     265            if (kill(pid, signo) != 0) {
     266                bb_perror_msg("can't kill pid %d", (int)pid);
     267                errors++;
     268            }
     269            arg = end; /* can only point to ' ' or '\0' now */
     270        }
     271#else
    212272        pid = bb_strtoi(arg, NULL, 10);
    213273        if (errno) {
     
    218278            errors++;
    219279        }
     280#endif
    220281        arg = *++argv;
    221282    }
Note: See TracChangeset for help on using the changeset viewer.