From patchwork Wed May 11 22:23:36 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 95195 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 3598C1007D1 for ; Thu, 12 May 2011 08:24:01 +1000 (EST) Received: (qmail 18709 invoked by alias); 11 May 2011 22:23:55 -0000 Received: (qmail 18691 invoked by uid 22791); 11 May 2011 22:23:53 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, TW_CP X-Spam-Check-By: sourceware.org Received: from mx01.qsc.de (HELO mx01.qsc.de) (213.148.129.14) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 11 May 2011 22:23:38 +0000 Received: from [192.168.178.22] (port-92-204-45-85.dynamic.qsc.de [92.204.45.85]) by mx01.qsc.de (Postfix) with ESMTP id A83C03CC24; Thu, 12 May 2011 00:23:36 +0200 (CEST) Message-ID: <4DCB0C68.1090601@net-b.de> Date: Thu, 12 May 2011 00:23:36 +0200 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.14) Gecko/20110221 SUSE/3.1.8 Thunderbird/3.1.8 MIME-Version: 1.0 To: gcc patches , gfortran Subject: [Patch, Fortran] PR 48961 - Fix EXECUTE_COMMAND_LINE w/ wait=.false. for non-fork systems Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org The attached patch fixes three issues: a) If fork() is not supported, CMDSTAT is -2 (as required by the standard) - and everything is executed synchronously. However, set_cmdstat will abort if the cmdstat value is not 0. b) The cmdstat value should be set to an error if system returns an error ("-1") -- also for WAIT=.false. c) In the synchronous case with WAIT=.false. the EXITSTAT= value was not set. Additionally, I converted some literals to the EXEC_* enum values. Build on x86-64-linux. OK for the trunk? Tobias PS: The next step would be to add support for asynchronous execution under Windows, cf. PR. 2011-05-12 Tobias Burnus PR fortran/48961 * intrinsics/execute_command_line.c (set_cmdstat): Don't abort if synchronously executing with WAIT=.false. (execute_command_line): Fix setting of cmdstat and exitstat. diff --git a/libgfortran/intrinsics/execute_command_line.c b/libgfortran/intrinsics/execute_command_line.c index 4e3c445..d0b79a4 100644 --- a/libgfortran/intrinsics/execute_command_line.c +++ b/libgfortran/intrinsics/execute_command_line.c @@ -38,9 +38,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #endif -enum { EXEC_NOERROR = 0, EXEC_SYSTEMFAILED }; +enum { EXEC_SYNCHRONOUS = -2, EXEC_NOERROR = 0, EXEC_SYSTEMFAILED, + EXEC_CHILDFAILED }; static const char *cmdmsg_values[] = - { "", "Execution of child process impossible" }; + { "", + "Termination status of the command-language interpreter cannot be obtained", + "Execution of child process impossible" }; @@ -49,7 +52,7 @@ set_cmdstat (int *cmdstat, int value) { if (cmdstat) *cmdstat = value; - else if (value != 0) + else if (value > EXEC_NOERROR) runtime_error ("Could not execute command line"); } @@ -74,10 +77,10 @@ execute_command_line (const char *command, bool wait, int *exitstat, /* Asynchronous execution. */ pid_t pid; - set_cmdstat (cmdstat, 0); + set_cmdstat (cmdstat, EXEC_NOERROR); if ((pid = fork()) < 0) - set_cmdstat (cmdstat, EXEC_SYSTEMFAILED); + set_cmdstat (cmdstat, EXEC_CHILDFAILED); else if (pid == 0) { /* Child process. */ @@ -91,13 +94,15 @@ execute_command_line (const char *command, bool wait, int *exitstat, /* Synchronous execution. */ int res = system (cmd); - if (!wait) - set_cmdstat (cmdstat, -2); - else if (res == -1) + if (res == -1) set_cmdstat (cmdstat, EXEC_SYSTEMFAILED); + else if (!wait) + set_cmdstat (cmdstat, EXEC_SYNCHRONOUS); else + set_cmdstat (cmdstat, EXEC_NOERROR); + + if (res != -1) { - set_cmdstat (cmdstat, 0); #if defined(WEXITSTATUS) && defined(WIFEXITED) *exitstat = WIFEXITED(res) ? WEXITSTATUS(res) : res; #else @@ -107,7 +112,7 @@ execute_command_line (const char *command, bool wait, int *exitstat, } /* Now copy back to the Fortran string if needed. */ - if (cmdstat && *cmdstat > 0) + if (cmdstat && *cmdstat > EXEC_NOERROR) { if (cmdmsg) fstrcpy (cmdmsg, cmdmsg_len, cmdmsg_values[*cmdstat],