system(): on command == NULL, return nonzero if shell exists

This commit is contained in:
Florian Meißner
2023-05-29 20:54:34 +02:00
parent 63b7b76ab3
commit 14709b3d5c
3 changed files with 23 additions and 6 deletions
+11 -5
View File
@@ -1170,13 +1170,19 @@ pub unsafe extern "C" fn strtoll(
pub unsafe extern "C" fn system(command: *const c_char) -> c_int {
//TODO: share code with popen
// handle shell detection on command == NULL
if command.is_null() {
let status = system("exit 0\0".as_ptr() as *const c_char);
if status == 0 {
return 1;
} else {
return 0;
}
}
let child_pid = unistd::fork();
if child_pid == 0 {
let command_nonnull = if command.is_null() {
"exit 0\0".as_ptr()
} else {
command as *const u8
};
let command_nonnull = command as *const u8;
let shell = "/bin/sh\0".as_ptr();