* [Patch, Fortran] PR 48961 - Fix EXECUTE_COMMAND_LINE w/ wait=.false. for non-fork systems
@ 2011-05-12 8:42 Tobias Burnus
2011-05-14 10:25 ` Steve Kargl
0 siblings, 1 reply; 2+ messages in thread
From: Tobias Burnus @ 2011-05-12 8:42 UTC (permalink / raw)
To: gcc patches, gfortran
[-- Attachment #1: Type: text/plain, Size: 625 bytes --]
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.
[-- Attachment #2: PR48961.diff --]
[-- Type: text/x-patch, Size: 2471 bytes --]
2011-05-12 Tobias Burnus <burnus@net-b.de>
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],
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Patch, Fortran] PR 48961 - Fix EXECUTE_COMMAND_LINE w/ wait=.false. for non-fork systems
2011-05-12 8:42 [Patch, Fortran] PR 48961 - Fix EXECUTE_COMMAND_LINE w/ wait=.false. for non-fork systems Tobias Burnus
@ 2011-05-14 10:25 ` Steve Kargl
0 siblings, 0 replies; 2+ messages in thread
From: Steve Kargl @ 2011-05-14 10:25 UTC (permalink / raw)
To: Tobias Burnus; +Cc: gcc patches, gfortran
On Thu, May 12, 2011 at 12:23:36AM +0200, Tobias Burnus wrote:
> 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.
This is OK with a proper ChangeLog entry.
--
Steve
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-05-14 0:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-12 8:42 [Patch, Fortran] PR 48961 - Fix EXECUTE_COMMAND_LINE w/ wait=.false. for non-fork systems Tobias Burnus
2011-05-14 10:25 ` Steve Kargl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).