From d0496719080ccf9ee00fccf6cb0765e31765529f Mon Sep 17 00:00:00 2001 From: Chih-Hsuan Yen Date: Sun, 5 Dec 2021 12:58:02 +0800 Subject: [PATCH] Fix adb server hang Since commit 04267085441d6fcd05eff7df0118708f7622e237, the server is run in a dedicated thread. For SDL, many signals, including SIGINT and SIGTERM, are masked for new threads. As a result, if the adb server is not already running, adb commands invoked by scrcpy will start an adb server that ignores those signals and cannot be terminated at system shutdown. Fixes #2873 PR #2870 Signed-off-by: Romain Vimont --- app/src/sys/unix/process.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/sys/unix/process.c b/app/src/sys/unix/process.c index 54a1bb80..cb82f3a9 100644 --- a/app/src/sys/unix/process.c +++ b/app/src/sys/unix/process.c @@ -119,6 +119,13 @@ sc_process_execute_p(const char *const argv[], sc_pid *pid, unsigned flags, close(internal[0]); enum sc_process_result err; + + // Somehow SDL masks many signals - undo them for other processes + // https://github.com/libsdl-org/SDL/blob/release-2.0.18/src/thread/pthread/SDL_systhread.c#L167 + sigset_t mask; + sigemptyset(&mask); + sigprocmask(SIG_SETMASK, &mask, NULL); + if (fcntl(internal[1], F_SETFD, FD_CLOEXEC) == 0) { execvp(argv[0], (char *const *) argv); perror("exec");