summaryrefslogtreecommitdiffstats
path: root/abs/core-testing/sysvinit-mod/sysvinit.diff
blob: d26f7cc802f86bbd22ad9fb67652a10d1ba55871 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
diff -r -u sysvinit-2.86/COPYRIGHT sysvinit-2.86.patched/COPYRIGHT
--- sysvinit-2.86/COPYRIGHT	2004-07-30 12:12:12.000000000 +0000
+++ sysvinit-2.86.patched/COPYRIGHT	2008-04-15 14:28:52.000000000 +0000
@@ -12,7 +12,7 @@
 
     You should have received a copy of the GNU General Public License
     along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
 On Debian GNU/Linux systems, the complete text of the GNU General
 Public License can be found in `/usr/share/common-licenses/GPL'.
diff -r -u sysvinit-2.86/man/killall5.8 sysvinit-2.86.patched/man/killall5.8
--- sysvinit-2.86/man/killall5.8	2004-06-09 12:47:45.000000000 +0000
+++ sysvinit-2.86.patched/man/killall5.8	2008-04-15 14:28:52.000000000 +0000
@@ -4,14 +4,29 @@
 .SH SYNOPSIS
 .B killall5
 .RB -signalnumber
+.RB [ \-o
+.IR omitpid ]
+.RB [ \-o
+.IR omitpid.. ]
 .SH DESCRIPTION
 .B killall5
 is the SystemV killall command. It sends a signal to all processes except
 kernel threads and the processes in its own session, so it won't kill
 the shell that is running the script it was called from. Its primary
 (only) use is in the \fBrc\fP scripts found in the /etc/init.d directory.
+.SH OPTIONS
+.IP "-o \fIomitpid\fP"
+Tells \fIkillall5\fP to omit processes with that process id.
+.SH NOTES
+\fIkillall5\fP can also be invoked as pidof, which is simply a
+(symbolic) link to the \fIkillall5\fP program.
+.SH EXIT STATUS
+The program return zero if it killed processes.  It return 2 if no
+process were killed, and 1 if it was unable to find any processes
+(/proc/ is missing).
 .SH SEE ALSO
 .BR halt (8),
-.BR reboot (8)
+.BR reboot (8),
+.BR pidof (8)
 .SH AUTHOR
 Miquel van Smoorenburg, miquels@cistron.nl
diff -r -u sysvinit-2.86/man/pidof.8 sysvinit-2.86.patched/man/pidof.8
--- sysvinit-2.86/man/pidof.8	1998-09-02 12:49:33.000000000 +0000
+++ sysvinit-2.86.patched/man/pidof.8	2008-04-15 14:28:52.000000000 +0000
@@ -27,13 +27,20 @@
 .IP -x
 Scripts too - this causes the program to also return process id's of
 shells running the named scripts.
-.IP -o \fIomitpid\fP
+.IP "-o \fIomitpid\fP"
 Tells \fIpidof\fP to omit processes with that process id. The special
 pid \fB%PPID\fP can be used to name the parent process of the \fIpidof\fP
 program, in other words the calling shell or shell script.
+.SH "EXIT STATUS"
+.TP
+.B 0
+At least one program was found with the requested name.
+.TP
+.B 1
+No program was found with the requested name.
 .SH NOTES
-\fIpidof\fP is simply a (symbolic) link to the \fIkillall5\fP program,
-which should also be located in \fP/sbin\fP.
+\fIpidof\fP is actually the same program as \fIkillall5\fP;
+the program behaves according to the name under which it is called.
 .PP
 When \fIpidof\fP is invoked with a full pathname to the program it
 should find the pid of, it is reasonably safe. Otherwise it is possible
@@ -43,6 +50,7 @@
 .BR shutdown (8),
 .BR init (8),
 .BR halt (8),
-.BR reboot (8)
+.BR reboot (8),
+.BR killall5 (8)
 .SH AUTHOR
 Miquel van Smoorenburg, miquels@cistron.nl
diff -r -u sysvinit-2.86/src/killall5.c sysvinit-2.86.patched/src/killall5.c
--- sysvinit-2.86/src/killall5.c	2004-07-30 12:16:23.000000000 +0000
+++ sysvinit-2.86.patched/src/killall5.c	2008-04-15 14:28:52.000000000 +0000
@@ -378,8 +378,8 @@
 	int		foundone = 0;
 	int		ok = 0;
 
-	/* Try to stat the executable. */
-	if (prog[0] == '/' && stat(prog, &st) == 0) dostat++;
+	if (! prog)
+		return NULL;
 
 	/* Get basename of program. */
 	if ((s = strrchr(prog, '/')) == NULL)
@@ -387,9 +387,16 @@
 	else
 		s++;
 
+	if (! *s)
+		return NULL;
+
 	q = (PIDQ_HEAD *)xmalloc(sizeof(PIDQ_HEAD));
 	q = init_pid_q(q);
 
+	/* Try to stat the executable. */
+	if (prog[0] == '/' && stat(prog, &st) == 0)
+		dostat++;
+
 	/* First try to find a match based on dev/ino pair. */
 	if (dostat) {
 		for (p = plist; p; p = p->next) {
@@ -404,15 +411,35 @@
 	if (!foundone) for (p = plist; p; p = p->next) {
 		ok = 0;
 
-		/* Compare name (both basename and full path) */
-		ok += (p->argv0 && strcmp(p->argv0, prog) == 0);
-		ok += (p->argv0 && strcmp(p->argv0base, s) == 0);
+		/*             matching        nonmatching
+		 * proc name   prog name       prog name
+		 * ---         -----------     ------------
+		 *   b         b, p/b, q/b
+		 * p/b         b, p/b          q/b
+		 *
+		 * Algorithm: Match if:
+		 *    cmd = arg
+		 * or cmd = base(arg)
+		 * or base(cmd) = arg
+		 *
+		 * Specifically, do not match just because base(cmd) = base(arg)
+		 * as was done in earlier versions of this program, since this
+		 * allows /aaa/foo to match /bbb/foo .
+		 */
+		ok |=
+			(p->argv0 && strcmp(p->argv0, prog) == 0)
+			|| (p->argv0 && s != prog && strcmp(p->argv0, s) == 0)
+			|| (p->argv0base && strcmp(p->argv0base, prog) == 0);
 
 		/* For scripts, compare argv[1] as well. */
-		if (scripts_too && p->argv1 &&
-		    !strncmp(p->statname, p->argv1base, STATNAMELEN)) {
-			ok += (strcmp(p->argv1, prog) == 0);
-			ok += (strcmp(p->argv1base, s) == 0);
+		if (
+			scripts_too && p->statname && p->argv1base
+			&& !strncmp(p->statname, p->argv1base, STATNAMELEN)
+		) {
+			ok |=
+				(p->argv1 && strcmp(p->argv1, prog) == 0)
+				|| (p->argv1 && s != prog && strcmp(p->argv1, s) == 0)
+				|| (p->argv1base && strcmp(p->argv1base, prog) == 0);
 		}
 
 		/*
@@ -423,7 +450,7 @@
 		    (p->argv0 == NULL ||
 		     p->argv0[0] == 0 ||
 		     strchr(p->argv0, ' '))) {
-			ok += (strcmp(p->statname, s) == 0);
+			ok |= (strcmp(p->statname, s) == 0);
 		}
 		if (ok) add_pid_to_q(q, p);
 	}
@@ -548,20 +575,28 @@
 			}
 		}
 	}
-	printf("\n");
+	if (!first)
+		printf("\n");
 	closelog();
 	return(first ? 1 : 0);
 }
 
 
 
+#define KILLALL_OMITSZ	16
+
 /* Main for either killall or pidof. */
 int main(int argc, char **argv)
 {
 	PROC		*p;
 	int		pid, sid = -1;
+	pid_t		opid[KILLALL_OMITSZ];
+	int		i, oind, omit = 0;
 	int		sig = SIGKILL;
 
+	/* return non-zero if no process was killed */
+	int		retval = 2;
+
 	/* Get program name. */
 	if ((progname = strrchr(argv[0], '/')) == NULL)
 		progname = argv[0];
@@ -576,10 +611,34 @@
 		return main_pidof(argc, argv);
 
 	/* Right, so we are "killall". */
+	for (oind = KILLALL_OMITSZ-1; oind > 0; oind--)
+		opid[oind] = 0;
+
 	if (argc > 1) {
-		if (argc != 2) usage();
-		if (argv[1][0] == '-') (argv[1])++;
-		if ((sig = atoi(argv[1])) <= 0 || sig > 31) usage();
+		for (i = 1; i < argc; i++) {
+			if (argv[i][0] == '-') (argv[i])++;
+			if (argv[i][0] == 'o') {
+				if (++i >= argc) usage();
+				if (oind >= KILLALL_OMITSZ -1) {
+					nsyslog(LOG_ERR,"omit pid buffer size "
+						"%d exceeded!\n",
+						KILLALL_OMITSZ);
+					closelog();
+					exit(1);
+				}
+				if ((opid[oind] = atoi(argv[i])) < 1) {
+					nsyslog(LOG_ERR,
+						"illegal omit pid value "
+						"(%s)!\n", argv[i]);
+					closelog();
+					exit(1);
+				}
+				oind++;
+				omit = 1;
+			}
+			else if ((sig = atoi(argv[1])) <= 0 || sig > 31)
+				usage();
+		}
 	}
 
 	/* First get the /proc filesystem online. */
@@ -602,15 +661,26 @@
 	/* Read /proc filesystem */
 	if (readproc() < 0) {
 		kill(-1, SIGCONT);
-		exit(1);
+		return(1);
 	}
 
-	/* Now kill all processes except our session. */
+	/* Now kill all processes except init (pid 1) and our session. */
 	sid = (int)getsid(0);
 	pid = (int)getpid();
-	for (p = plist; p; p = p->next)
-		if (p->pid != pid && p->sid != sid && !p->kernel)
-			kill(p->pid, sig);
+	for (p = plist; p; p = p->next) {
+		if (p->pid == 1 || p->pid == pid || p->sid == sid || p->kernel)
+			continue;
+		if (omit) {
+			for (i = 0; i < oind; i++)
+				if (opid[i] == p->pid)
+					break;
+			/* On a match, continue with the for loop above. */
+			if (i < oind)
+				continue;
+		}
+		kill(p->pid, sig);
+		retval = 0;
+	}
 
 	/* And let them continue. */
 	kill(-1, SIGCONT);
@@ -618,5 +688,8 @@
 	/* Done. */
 	closelog();
 
-	return 0;
+	/* Force the kernel to run the scheduler */
+	usleep(1);
+
+	return retval;
 }