From patchwork Wed Jun 21 14:13:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Jackson X-Patchwork-Id: 9801927 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5E0C360329 for ; Wed, 21 Jun 2017 14:16:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4EFE026222 for ; Wed, 21 Jun 2017 14:16:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 43BAA28389; Wed, 21 Jun 2017 14:16:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3BC5626222 for ; Wed, 21 Jun 2017 14:16:19 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dNgP0-000582-Db; Wed, 21 Jun 2017 14:14:38 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dNgOz-000573-MK for xen-devel@lists.xenproject.org; Wed, 21 Jun 2017 14:14:37 +0000 Received: from [193.109.254.147] by server-5.bemta-6.messagelabs.com id 2D/BC-03371-D4F7A495; Wed, 21 Jun 2017 14:14:37 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpgkeJIrShJLcpLzFFi42JxWrohUten3iv S4NViEYvvWyYzOTB6HP5whSWAMYo1My8pvyKBNePhycPsBT8FKua8Wc/cwLiAp4uRk0NCwF/i 16ND7CA2m4CuRNOWv2xdjBwcIgIqErf3GoCYzAKhEjteWIJUCAvEShzYfJ4JxGYRUJU4//8WG 4jNK+ApsXPHfSaIiXIS54//ZAZp5RTwklj8yB/EFAIqmX/KD8JUk5i7Ph6iUVDi5MwnLCA2s4 CExMEXL5gnMPLOQpKahSS1gJFpFaNGcWpRWWqRrpGpXlJRZnpGSW5iZo6uoYGZXm5qcXFiemp OYlKxXnJ+7iZGYMgwAMEOxlULAg8xSnIwKYnylnt7RQrxJeWnVGYkFmfEF5XmpBYfYpTh4FCS 4D1ZC5QTLEpNT61Iy8wBBi9MWoKDR0mEd00JUJq3uCAxtzgzHSJ1ilFRSpz3BEifAEgiozQPr g0WMZcYZaWEeRmBDhHiKUgtys0sQZV/xSjOwagkzHuwBmgKT2ZeCdz0V0CLmYAWvzjiAbK4JB EhJdXA2Fj/9twxlffij3MiXz112ZWXInpj5coFZwxMOs4f9tzCq5IkcORMw0aBj0ekpPoWBO3 isIhdr/LO0vNCy3uFwOt7Dh5oYAv7ybzihPSNk1VXVlfu3upz6tUitSNRmns+/by18tmz52zO /Npsfn/XCpu9z729Uyxym8CV8n1z7Rgvbn8XrGaov1eJpTgj0VCLuag4EQDaOA5okwIAAA== X-Env-Sender: prvs=33896ecda=Ian.Jackson@citrix.com X-Msg-Ref: server-13.tower-27.messagelabs.com!1498054474!99281155!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 44375 invoked from network); 21 Jun 2017 14:14:36 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-13.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 21 Jun 2017 14:14:36 -0000 X-IronPort-AV: E=Sophos;i="5.39,369,1493683200"; d="scan'208";a="428818067" From: Ian Jackson To: Date: Wed, 21 Jun 2017 15:13:57 +0100 Message-ID: <1498054447-11281-6-git-send-email-ian.jackson@eu.citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1498054447-11281-1-git-send-email-ian.jackson@eu.citrix.com> References: <1498054447-11281-1-git-send-email-ian.jackson@eu.citrix.com> MIME-Version: 1.0 Cc: Ian Jackson Subject: [Xen-devel] [OSSTEST PATCH 05/15] sg-run-job: Support scripts which need to be told when to quit X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP We give them a pipe on stdin, whose writing end we close when we want to reap them. Signed-off-by: Ian Jackson --- sg-run-job | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/sg-run-job b/sg-run-job index b820642..8acb902 100755 --- a/sg-run-job +++ b/sg-run-job @@ -238,6 +238,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 @@ -293,6 +298,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}] @@ -339,12 +350,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 " @@ -357,7 +372,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] }