87c1f6
commit 42dda89dcb0407f6799dbfd0b9dab1529666ad51
87c1f6
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
87c1f6
Date:   Fri Dec 11 15:23:05 2020 -0300
87c1f6
87c1f6
    posix: Fix return value of system if shell can not be executed [BZ #27053]
87c1f6
    
87c1f6
    POSIX states that system returned code for failure to execute the shell
87c1f6
    shall be as if the shell had terminated using _exit(127).  This
87c1f6
    behaviour was removed with 5fb7fc96350575.
87c1f6
    
87c1f6
    Checked on x86_64-linux-gnu.
87c1f6
87c1f6
diff --git a/stdlib/tst-system.c b/stdlib/tst-system.c
87c1f6
index 194e09828dd5c206..8681584f15ef3b47 100644
87c1f6
--- a/stdlib/tst-system.c
87c1f6
+++ b/stdlib/tst-system.c
87c1f6
@@ -26,6 +26,7 @@
87c1f6
 #include <support/check.h>
87c1f6
 #include <support/temp_file.h>
87c1f6
 #include <support/support.h>
87c1f6
+#include <support/xunistd.h>
87c1f6
 
87c1f6
 static char *tmpdir;
87c1f6
 static long int namemax;
87c1f6
@@ -138,6 +139,22 @@ do_test (void)
87c1f6
     support_capture_subprocess_check (&result, "system", 0, sc_allow_none);
87c1f6
   }
87c1f6
 
87c1f6
+  {
87c1f6
+    struct stat64 st;
87c1f6
+    xstat (_PATH_BSHELL, &st);
87c1f6
+    mode_t mode = st.st_mode;
87c1f6
+    xchmod (_PATH_BSHELL, mode & ~(S_IXUSR | S_IXGRP | S_IXOTH));
87c1f6
+
87c1f6
+    struct support_capture_subprocess result;
87c1f6
+    result = support_capture_subprocess (call_system,
87c1f6
+					 &(struct args) {
87c1f6
+					   "exit 1", 127, 0
87c1f6
+					 });
87c1f6
+    support_capture_subprocess_check (&result, "system", 0, sc_allow_none);
87c1f6
+
87c1f6
+    xchmod (_PATH_BSHELL, st.st_mode);
87c1f6
+  }
87c1f6
+
87c1f6
   TEST_COMPARE (system (""), 0);
87c1f6
 
87c1f6
   return 0;
87c1f6
diff --git a/support/Makefile b/support/Makefile
87c1f6
index 4875f52495ef292d..09b41b0d57e9239a 100644
87c1f6
--- a/support/Makefile
87c1f6
+++ b/support/Makefile
87c1f6
@@ -86,6 +86,7 @@ libsupport-routines = \
87c1f6
   xchroot \
87c1f6
   xclone \
87c1f6
   xclose \
87c1f6
+  xchmod \
87c1f6
   xconnect \
87c1f6
   xcopy_file_range \
87c1f6
   xdlfcn \
87c1f6
diff --git a/sysdeps/posix/system.c b/sysdeps/posix/system.c
87c1f6
index 7db09a05c3fbca43..047ded4badfddcab 100644
87c1f6
--- a/sysdeps/posix/system.c
87c1f6
+++ b/sysdeps/posix/system.c
87c1f6
@@ -171,6 +171,10 @@ do_system (const char *line)
87c1f6
       __libc_cleanup_region_end (0);
87c1f6
 #endif
87c1f6
     }
87c1f6
+  else
87c1f6
+   /* POSIX states that failure to execute the shell should return
87c1f6
+      as if the shell had terminated using _exit(127).  */
87c1f6
+   status = W_EXITCODE (127, 0);
87c1f6
 
87c1f6
   DO_LOCK ();
87c1f6
   if (SUB_REF () == 0)