From c29c510e30da1f55528d8d040adee9a48f8605cf Mon Sep 17 00:00:00 2001 From: Wiktor Garbacz Date: Wed, 22 Sep 2021 07:16:12 -0700 Subject: [PATCH] Log when global forkserver is started and its exit status PiperOrigin-RevId: 398232735 Change-Id: Ia0628cf2dee51a94938dae82bcb392384feeb74c --- sandboxed_api/sandbox2/global_forkclient.cc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/sandboxed_api/sandbox2/global_forkclient.cc b/sandboxed_api/sandbox2/global_forkclient.cc index 3f5e653..0312d47 100644 --- a/sandboxed_api/sandbox2/global_forkclient.cc +++ b/sandboxed_api/sandbox2/global_forkclient.cc @@ -119,6 +119,8 @@ GlobalForkserverStartModeSet GetForkserverStartMode() { } absl::StatusOr> StartGlobalForkServer() { + SAPI_RAW_LOG(INFO, "Starting global forkserver"); + // The fd is owned by EmbedFile int exec_fd = sapi::EmbedFile::instance()->GetFdForFileToc( forkserver_bin_embed_create()); @@ -168,10 +170,23 @@ absl::StatusOr> StartGlobalForkServer() { } void WaitForForkserver(pid_t pid) { - pid_t wpid = TEMP_FAILURE_RETRY(waitpid(pid, nullptr, 0)); + int status; + pid_t wpid = TEMP_FAILURE_RETRY(waitpid(pid, &status, 0)); if (wpid != pid) { SAPI_RAW_PLOG(ERROR, "Waiting for %d failed", pid); } + if (WIFEXITED(status)) { + int exit_code = WEXITSTATUS(status); + if (exit_code == 0) { + SAPI_RAW_LOG(INFO, "forkserver (pid=%d) terminated normally", pid); + } else { + SAPI_RAW_LOG(WARNING, "forkserver (pid=%d) terminated with exit code %d", + pid, exit_code); + } + } else if (WIFSIGNALED(status)) { + SAPI_RAW_LOG(WARNING, "forkserver (pid=%d) terminated by signal %d", pid, + WTERMSIG(status)); + } } } // namespace