Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/exec: allow shell return code of 126

When the shell fails to invoke a script because its path name
is too long (ENAMETOOLONG), most shells return 127 to indicate
command not found. However, some systems report 126 (which POSIX
suggests should indicate a non-executable file) for this case,
so allow that too.

Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: David Drysdale <drysdale@google.com>
Tested-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>

authored by

David Drysdale and committed by
Shuah Khan
cd805f36 6898b627

+13 -6
+13 -6
tools/testing/selftests/exec/execveat.c
··· 62 62 } 63 63 64 64 static int check_execveat_invoked_rc(int fd, const char *path, int flags, 65 - int expected_rc) 65 + int expected_rc, int expected_rc2) 66 66 { 67 67 int status; 68 68 int rc; ··· 98 98 child, status); 99 99 return 1; 100 100 } 101 - if (WEXITSTATUS(status) != expected_rc) { 102 - printf("[FAIL] (child %d exited with %d not %d)\n", 103 - child, WEXITSTATUS(status), expected_rc); 101 + if ((WEXITSTATUS(status) != expected_rc) && 102 + (WEXITSTATUS(status) != expected_rc2)) { 103 + printf("[FAIL] (child %d exited with %d not %d nor %d)\n", 104 + child, WEXITSTATUS(status), expected_rc, expected_rc2); 104 105 return 1; 105 106 } 106 107 printf("[OK]\n"); ··· 110 109 111 110 static int check_execveat(int fd, const char *path, int flags) 112 111 { 113 - return check_execveat_invoked_rc(fd, path, flags, 99); 112 + return check_execveat_invoked_rc(fd, path, flags, 99, 99); 114 113 } 115 114 116 115 static char *concat(const char *left, const char *right) ··· 193 192 * Execute as a long pathname relative to ".". If this is a script, 194 193 * the interpreter will launch but fail to open the script because its 195 194 * name ("/dev/fd/5/xxx....") is bigger than PATH_MAX. 195 + * 196 + * The failure code is usually 127 (POSIX: "If a command is not found, 197 + * the exit status shall be 127."), but some systems give 126 (POSIX: 198 + * "If the command name is found, but it is not an executable utility, 199 + * the exit status shall be 126."), so allow either. 196 200 */ 197 201 if (is_script) 198 - fail += check_execveat_invoked_rc(dot_dfd, longpath, 0, 127); 202 + fail += check_execveat_invoked_rc(dot_dfd, longpath, 0, 203 + 127, 126); 199 204 else 200 205 fail += check_execveat(dot_dfd, longpath, 0); 201 206