From c5cbf4aeb6a0993f2f739363d173308389e32a4a Mon Sep 17 00:00:00 2001 From: Kory Draughn Date: Thu, 24 Oct 2024 09:17:17 -0400 Subject: [PATCH] squash. Added words about the use of _exit() after a failed call to fork(). --- server/main_server/src/main.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server/main_server/src/main.cpp b/server/main_server/src/main.cpp index 77b7727812..44402757ac 100644 --- a/server/main_server/src/main.cpp +++ b/server/main_server/src/main.cpp @@ -867,6 +867,13 @@ Mandatory arguments to long options are mandatory for short options too. if (0 == g_pid_ds) { execv(args[0], args.data()); + + // If execv() fails, the POSIX standard recommends using _exit() instead of exit() to avoid + // flushing stdio buffers and handlers registered by the parent. + // + // In the case of C++, this is necessary to avoid triggering destructors. Triggering a destructor + // could result in assertions made by the struct/class being violatied. For some data types, + // violating an assertion results in program termination (i.e. SIGABRT). _exit(1); } else if (g_pid_ds > 0) {