From 526ca6878629865a1f535552abbfcd17d7e04326 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Thu, 2 Jul 2020 13:49:04 -0400 Subject: [PATCH] SystemMonitor: Correctly check error of posix_spawn() posix_spawn() has a bit of a whacky API in that it doens't return 0 on success and -1 on failure while writing the error code to errno -- it instead returns 0 on success and the error code on error. So assign the return value to errno so that perror() does the right thing. --- Applications/SystemMonitor/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Applications/SystemMonitor/main.cpp b/Applications/SystemMonitor/main.cpp index 79f6c2bc19..ae585e4bc9 100644 --- a/Applications/SystemMonitor/main.cpp +++ b/Applications/SystemMonitor/main.cpp @@ -214,7 +214,7 @@ int main(int argc, char** argv) auto pid_string = String::format("%d", pid); pid_t child; const char* argv[] = { "/bin/Profiler", "--pid", pid_string.characters(), nullptr }; - if (posix_spawn(&child, "/bin/Profiler", nullptr, nullptr, const_cast(argv), environ) < 0) { + if ((errno = posix_spawn(&child, "/bin/Profiler", nullptr, nullptr, const_cast(argv), environ))) { perror("posix_spawn"); } }