summaryrefslogtreecommitdiff
path: root/libgfortran/intrinsics
diff options
context:
space:
mode:
authorburnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4>2011-05-14 06:35:18 +0000
committerburnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4>2011-05-14 06:35:18 +0000
commit96cb28340343e35fc361b061ad2c55336ef613c7 (patch)
tree81bdaf969181cf13f0189259f9ec948ad548a711 /libgfortran/intrinsics
parent3d519d6904bcc1e1c47a25e954ef8fd9870f3144 (diff)
downloadgcc-96cb28340343e35fc361b061ad2c55336ef613c7.tar.gz
2011-05-14 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@173748 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgfortran/intrinsics')
-rw-r--r--libgfortran/intrinsics/execute_command_line.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/libgfortran/intrinsics/execute_command_line.c b/libgfortran/intrinsics/execute_command_line.c
index 4e3c4451d62..d0b79a45a52 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],