From ca544ed6fcbd115a3c6308dbdb9eb9535d1ddcde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=98=8E?= <7737673+caobug@users.noreply.github.com> Date: Fri, 23 Jun 2023 17:09:53 +0800 Subject: [PATCH] unix: skip prohibited syscalls on tvOS and watchOS (#4043) --- src/unix/process.c | 12 ++++---- test/runner-unix.c | 10 +++++++ test/test-fork.c | 36 ++++++++++++++++++++++++ test/test-pipe-close-stdout-read-stdin.c | 12 +++++++- 4 files changed, 63 insertions(+), 7 deletions(-) diff --git a/src/unix/process.c b/src/unix/process.c index dbb4a1dc..dd58c18d 100644 --- a/src/unix/process.c +++ b/src/unix/process.c @@ -183,6 +183,11 @@ void uv__wait_children(uv_loop_t* loop) { * Used for initializing stdio streams like options.stdin_stream. Returns * zero on success. See also the cleanup section in uv_spawn(). */ +#if !(defined(__APPLE__) && (TARGET_OS_TV || TARGET_OS_WATCH)) +/* execvp is marked __WATCHOS_PROHIBITED __TVOS_PROHIBITED, so must be + * avoided. Since this isn't called on those targets, the function + * doesn't even need to be defined for them. + */ static int uv__process_init_stdio(uv_stdio_container_t* container, int fds[2]) { int mask; int fd; @@ -269,11 +274,6 @@ static void uv__write_errno(int error_fd) { } -#if !(defined(__APPLE__) && (TARGET_OS_TV || TARGET_OS_WATCH)) -/* execvp is marked __WATCHOS_PROHIBITED __TVOS_PROHIBITED, so must be - * avoided. Since this isn't called on those targets, the function - * doesn't even need to be defined for them. - */ static void uv__process_child_init(const uv_process_options_t* options, int stdio_count, int (*pipes)[2], @@ -405,7 +405,6 @@ static void uv__process_child_init(const uv_process_options_t* options, uv__write_errno(error_fd); } -#endif #if defined(__APPLE__) @@ -952,6 +951,7 @@ static int uv__spawn_and_init_child( return err; } +#endif /* ISN'T TARGET_OS_TV || TARGET_OS_WATCH */ int uv_spawn(uv_loop_t* loop, uv_process_t* process, diff --git a/test/runner-unix.c b/test/runner-unix.c index 09191dbd..81560add 100644 --- a/test/runner-unix.c +++ b/test/runner-unix.c @@ -40,6 +40,10 @@ #include #include +#ifdef __APPLE__ +#include +#endif + extern char** environ; static void closefd(int fd) { @@ -131,7 +135,11 @@ int process_start(char* name, char* part, process_info_t* p, int is_helper) { p->terminated = 0; p->status = 0; +#if defined(__APPLE__) && (TARGET_OS_TV || TARGET_OS_WATCH) + pid = -1; +#else pid = fork(); +#endif if (pid < 0) { perror("fork"); @@ -144,7 +152,9 @@ int process_start(char* name, char* part, process_info_t* p, int is_helper) { closefd(pipefd[0]); dup2(stdout_fd, STDOUT_FILENO); dup2(stdout_fd, STDERR_FILENO); +#if !(defined(__APPLE__) && (TARGET_OS_TV || TARGET_OS_WATCH)) execve(args[0], args, environ); +#endif perror("execve()"); _exit(127); } diff --git a/test/test-fork.c b/test/test-fork.c index 7a6eb9c4..29ed132a 100644 --- a/test/test-fork.c +++ b/test/test-fork.c @@ -27,6 +27,10 @@ #include #include +#ifdef __APPLE__ +#include +#endif + #include "uv.h" #include "task.h" @@ -100,7 +104,11 @@ TEST_IMPL(fork_timer) { pid_t child_pid; run_timer_loop_once(); +#if defined(__APPLE__) && (TARGET_OS_TV || TARGET_OS_WATCH) + child_pid = -1; +#else child_pid = fork(); +#endif ASSERT(child_pid != -1); if (child_pid != 0) { @@ -132,7 +140,11 @@ TEST_IMPL(fork_socketpair) { /* Create the server watcher in the parent, use it in the child. */ ASSERT(0 == uv_poll_init(uv_default_loop(), &poll_handle, socket_fds[0])); +#if defined(__APPLE__) && (TARGET_OS_TV || TARGET_OS_WATCH) + child_pid = -1; +#else child_pid = fork(); +#endif ASSERT(child_pid != -1); if (child_pid != 0) { @@ -181,7 +193,11 @@ TEST_IMPL(fork_socketpair_started) { */ ASSERT(1 == uv_run(uv_default_loop(), UV_RUN_NOWAIT)); +#if defined(__APPLE__) && (TARGET_OS_TV || TARGET_OS_WATCH) + child_pid = -1; +#else child_pid = fork(); +#endif ASSERT(child_pid != -1); if (child_pid != 0) { @@ -245,7 +261,11 @@ TEST_IMPL(fork_signal_to_child) { ASSERT(0 == uv_signal_init(uv_default_loop(), &signal_handle)); ASSERT(0 == uv_signal_start(&signal_handle, fork_signal_to_child_cb, SIGUSR1)); +#if defined(__APPLE__) && (TARGET_OS_TV || TARGET_OS_WATCH) + child_pid = -1; +#else child_pid = fork(); +#endif ASSERT(child_pid != -1); if (child_pid != 0) { @@ -297,7 +317,11 @@ TEST_IMPL(fork_signal_to_child_closed) { ASSERT(0 == uv_signal_init(uv_default_loop(), &signal_handle)); ASSERT(0 == uv_signal_start(&signal_handle, fork_signal_to_child_cb, SIGUSR1)); +#if defined(__APPLE__) && (TARGET_OS_TV || TARGET_OS_WATCH) + child_pid = -1; +#else child_pid = fork(); +#endif ASSERT(child_pid != -1); if (child_pid != 0) { @@ -463,7 +487,11 @@ static int _do_fork_fs_events_child(int file_or_dir) { /* Watch in the parent, prime the loop and/or threads. */ assert_watch_file_current_dir(uv_default_loop(), file_or_dir); +#if defined(__APPLE__) && (TARGET_OS_TV || TARGET_OS_WATCH) + child_pid = -1; +#else child_pid = fork(); +#endif ASSERT(child_pid != -1); if (child_pid != 0) { @@ -569,7 +597,11 @@ TEST_IMPL(fork_fs_events_file_parent_child) { r = uv_timer_init(loop, &timer); ASSERT(r == 0); +#if defined(__APPLE__) && (TARGET_OS_TV || TARGET_OS_WATCH) + child_pid = -1; +#else child_pid = fork(); +#endif ASSERT(child_pid != -1); if (child_pid != 0) { /* parent */ @@ -654,7 +686,11 @@ TEST_IMPL(fork_threadpool_queue_work_simple) { /* Prime the pool and default loop. */ assert_run_work(uv_default_loop()); +#if defined(__APPLE__) && (TARGET_OS_TV || TARGET_OS_WATCH) + child_pid = -1; +#else child_pid = fork(); +#endif ASSERT(child_pid != -1); if (child_pid != 0) { diff --git a/test/test-pipe-close-stdout-read-stdin.c b/test/test-pipe-close-stdout-read-stdin.c index e0f864e9..a9295f0a 100644 --- a/test/test-pipe-close-stdout-read-stdin.c +++ b/test/test-pipe-close-stdout-read-stdin.c @@ -26,6 +26,10 @@ #include #include +#ifdef __APPLE__ +#include +#endif + #include "uv.h" #include "task.h" @@ -58,8 +62,14 @@ TEST_IMPL(pipe_close_stdout_read_stdin) { r = pipe(fd); ASSERT(r == 0); + +#if defined(__APPLE__) && (TARGET_OS_TV || TARGET_OS_WATCH) + pid = -1; +#else + pid = fork(); +#endif - if ((pid = fork()) == 0) { + if (pid == 0) { /* * Make the read side of the pipe our stdin. * The write side will be closed by the parent process.