From bff9f5c0f51338a2d2fc11cab4355b65bf051307 Mon Sep 17 00:00:00 2001 From: Arne Juul Date: Thu, 16 Mar 2023 13:17:31 +0000 Subject: handle "Interrupted system call" and silence stdout from vespa-logctl --- configd/src/apps/sentinel/logctl.cpp | 41 ++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 14 deletions(-) (limited to 'configd') diff --git a/configd/src/apps/sentinel/logctl.cpp b/configd/src/apps/sentinel/logctl.cpp index 057178cec2e..59c02b57344 100644 --- a/configd/src/apps/sentinel/logctl.cpp +++ b/configd/src/apps/sentinel/logctl.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -18,28 +19,40 @@ void justRunLogctl(const char *cspec, const char *lspec) pid_t pid = fork(); if (pid == 0) { LOG(debug, "running '%s' '%s' '%s'", progName, cspec, lspec); + int devnull = open("/dev/null", O_WRONLY); + if (devnull > 1) { + dup2(devnull, 1); + close(devnull); + } int rv = execlp(progName, progName, "-c", cspec, lspec, nullptr); if (rv != 0) { LOG(warning, "execlp of '%s' failed: %s", progName, strerror(errno)); } } else if (pid > 0) { - int wstatus = 0; - pid_t got = waitpid(pid, &wstatus, 0); - if (got == pid) { - if (WIFEXITED(wstatus)) { - int exitCode = WEXITSTATUS(wstatus); - if (exitCode != 0) { - LOG(warning, "running '%s' failed (exit code %d)", progName, exitCode); + bool again; + do { + again = false; + int wstatus = 0; + pid_t got = waitpid(pid, &wstatus, 0); + if (got == pid) { + again = false; + if (WIFEXITED(wstatus)) { + int exitCode = WEXITSTATUS(wstatus); + if (exitCode != 0) { + LOG(warning, "running '%s' failed (exit code %d)", progName, exitCode); + } + } else if (WIFSIGNALED(wstatus)) { + int termSig = WTERMSIG(wstatus); + LOG(warning, "running '%s' failed (got signal %d)", progName, termSig); + } else { + LOG(warning, "'%s' failure (wait status was %d)", progName, wstatus); } - } else if (WIFSIGNALED(wstatus)) { - int termSig = WTERMSIG(wstatus); - LOG(warning, "running '%s' failed (got signal %d)", progName, termSig); + } else if (errno == EINTR) { + again = true; } else { - LOG(warning, "'%s' failure (wait status was %d)", progName, wstatus); + LOG(error, "waitpid() failed: %s", strerror(errno)); } - } else { - LOG(error, "waitpid() failed: %s", strerror(errno)); - } + } while (again); } else { LOG(error, "fork() failed: %s", strerror(errno)); } -- cgit v1.2.3