[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [OSSTEST PATCH 2/6] sg-run-job: Support scripts which need to be told when to quit



We give them a pipe on stdin, whose writing end we close when we want
to reap them.

Signed-off-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
---
 sg-run-job | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/sg-run-job b/sg-run-job
index fd109e1..34462c7 100755
--- a/sg-run-job
+++ b/sg-run-job
@@ -234,6 +234,11 @@ proc testid_matches_globs {testid globs} {
 #       to find the script in the current directory.  This will be
 #       added implicitly.
 #
+#       If the very first item is "|" (before the script name), the
+#       script will get a pipe as its standard input rather than
+#       /dev/null; this pipe will give EOF when sg-run-job wants to
+#       end the script (ie, when reap-ts is called).
+#
 #       An argument which is precisely "+" toggles whether the
 #       subsequent items in SCRIPT-ARGS are added to the expansion of
 #       /@ in TESTID.  (The "+" itself is not added to the arguments
@@ -289,6 +294,12 @@ proc spawn-ts {iffail testid args} {
     set real_args {}
     set adding 1
     set testid_args {}
+    set child_pipe_mode r
+
+    if {![string compare | [lindex $args 0]]} {
+       set child_pipe_mode w
+       lshift args
+    }
     foreach arg $args {
         if {![string compare + $arg]} {
             set adding [expr {!$adding}]
@@ -335,12 +346,16 @@ proc spawn-ts {iffail testid args} {
     if {[var-or-default env(OSSTEST_SIMULATE) 0]} { set xprefix echo }
 
     set log [jobdb::step-log-filename $flight $jobinfo(job) $stepno $ts]
-    set redirects {< /dev/null}
+    set redirects {}
     if {[string length $log]} {
         lappend redirects 2> $log
     } else {
         lappend redirects 2>@ stderr
     }
+    switch -exact $child_pipe_mode {
+       r { lappend redirects < /dev/null }
+       w { lappend redirects >@ stderr }
+    }
 
     set cmd [concat \
                  [list sh -xc "
@@ -353,7 +368,7 @@ proc spawn-ts {iffail testid args} {
                      exit \$rc
                  " x $testid ./$ts] \
                  $real_args $redirects]
-    set fh [open |$cmd r]
+    set fh [open |$cmd $child_pipe_mode]
     return [list fh $fh $details]
 }
 
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.