From patchwork Wed Jul 8 00:11:39 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 29547 Return-Path: X-Original-To: patchwork-incoming@bilbo.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ozlabs.org (ozlabs.org [203.10.76.45]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "mx.ozlabs.org", Issuer "CA Cert Signing Authority" (verified OK)) by bilbo.ozlabs.org (Postfix) with ESMTPS id 80BDCB7085 for ; Wed, 8 Jul 2009 10:18:59 +1000 (EST) Received: by ozlabs.org (Postfix) id 449DFDDF94; Wed, 8 Jul 2009 10:18:49 +1000 (EST) Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id 3D51DDE054 for ; Wed, 8 Jul 2009 10:18:49 +1000 (EST) X-Original-To: cbe-oss-dev@ozlabs.org Delivered-To: cbe-oss-dev@ozlabs.org Received: from hera.kernel.org (hera.kernel.org [140.211.167.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 68446DDE32; Wed, 8 Jul 2009 10:18:08 +1000 (EST) Received: from hera.kernel.org (IDENT:U2FsdGVkX1/+5ZXCiCOWnMbNig71KlxVHOAIDCk7ra8@localhost [127.0.0.1]) by hera.kernel.org (8.14.2/8.14.2) with ESMTP id n680I2kp026318 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 8 Jul 2009 00:18:02 GMT Received: (from geoff@localhost) by hera.kernel.org (8.14.2/8.13.1/Submit) id n680I2tD026317; Wed, 8 Jul 2009 00:18:02 GMT Message-Id: <20090708001135.296018802@am.sony.com> User-Agent: quilt/0.47-1 Date: Tue, 07 Jul 2009 17:11:39 -0700 From: Geoff Levand To: Jeremy Kerr In-Reply-To: <20090708001134.934244536@am.sony.com> References: <20090708001134.934244536@am.sony.com> Content-Disposition: inline; filename=log-child-output.diff X-Virus-Scanned: ClamAV 0.93.3/9541/Tue Jul 7 17:31:53 2009 on hera.kernel.org X-Virus-Status: Clean X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on hera.kernel.org X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.0 (hera.kernel.org [127.0.0.1]); Wed, 08 Jul 2009 00:18:02 +0000 (UTC) Cc: cbe-oss-dev@ozlabs.org Subject: [Cbe-oss-dev] [patch 05/31] petitboot: Log child output X-BeenThere: cbe-oss-dev@ozlabs.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Discussion about Open Source Software for the Cell Broadband Engine List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: cbe-oss-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org Errors-To: cbe-oss-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org Redirect the output of child processes to pb_log. Signed-off-by: Geoff Levand --- lib/system/system.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) --- a/lib/system/system.c +++ b/lib/system/system.c @@ -3,6 +3,7 @@ #include "config.h" #endif +#include #include #include #include @@ -104,13 +105,13 @@ int pb_rmdir_recursive(const char *base, int pb_run_cmd(const char *const *cmd_argv) { - int status; - pid_t pid; #if defined(DEBUG) enum {do_debug = 1}; #else enum {do_debug = 0}; #endif + int status; + pid_t pid; if (do_debug) { const char *const *p = cmd_argv; @@ -125,12 +126,23 @@ int pb_run_cmd(const char *const *cmd_ar pb_log("%s: %s\n", __func__, cmd_argv[0]); pid = fork(); + if (pid == -1) { pb_log("%s: fork failed: %s\n", __func__, strerror(errno)); return -1; } if (pid == 0) { + int log = fileno(pb_log_get_stream()); + + /* Redirect child output to log. */ + + status = dup2(log, STDOUT_FILENO); + assert(status != -1); + + status = dup2(log, STDERR_FILENO); + assert(status != -1); + execvp(cmd_argv[0], (char *const *)cmd_argv); pb_log("%s: exec failed: %s\n", __func__, strerror(errno)); exit(EXIT_FAILURE);