3 ms·
This is hilarious, though interestingly if you try to see what's going on with gdb or strace it actually errors out properly. $ strace ./empty execve("
by 4oo4 5y ago
This is hilarious, though interestingly if you try to see what's going on with gdb or strace it actually errors out properly.
$ strace ./empty
execve("./empty", ["./empty"], 0x7ffe0156c9d0 /* 61 vars */) = -1 ENOEXEC (Exec format error)
strace: exec: Exec format error
+++ exited with 1 +++
(I'm not very good with gdb so maybe this is wrong)
gdb empty
"0x7ffd34c7dc30s": not in executable format: file format not recognized
(gdb) exec-file
No executable file now
I think what's actually happening is that bash is `source`-ing the file, so that's what causes the exit code to be zero.
- infotogivenm 5y agoIt is indeed a shell behavior, specified in POSIX sh. > If the execve() function fails due to an error equivalent to the [ENOEXEC] error defined in the System Interfaces volume of IEEE Std 1003.1-2001, the shell shall execute a command equivalent to having a shell invoked with the pathname resulting from the search as its first operand, with any remaining arguments passed to the new shell, except that the value of "$0" in the new shell may be set to the command name. If the executable file is not a text file, the shell may bypass this command execution. In this case, it shall write an error message, and shall return an exit status of 126. https://pubs.opengroup.org/onlinepubs/009604499/utilities/xcu_chap02.html#tag_02_09_01_01 https://pubs.opengroup.org/onlinepubs/009604499/utilities/xc...
- garaetjjte 5y agoDoes file that don't contain any LF is valid "text file", though?
- bombcar 5y agoWhich likely means the zero byte /bin/true is SLOWER than a compiled correct one because it has to first ENOEXEC and then reexecute via the shell.