diff options
author | Eric Andersen <andersen@codepoet.org> | 1999-10-05 16:24:54 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 1999-10-05 16:24:54 +0000 |
commit | cc8ed39b240180b58810784f844e253263594ac3 (patch) | |
tree | 15feebbb4be9a9168209609f48f0b100f9364420 /kill.c | |
download | busybox-w32-0_29alpha2.tar.gz busybox-w32-0_29alpha2.tar.bz2 busybox-w32-0_29alpha2.zip |
Initial revision0_29alpha2
Diffstat (limited to 'kill.c')
-rw-r--r-- | kill.c | 140 |
1 files changed, 140 insertions, 0 deletions
@@ -0,0 +1,140 @@ | |||
1 | #include "internal.h" | ||
2 | #include <stdio.h> | ||
3 | #include <stdlib.h> | ||
4 | #include <unistd.h> | ||
5 | #include <signal.h> | ||
6 | |||
7 | const char kill_usage[] = "kill [-signal] process-id [process-id ...]\n"; | ||
8 | |||
9 | struct signal_name { | ||
10 | const char * name; | ||
11 | int number; | ||
12 | }; | ||
13 | |||
14 | const struct signal_name signames[] = { | ||
15 | { "HUP", SIGHUP }, | ||
16 | { "INT", SIGINT }, | ||
17 | { "QUIT", SIGQUIT }, | ||
18 | { "ILL", SIGILL }, | ||
19 | { "TRAP", SIGTRAP }, | ||
20 | { "ABRT", SIGABRT }, | ||
21 | #ifndef __alpha__ | ||
22 | { "IOT", SIGIOT }, | ||
23 | #endif | ||
24 | #if defined(sparc) || defined(__alpha__) | ||
25 | { "EMT", SIGEMT }, | ||
26 | #else | ||
27 | { "BUS", SIGBUS }, | ||
28 | #endif | ||
29 | { "FPE", SIGFPE }, | ||
30 | { "KILL", SIGKILL }, | ||
31 | #if defined(sparc) || defined(__alpha__) | ||
32 | { "BUS", SIGBUS }, | ||
33 | #else | ||
34 | { "USR1", SIGUSR1 }, | ||
35 | #endif | ||
36 | { "SEGV", SIGSEGV }, | ||
37 | #if defined(sparc) || defined(__alpha__) | ||
38 | { "SYS", SIGSYS }, | ||
39 | #else | ||
40 | { "USR2", SIGUSR2 }, | ||
41 | #endif | ||
42 | { "PIPE", SIGPIPE }, | ||
43 | { "ALRM", SIGALRM }, | ||
44 | { "TERM", SIGTERM }, | ||
45 | #if defined(sparc) || defined(__alpha__) | ||
46 | { "URG", SIGURG }, | ||
47 | { "STOP", SIGSTOP }, | ||
48 | { "TSTP", SIGTSTP }, | ||
49 | { "CONT", SIGCONT }, | ||
50 | { "CHLD", SIGCHLD }, | ||
51 | { "TTIN", SIGTTIN }, | ||
52 | { "TTOU", SIGTTOU }, | ||
53 | { "IO", SIGIO }, | ||
54 | # ifndef __alpha__ | ||
55 | { "POLL", SIGIO }, | ||
56 | # endif | ||
57 | { "XCPU", SIGXCPU }, | ||
58 | { "XFSZ", SIGXFSZ }, | ||
59 | { "VTALRM", SIGVTALRM }, | ||
60 | { "PROF", SIGPROF }, | ||
61 | { "WINCH", SIGWINCH }, | ||
62 | # ifdef __alpha__ | ||
63 | { "INFO", SIGINFO }, | ||
64 | # else | ||
65 | { "LOST", SIGLOST }, | ||
66 | # endif | ||
67 | { "USR1", SIGUSR1 }, | ||
68 | { "USR2", SIGUSR2 }, | ||
69 | #else | ||
70 | { "STKFLT", SIGSTKFLT }, | ||
71 | { "CHLD", SIGCHLD }, | ||
72 | { "CONT", SIGCONT }, | ||
73 | { "STOP", SIGSTOP }, | ||
74 | { "TSTP", SIGTSTP }, | ||
75 | { "TTIN", SIGTTIN }, | ||
76 | { "TTOU", SIGTTOU }, | ||
77 | { "URG", SIGURG }, | ||
78 | { "XCPU", SIGXCPU }, | ||
79 | { "XFSZ", SIGXFSZ }, | ||
80 | { "VTALRM", SIGVTALRM }, | ||
81 | { "PROF", SIGPROF }, | ||
82 | { "WINCH", SIGWINCH }, | ||
83 | { "IO", SIGIO }, | ||
84 | { "POLL", SIGPOLL }, | ||
85 | { "PWR", SIGPWR }, | ||
86 | { "UNUSED", SIGUNUSED }, | ||
87 | #endif | ||
88 | { 0, 0 } | ||
89 | }; | ||
90 | |||
91 | extern int | ||
92 | kill_main(struct FileInfo * i, int argc, char * * argv) | ||
93 | { | ||
94 | int had_error = 0; | ||
95 | int sig = SIGTERM; | ||
96 | if ( argv[1][0] == '-' ) { | ||
97 | if ( argv[1][1] >= '0' && argv[1][1] <= '9' ) { | ||
98 | sig = atoi(&argv[1][1]); | ||
99 | if ( sig < 0 || sig >= NSIG ) { | ||
100 | usage(kill_usage); | ||
101 | exit(-1); | ||
102 | } | ||
103 | } | ||
104 | else { | ||
105 | const struct signal_name * s = signames; | ||
106 | for ( ; ; ) { | ||
107 | if ( strcmp(s->name, &argv[1][1]) == 0 ) { | ||
108 | sig = s->number; | ||
109 | break; | ||
110 | } | ||
111 | s++; | ||
112 | if ( s->name == 0 ) { | ||
113 | usage(kill_usage); | ||
114 | exit(-1); | ||
115 | } | ||
116 | } | ||
117 | } | ||
118 | argv++; | ||
119 | argc--; | ||
120 | |||
121 | } | ||
122 | while ( argc > 1 ) { | ||
123 | int pid; | ||
124 | if ( argv[1][0] < '0' || argv[1][0] > '9' ) { | ||
125 | usage(kill_usage); | ||
126 | exit(-1); | ||
127 | } | ||
128 | pid = atoi(argv[1]); | ||
129 | if ( kill(pid, sig) != 0 ) { | ||
130 | had_error = 1; | ||
131 | perror(argv[1]); | ||
132 | } | ||
133 | argv++; | ||
134 | argc--; | ||
135 | } | ||
136 | if ( had_error ) | ||
137 | return -1; | ||
138 | else | ||
139 | return 0; | ||
140 | } | ||