Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/procps/kill.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/procps/kill.c
r1765 r2725 6 6 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> 7 7 * 8 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.8 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 9 9 */ 10 10 … … 25 25 */ 26 26 27 int kill_main(int argc, char **argv);28 27 int kill_main(int argc, char **argv) 29 28 { … … 59 58 if (argc == 1) { 60 59 /* Print the whole signal list */ 61 for (signo = 1; signo < 32; signo++) { 62 const char *name = get_signame(signo); 63 if (!isdigit(name[0])) 64 puts(name); 65 } 66 } else { /* -l <sig list> */ 67 while ((arg = *++argv)) { 68 if (isdigit(arg[0])) { 69 signo = bb_strtou(arg, NULL, 10); 70 if (errno) { 71 bb_error_msg("unknown signal '%s'", arg); 72 return EXIT_FAILURE; 73 } 74 /* Exitcodes >= 0x80 are to be treated 75 * as "killed by signal (exitcode & 0x7f)" */ 76 puts(get_signame(signo & 0x7f)); 77 /* TODO: 'bad' signal# - coreutils says: 78 * kill: 127: invalid signal 79 * we just print "127" instead */ 80 } else { 81 signo = get_signum(arg); 82 if (signo < 0) { 83 bb_error_msg("unknown signal '%s'", arg); 84 return EXIT_FAILURE; 85 } 86 printf("%d\n", signo); 87 } 60 print_signames(); 61 return 0; 62 } 63 /* -l <sig list> */ 64 while ((arg = *++argv)) { 65 if (isdigit(arg[0])) { 66 signo = bb_strtou(arg, NULL, 10); 67 if (errno) { 68 bb_error_msg("unknown signal '%s'", arg); 69 return EXIT_FAILURE; 70 } 71 /* Exitcodes >= 0x80 are to be treated 72 * as "killed by signal (exitcode & 0x7f)" */ 73 puts(get_signame(signo & 0x7f)); 74 /* TODO: 'bad' signal# - coreutils says: 75 * kill: 127: invalid signal 76 * we just print "127" instead */ 77 } else { 78 signo = get_signum(arg); 79 if (signo < 0) { 80 bb_error_msg("unknown signal '%s'", arg); 81 return EXIT_FAILURE; 82 } 83 printf("%d\n", signo); 88 84 } 89 85 } … … 97 93 arg = *++argv; 98 94 argc--; 99 if (argc < 1) bb_show_usage(); 100 if (arg[0] != '-') goto do_it_now; 101 } 102 103 /* -SIG */ 104 signo = get_signum(&arg[1]); 95 if (argc < 1) 96 bb_show_usage(); 97 if (arg[0] != '-') 98 goto do_it_now; 99 } 100 101 arg++; /* skip '-' */ 102 103 /* -o PID? (if present, it always is at the end of command line) */ 104 if (killall5 && arg[0] == 'o') 105 goto do_it_now; 106 107 if (argc > 1 && arg[0] == 's' && arg[1] == '\0') { /* -s SIG? */ 108 argc--; 109 arg = *++argv; 110 } /* else it must be -SIG */ 111 signo = get_signum(arg); 105 112 if (signo < 0) { /* || signo > MAX_SIGNUM ? */ 106 bb_error_msg("bad signal name '%s'", &arg[1]);113 bb_error_msg("bad signal name '%s'", arg); 107 114 return EXIT_FAILURE; 108 115 } … … 110 117 argc--; 111 118 112 do_it_now: 119 do_it_now: 120 pid = getpid(); 113 121 114 122 if (killall5) { 115 123 pid_t sid; 116 124 procps_status_t* p = NULL; 117 118 /* Now stop all processes */ 125 int ret = 0; 126 127 /* Find out our session id */ 128 sid = getsid(pid); 129 /* Stop all processes */ 119 130 kill(-1, SIGSTOP); 120 /* Find out our own session id */ 121 pid = getpid(); 122 sid = getsid(pid); 123 /* Now kill all processes except our session */ 131 /* Signal all processes except those in our session */ 124 132 while ((p = procps_scan(p, PSSCAN_PID|PSSCAN_SID))) { 125 if (p->sid != sid && p->pid != pid && p->pid != 1) 126 kill(p->pid, signo); 127 } 133 int i; 134 135 if (p->sid == (unsigned)sid 136 || p->pid == (unsigned)pid 137 || p->pid == 1) 138 continue; 139 140 /* All remaining args must be -o PID options. 141 * Check p->pid against them. */ 142 for (i = 0; i < argc; i++) { 143 pid_t omit; 144 145 arg = argv[i]; 146 if (arg[0] != '-' || arg[1] != 'o') { 147 bb_error_msg("bad option '%s'", arg); 148 ret = 1; 149 goto resume; 150 } 151 arg += 2; 152 if (!arg[0] && argv[++i]) 153 arg = argv[i]; 154 omit = bb_strtoi(arg, NULL, 10); 155 if (errno) { 156 bb_error_msg("invalid number '%s'", arg); 157 ret = 1; 158 goto resume; 159 } 160 if (p->pid == omit) 161 goto dont_kill; 162 } 163 kill(p->pid, signo); 164 dont_kill: ; 165 } 166 resume: 128 167 /* And let them continue */ 129 168 kill(-1, SIGCONT); 130 return 0;169 return ret; 131 170 } 132 171 133 172 /* Pid or name is required for kill/killall */ 134 173 if (argc < 1) { 135 puts("You need to specify whom to kill");174 bb_error_msg("you need to specify whom to kill"); 136 175 return EXIT_FAILURE; 137 176 } … … 139 178 if (killall) { 140 179 /* Looks like they want to do a killall. Do that */ 141 pid = getpid();142 180 while (arg) { 143 181 pid_t* pidList; … … 158 196 errors++; 159 197 if (!quiet) 160 bb_perror_msg("can not kill pid %u", (unsigned)*pl);198 bb_perror_msg("can't kill pid %d", (int)*pl); 161 199 } 162 200 } … … 174 212 pid = bb_strtoi(arg, NULL, 10); 175 213 if (errno) { 176 bb_error_msg(" bad pid'%s'", arg);214 bb_error_msg("invalid number '%s'", arg); 177 215 errors++; 178 216 } else if (kill(pid, signo) != 0) { 179 bb_perror_msg("can not kill pid %d", (int)pid);217 bb_perror_msg("can't kill pid %d", (int)pid); 180 218 errors++; 181 219 }
Note:
See TracChangeset
for help on using the changeset viewer.