From bd5969fc876a10b18613302db7087ef3c40f18e1 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Thu, 7 Mar 2024 17:28:00 -0500 Subject: lib: Add mlibc Signed-off-by: Ian Moffett --- lib/mlibc/tests/posix/posix_spawn.c | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 lib/mlibc/tests/posix/posix_spawn.c (limited to 'lib/mlibc/tests/posix/posix_spawn.c') diff --git a/lib/mlibc/tests/posix/posix_spawn.c b/lib/mlibc/tests/posix/posix_spawn.c new file mode 100644 index 0000000..cc5ccff --- /dev/null +++ b/lib/mlibc/tests/posix/posix_spawn.c @@ -0,0 +1,38 @@ +#include +#include +#include +#include + +#include +#include +#include + +extern char **environ; + +void run_cmd(char *cmd) +{ + pid_t pid; + char *argv[] = {"sh", "-c", cmd, NULL}; + int status; + printf("Run command: %s\n", cmd); + status = posix_spawn(&pid, "/bin/sh", NULL, NULL, argv, environ); + if(status == 0) { + printf("Child pid: %i\n", pid); + if(waitpid(pid, &status, 0) != -1) { + printf("Child exited with status %i\n", status); + printf("Child exit status: %i\n", WEXITSTATUS(status)); + assert(WEXITSTATUS(status) == 0); + } else { + perror("waitpid"); + assert(0 == 1); + } + } else { + printf("posix_spawn: %s\n", strerror(status)); + assert(0 == 1); + } +} + +int main() { + run_cmd(":"); + return 0; +} -- cgit v1.2.3