4 ms·
Based on the generated code, you may need to broaden the definition of "binary" to include anything that is executable (shell script.)
by icedchai 6y ago
Based on the generated code, you may need to broaden the definition of "binary" to include anything that is executable (shell script.)
- chungy 6y agoIt's not really a shell script though, it just looks like one enough to the point that a bourne shell can modify it to be directly executable. I'd probably be most worried about the bourne shell part. It seems like it'll be easy for this to break on any "non-standard" shell that Linux might execute.
- icedchai 6y agoThis is true, but the shell is executing it "as if" it were a script, right? Until the binary part takes over...
- jart 6y agoThe behavior that Cosmopolitan needs is required by POSIX because UNIX Sixth Edition didn't have shebang lines. It's normally an implementation detail of execve() in C libraries and the behavior is implemented by nearly all shells too. So far the only issue has been that some shells, like zsh, have a binary safety check where it refuses to run scripts that have embedded NUL characters. I worked with the FreeBSD team to get POSIX revised to clarify the correct behavior w.r.t. these restrictions. FreeBSD's /bin/sh has already been patched and zsh is pending upstream. https://github.com/jart/zsh/commit/94a4bc14bb2e415ec3d10cf716512bd3e0d99f48 https://github.com/jart/zsh/commit/94a4bc14bb2e415ec3d10cf71...
- ashkankiani 6y agoI appreciate the thoroughness with which you are pursuing this. The amount of work you're doing outside of the technical aspect is definitely something I can admit that I would've never pursued. It's encouraging to see.
- fao_ 6y ago/bin/sh execution is supported at the kernel level iirc? Like, the minimum requirement for a linux distribution is /bin/sh, the rest of the system doesn't have to be there necessarily.
- deleted 6y ago[deleted]
- deleted 6y ago[deleted]
- 10000truths 6y agoNo, the Linux kernel only requires an init executable to run. It otherwise makes no assumptions about the programs available in userland. Pretty much any sane/usable Linux distribution will package a shell, though.
- saagarjha 6y agoThe behavior your are likely thinking of (execvp on a file without a shebang) is implemented in libc.
- fao_ 6y agoNo. As someone else mentioned, the kernel hardcodes /bin/sh as a last resort: https://github.com/torvalds/linux/blob/dcc0b49040c70ad827a7f3d58a21b01fdb14e749/init/main.c#L1476 https://github.com/torvalds/linux/blob/dcc0b49040c70ad827a7f...