re PR libfortran/62296 (EXECUTE_COMMAND_LINE not F2008 conforming)
authorFrançois-Xavier Coudert <fxcoudert@gcc.gnu.org>
Sun, 23 Aug 2015 21:24:49 +0000 (21:24 +0000)
committerFrançois-Xavier Coudert <fxcoudert@gcc.gnu.org>
Sun, 23 Aug 2015 21:24:49 +0000 (21:24 +0000)
PR libfortran/62296

* intrinsics/execute_command_line.c (EXEC_INVALIDCOMMAND): New
error code.
(cmdmsg_values): New error message.
(set_cmdstat): Rework runtime error.
(execute_command_line): Handle invalid command line error status.

* gfortran.dg/execute_command_line_2.f90: New test.

From-SVN: r227105

gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/execute_command_line_2.f90 [new file with mode: 0644]
libgfortran/ChangeLog
libgfortran/intrinsics/execute_command_line.c

index 0d06a933d88e2b003c97bd96c77d54e073192104..35b7da236d5621293042ff00f31eaeb4a32b193d 100644 (file)
@@ -1,3 +1,8 @@
+2015-08-23  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
+
+       PR libfortran/62296
+       * gfortran.dg/execute_command_line_2.f90: New test.
+
 2015-08-23  Tom de Vries  <tom@codesourcery.com>
 
        * gcc.dg/vect/trapv-vect-reduc-4.c: Use vect_no_int_min_max.
diff --git a/gcc/testsuite/gfortran.dg/execute_command_line_2.f90 b/gcc/testsuite/gfortran.dg/execute_command_line_2.f90
new file mode 100644 (file)
index 0000000..5a4e9cc
--- /dev/null
@@ -0,0 +1,14 @@
+! { dg-do run }
+!
+! Check that EXECUTE_COMMAND_LINE handles invalid command lines appropriately
+!
+  integer :: s = 0, c = 0
+  character(len=255) :: msg = ""
+
+  ! This should fail, set CMDSTAT to nonzero value, and an error message
+  ! in CMDMSG.
+  call execute_command_line ("/nosuchfile", exitstat=s, cmdstat=c, cmdmsg=msg)
+  if (c == 0) call abort
+  if (len_trim(msg) == 0) call abort
+
+end
index 2206c7fe35e2584eec1aea5f8c353921d2b5dd5e..9ffaa035b6064cd251ec43e94a17e5a8b019bf51 100644 (file)
@@ -1,7 +1,16 @@
+2015-08-23  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
+
+       PR libfortran/62296
+       * intrinsics/execute_command_line.c (EXEC_INVALIDCOMMAND): New
+       error code.
+       (cmdmsg_values): New error message.
+       (set_cmdstat): Rework runtime error.
+       (execute_command_line): Handle invalid command line error status.
+
 2015-08-10  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR libfortran/67140
-       * intrinsics/mvbits.c: Fix build for paltforms without c_int128_t.
+       * intrinsics/mvbits.c: Fix build for platforms without c_int128_t.
 
 2015-08-10  Steven G. Kargl  <kargl@gcc.gnu.org>
 
index 404314b09521d0c51f5e64ad91f0c10125071a95..5af9efd794687ecb637bc9308f3e4ae1ff62f55b 100644 (file)
@@ -36,11 +36,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 
 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" };
 
 
 
@@ -50,7 +51,12 @@ set_cmdstat (int *cmdstat, int value)
   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 (msg);
+    }
 }
 
 
@@ -95,6 +101,15 @@ execute_command_line (const char *command, bool wait, int *exitstat,
       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);