View | Details | Raw Unified | Return to bug 197608 | Differences between
and this patch

Collapse All | Expand All

(-)b/usr.bin/timeout/timeout.c (-13 / +19 lines)
Lines 172-177 main(int argc, char **argv) Link Here
172
	double second_kill;
172
	double second_kill;
173
	bool timedout = false;
173
	bool timedout = false;
174
	bool do_second_kill = false;
174
	bool do_second_kill = false;
175
	bool child_done = false;
175
	struct sigaction signals;
176
	struct sigaction signals;
176
	struct procctl_reaper_status info;
177
	struct procctl_reaper_status info;
177
	struct procctl_reaper_kill killemall;
178
	struct procctl_reaper_kill killemall;
Lines 187-193 main(int argc, char **argv) Link Here
187
188
188
	foreground = preserve = 0;
189
	foreground = preserve = 0;
189
	second_kill = 0;
190
	second_kill = 0;
190
	cpid = -1;
191
191
192
	const struct option longopts[] = {
192
	const struct option longopts[] = {
193
		{ "preserve-status", no_argument,       &preserve,    1 },
193
		{ "preserve-status", no_argument,       &preserve,    1 },
Lines 281-300 main(int argc, char **argv) Link Here
281
281
282
		if (sig_chld) {
282
		if (sig_chld) {
283
			sig_chld = 0;
283
			sig_chld = 0;
284
			while (((cpid = wait(&status)) < 0) && errno == EINTR)
285
				continue;
286
284
287
			if (cpid == pid) {
285
			while ((cpid = waitpid(-1, &status, WNOHANG)) != 0) {
288
				pstat = status;
286
				if (cpid < 0) {
289
				if (!foreground)
287
					if (errno == EINTR)
290
					break;
288
						continue;
289
					else
290
						break;
291
				} else if (cpid == pid) {
292
					pstat = status;
293
					child_done = true;
294
				}
291
			}
295
			}
292
			if (!foreground) {
296
			if (child_done) {
293
				procctl(P_PID, getpid(), PROC_REAP_STATUS,
297
				if (foreground) {
294
				    &info);
295
				if (info.rs_children == 0) {
296
					cpid = pid;
297
					break;
298
					break;
299
				} else {
300
					procctl(P_PID, getpid(),
301
					    PROC_REAP_STATUS, &info);
302
					if (info.rs_children == 0)
303
						break;
298
				}
304
				}
299
			}
305
			}
300
		} else if (sig_alrm) {
306
		} else if (sig_alrm) {
Lines 336-342 main(int argc, char **argv) Link Here
336
		}
342
		}
337
	}
343
	}
338
344
339
	while (cpid != pid  && wait(&pstat) == -1) {
345
	while (!child_done && wait(&pstat) == -1) {
340
		if (errno != EINTR)
346
		if (errno != EINTR)
341
			err(EX_OSERR, "waitpid()");
347
			err(EX_OSERR, "waitpid()");
342
	}
348
	}

Return to bug 197608