Merge branch 'functions/system/return_shell_exists' into 'master'
system(): on command == NULL, return nonzero if shell exists See merge request redox-os/relibc!403
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
shell found: 1
|
||||
test of system
|
||||
|
||||
+11
-1
@@ -3,6 +3,16 @@
|
||||
#include "test_helpers.h"
|
||||
|
||||
int main(void) {
|
||||
int status = system("echo test of system");
|
||||
// testing shell detection
|
||||
// this means, because we don't detect if a shell actually exists but just assume it does, this test case breaks in
|
||||
// environments without `sh`. I think that is a reasonable tradeoff.
|
||||
// (And if there isn't a shell, system() won't work anyways)
|
||||
int status = system(NULL);
|
||||
printf("shell found: %i\n", status);
|
||||
fflush(stdout);
|
||||
ERROR_IF(system, status, == 0);
|
||||
|
||||
// base case
|
||||
status = system("echo test of system");
|
||||
ERROR_IF(system, status, == -1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user