changeset 751:d0157468f73d

Prevent smoketest-all.sh from hanging if an individual smoketest.sh doesn't exit properly.
author Rob Landley <rob@landley.net>
date Thu, 18 Jun 2009 04:31:44 -0500
parents adfe2f5bd737
children 9f6b0cad047c
files run-from-build.sh smoketest.sh sources/patches/busybox-pgrep.patch sources/toys/run-emulator.sh
diffstat 4 files changed, 151 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/run-from-build.sh	Mon Jun 15 03:22:00 2009 -0500
+++ b/run-from-build.sh	Thu Jun 18 04:31:44 2009 -0500
@@ -19,5 +19,7 @@
 
 # And run it, using the distccd we built (if necessary) and the cross-compiler.
 
+trap "pkill -P$$" EXIT
+
 ./run-emulator.sh --make-hdb 2048 --memory 256 --with-distcc \
 	"${BUILD}/cross-compiler-${ARCH}"
--- a/smoketest.sh	Mon Jun 15 03:22:00 2009 -0500
+++ b/smoketest.sh	Thu Jun 18 04:31:44 2009 -0500
@@ -7,12 +7,12 @@
 
 timeout()
 {
-  sleep 60
+  sleep 45
   kill $1
 }
 
 timeout $$ &
-trap "kill $(jobs -p) 2>/dev/null" EXIT
+trap "pkill -P$$" EXIT
 
 # Call run-from-build with a here document to do stuff.
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sources/patches/busybox-pgrep.patch	Thu Jun 18 04:31:44 2009 -0500
@@ -0,0 +1,143 @@
+diff --git a/include/usage.h b/include/usage.h
+index e606925..20fd909 100644
+--- a/include/usage.h
++++ b/include/usage.h
+@@ -3207,7 +3207,7 @@
+        "$ patch -p0 -i example.diff"
+ 
+ #define pgrep_trivial_usage \
+-       "[-flnovx] pattern"
++       "[-flnovx] [-s SID|-P ppid|pattern]"
+ #define pgrep_full_usage "\n\n" \
+        "Display process(es) selected by regex pattern\n" \
+      "\nOptions:" \
+@@ -3217,6 +3217,8 @@
+      "\n	-o	Show the oldest process only" \
+      "\n	-v	Negate the matching" \
+      "\n	-x	Match whole name (not substring)" \
++     "\n	-s	Match session ID (0 for this one)" \
++     "\n	-P	Match parent process ID" \
+ 
+ #if (ENABLE_FEATURE_PIDOF_SINGLE || ENABLE_FEATURE_PIDOF_OMIT)
+ #define pidof_trivial_usage \
+@@ -3309,7 +3311,8 @@
+        "the new root file system"
+ 
+ #define pkill_trivial_usage \
+-       "[-l] | [-fnovx] [-signal] pattern"
++       "[-l|-SIGNAL] [-fnovx] [-s SID|-P ppid|pattern]"
++
+ #define pkill_full_usage "\n\n" \
+        "Send a signal to process(es) selected by regex pattern\n" \
+      "\nOptions:" \
+@@ -3319,6 +3322,10 @@
+      "\n	-o	Signal the oldest process only" \
+      "\n	-v	Negate the matching" \
+      "\n	-x	Match whole name (not substring)" \
++     "\n	-s	Match session ID (0 for this one)" \
++     "\n	-P	Match parent process ID" \
++     "\n\nSignal, if present, must be first option."
++
+ 
+ #define popmaildir_trivial_usage \
+        "[OPTIONS] Maildir [connection-helper ...]"
+diff --git a/procps/pgrep.c b/procps/pgrep.c
+index 0e8e529..a336bdf 100644
+--- a/procps/pgrep.c
++++ b/procps/pgrep.c
+@@ -49,10 +49,8 @@ int pgrep_main(int argc UNUSED_PARAM, char **argv)
+ 	int signo = SIGTERM;
+ 	unsigned opt;
+ 	int scan_mask = PSSCAN_COMM;
+-	char *first_arg;
+-	int first_arg_idx;
+-	int matched_pid;
+-	char *cmd_last;
++	int matched_pid, matched_sid = 0, matched_ppid = 0;
++	char *cmd_last, *which_sid = NULL, *which_ppid = NULL;
+ 	procps_status_t *proc;
+ 	/* These are initialized to 0 */
+ 	struct {
+@@ -64,45 +62,39 @@ int pgrep_main(int argc UNUSED_PARAM, char **argv)
+ 
+ 	memset(&Z, 0, sizeof(Z));
+ 
+-	/* We must avoid interpreting -NUM (signal num) as an option */
+-	first_arg_idx = 1;
+-	while (1) {
+-		first_arg = argv[first_arg_idx];
+-		if (!first_arg)
+-			break;
+-		/* not "-<small_letter>..."? */
+-		if (first_arg[0] != '-' || first_arg[1] < 'a' || first_arg[1] > 'z') {
+-			argv[first_arg_idx] = NULL; /* terminate argv here */
+-			break;
++	/* Parse -SIGNAL for pkill.  Must be first option, if present. */
++	if (pkill && argv[1] && argv[1][0]=='-') {
++		int temp = get_signum(argv[1]+1);
++		if (temp != -1) {
++			signo = temp;
++			argv++;
+ 		}
+-		first_arg_idx++;
+ 	}
+-	opt = getopt32(argv, "vlfxon");
+-	argv[first_arg_idx] = first_arg;
++
++	/* Parse remaining options */
++	opt = getopt32(argv, "vlfxons:P:", &which_sid, &which_ppid);
++
++	if (pkill && OPT_LIST) { /* -l: print the whole signal list */
++		print_signames();
++		return 0;
++	}
++
++	if (which_sid) {
++		matched_sid = xatol(which_sid);
++		if (!matched_sid) matched_sid = getsid(pid);
++	}
++	if (which_ppid) matched_ppid = xatol(which_ppid);
+ 
+ 	argv += optind;
+ 	//argc -= optind; - unused anyway
+ 	if (OPT_FULL)
+ 		scan_mask |= PSSCAN_ARGVN;
+ 
+-	if (pkill) {
+-		if (OPT_LIST) { /* -l: print the whole signal list */
+-			print_signames();
+-			return 0;
+-		}
+-		if (first_arg && first_arg[0] == '-') {
+-			signo = get_signum(&first_arg[1]);
+-			if (signo < 0) /* || signo > MAX_SIGNUM ? */
+-				bb_error_msg_and_die("bad signal name '%s'", &first_arg[1]);
+-			argv++;
+-		}
+-	}
+-
+ 	/* One pattern is required */
+-	if (!argv[0] || argv[1])
++	if (!which_sid && !which_ppid && (!argv[0] || argv[1]))
+ 		bb_show_usage();
+ 
+-	xregcomp(&re_buffer, argv[0], 0);
++	if (argv[0]) xregcomp(&re_buffer, argv[0], 0);
+ 	matched_pid = 0;
+ 	cmd_last = NULL;
+ 	proc = NULL;
+@@ -120,8 +112,13 @@ int pgrep_main(int argc UNUSED_PARAM, char **argv)
+ 				i--;
+ 			}
+ 		}
++
++		if (matched_ppid && matched_ppid != proc->ppid) continue;
++		if (matched_sid && matched_sid != proc->sid) continue;
++
+ 		/* NB: OPT_INVERT is always 0 or 1 */
+-		if ((regexec(&re_buffer, cmd, 1, re_match, 0) == 0 /* match found */
++		if (!argv[0] ||
++			(regexec(&re_buffer, cmd, 1, re_match, 0) == 0 /* match found */
+ 		     && (!OPT_ANCHOR || (re_match[0].rm_so == 0 && re_match[0].rm_eo == (regoff_t)strlen(cmd)))) ^ OPT_INVERT
+ 		) {
+ 			matched_pid = proc->pid;
--- a/sources/toys/run-emulator.sh	Mon Jun 15 03:22:00 2009 -0500
+++ b/sources/toys/run-emulator.sh	Thu Jun 18 04:31:44 2009 -0500
@@ -107,5 +107,9 @@
 
 [ -e "$HDB" ] && WITH_HDB="-hdb $HDB"
 
+# Kill our child processes on exit.
+
+trap "pkill -P$$" EXIT
+
 # The actual emulator invocation command gets appended here