/* Implementation of the EXECUTE_COMMAND_LINE intrinsic.
- Copyright (C) 2009-2014 Free Software Foundation, Inc.
- Contributed by FranÃ\83§ois-Xavier Coudert.
+ Copyright (C) 2009-2018 Free Software Foundation, Inc.
+ Contributed by François-Xavier Coudert.
This file is part of the GNU Fortran runtime library (libgfortran).
#include "libgfortran.h"
#include <string.h>
-#include <stdlib.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
enum { EXEC_SYNCHRONOUS = -2, EXEC_NOERROR = 0, EXEC_SYSTEMFAILED,
- EXEC_CHILDFAILED };
+ EXEC_CHILDFAILED, EXEC_INVALIDCOMMAND };
static const char *cmdmsg_values[] =
{ "",
"Termination status of the command-language interpreter cannot be obtained",
- "Execution of child process impossible" };
+ "Execution of child process impossible",
+ "Invalid command line" };
if (cmdstat)
*cmdstat = value;
else if (value > EXEC_NOERROR)
- runtime_error ("Could not execute command line");
+ {
+#define MSGLEN 200
+ char msg[MSGLEN] = "EXECUTE_COMMAND_LINE: ";
+ strncat (msg, cmdmsg_values[value], MSGLEN - strlen(msg) - 1);
+ runtime_error ("%s", msg);
+ }
}
else if (!wait)
set_cmdstat (cmdstat, EXEC_SYNCHRONOUS);
#endif
+ else if (res == 127 || res == 126
+#if defined(WEXITSTATUS) && defined(WIFEXITED)
+ || (WIFEXITED(res) && WEXITSTATUS(res) == 127)
+ || (WIFEXITED(res) && WEXITSTATUS(res) == 126)
+#endif
+ )
+ /* Shell return codes 126 and 127 mean that the command line could
+ not be executed for various reasons. */
+ set_cmdstat (cmdstat, EXEC_INVALIDCOMMAND);
else
set_cmdstat (cmdstat, EXEC_NOERROR);
free (cmd);
/* Now copy back to the Fortran string if needed. */
- if (cmdstat && *cmdstat > EXEC_NOERROR)
- {
- if (cmdmsg)
- fstrcpy (cmdmsg, cmdmsg_len, cmdmsg_values[*cmdstat],
+ if (cmdstat && *cmdstat > EXEC_NOERROR && cmdmsg)
+ fstrcpy (cmdmsg, cmdmsg_len, cmdmsg_values[*cmdstat],
strlen (cmdmsg_values[*cmdstat]));
- else
- runtime_error ("Failure in EXECUTE_COMMAND_LINE: %s",
- cmdmsg_values[*cmdstat]);
- }
}