diff --git a/apps/init.c b/apps/init.c index 4192bc06..e549951a 100644 --- a/apps/init.c +++ b/apps/init.c @@ -38,5 +38,5 @@ int main() fprintf(stderr, "init is running as PID %d\n", getpid()); char* argv[] = { "/bin/hello", "--help", NULL }; - syscall(SYS_exec, "/bin/hello", argv); + execv("/bin/hello", argv); } diff --git a/libc/include/unistd.h b/libc/include/unistd.h index 1782a796..a12172d9 100644 --- a/libc/include/unistd.h +++ b/libc/include/unistd.h @@ -23,7 +23,9 @@ extern "C" /* Return the current process' process ID. */ pid_t getpid(void); - int execv(const char*, char* const*); + /* Replace the current process with another one. On success, does not return. */ + int execv(const char* path, char* const* argv); + int execve(const char*, char* const*, char* const*); int execvp(const char*, char* const*); diff --git a/libc/src/unistd.cpp b/libc/src/unistd.cpp index 8b989ce7..2281f72c 100644 --- a/libc/src/unistd.cpp +++ b/libc/src/unistd.cpp @@ -13,6 +13,12 @@ extern "C" return (pid_t)syscall(SYS_getpid); } + int execv(const char* path, char* const* argv) + { + long rc = syscall(SYS_exec, path, argv); + __errno_return(rc, int); + } + long syscall(long num, ...) { va_list ap;