diff options
author | Arne Juul <arnej@verizonmedia.com> | 2020-07-02 11:52:21 +0000 |
---|---|---|
committer | Arne Juul <arnej@verizonmedia.com> | 2020-07-03 08:02:39 +0000 |
commit | 6cd62c06b215ebd785fded2c5afb42a0df8be104 (patch) | |
tree | e24e6a3a165757cc3627fb368018e07e280b5fd4 /vespalog/src/logger | |
parent | 2a57218cd2f3020aed5aa4cea739c85cab594b0a (diff) |
avoid naked exit
Diffstat (limited to 'vespalog/src/logger')
-rw-r--r-- | vespalog/src/logger/logreplay.c | 4 | ||||
-rw-r--r-- | vespalog/src/logger/runserver.cpp | 29 |
2 files changed, 16 insertions, 17 deletions
diff --git a/vespalog/src/logger/logreplay.c b/vespalog/src/logger/logreplay.c index 70a1b9a08a9..7a920a916a4 100644 --- a/vespalog/src/logger/logreplay.c +++ b/vespalog/src/logger/logreplay.c @@ -19,7 +19,7 @@ main(int argc, char **argv) "Replays a vespa log file with the same timing delta between each log message.\n" "Reprints the log messages without timestamps.\n\n", argv[0]); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } while (fgets(line, sizeof line, stdin)) { @@ -54,5 +54,5 @@ main(int argc, char **argv) fwrite(s, strlen(s), 1, stdout); fflush(stdout); } - exit(EXIT_SUCCESS); + return EXIT_SUCCESS; } diff --git a/vespalog/src/logger/runserver.cpp b/vespalog/src/logger/runserver.cpp index e58565f78b9..f8d16dad29e 100644 --- a/vespalog/src/logger/runserver.cpp +++ b/vespalog/src/logger/runserver.cpp @@ -102,7 +102,7 @@ PidFile::writePid() if (didtruncate != 0) { fprintf(stderr, "could not truncate pid file %s: %s\n", _pidfile, strerror(errno)); - exit(1); + std::_Exit(1); } char buf[100]; sprintf(buf, "%d\n", getpid()); @@ -111,7 +111,7 @@ PidFile::writePid() if (didw != l) { fprintf(stderr, "could not write pid to %s: %s\n", _pidfile, strerror(errno)); - exit(1); + std::_Exit(1); } LOG(debug, "wrote '%s' to %s (fd %d)", buf, _pidfile, _fd); } @@ -168,7 +168,7 @@ int loop(const char *svc, char * const * run) if (pipe(pstdout) < 0 || pipe(pstderr) < 0) { LOG(error, "pipe: %s", strerror(errno)); - exit(1); + std::_Exit(1); } LOG(debug, "stdout pipe %d <- %d; stderr pipe %d <- %d", pstdout[0], pstdout[1], @@ -188,11 +188,11 @@ int loop(const char *svc, char * const * run) close(pstderr[1]); execvp(run[0], run); LOG(error, "exec %s: %s", run[0], strerror(errno)); - exit(1); + std::_Exit(1); } if (child < 0) { LOG(error, "fork(): %s", strerror(errno)); - exit(1); + std::_Exit(1); } // I am the parent process @@ -374,7 +374,7 @@ int main(int argc, char *argv[]) } if (chdir(envROOT) != 0) { fprintf(stderr, "Cannot chdir to %s: %s\n", envROOT, strerror(errno)); - exit(1); + return 1; } PidFile mypf(pidfile); @@ -393,7 +393,7 @@ int main(int argc, char *argv[]) if (killpg(pid, SIGTERM) != 0) { fprintf(stderr, "could not signal %d: %s\n", pid, strerror(errno)); - exit(1); + return 1; } } fprintf(stdout, "Waiting for exit (up to 60 seconds)\n"); @@ -421,7 +421,7 @@ int main(int argc, char *argv[]) service, pidfile); } mypf.cleanUp(); - exit(0); + return 0; } if (optind >= argc || killcmd != NULL) { usage(argv[0], 1); @@ -430,7 +430,7 @@ int main(int argc, char *argv[]) if (mypf.anotherRunning()) { fprintf(stderr, "runserver already running with pid %d\n", mypf.readPid()); - exit(0); + return 0; } if (!mypf.writeOpen()) { @@ -443,17 +443,17 @@ int main(int argc, char *argv[]) close(0); if (open("/dev/null", O_RDONLY) != 0) { perror("open /dev/null for reading failed"); - exit(1); + std::_Exit(1); } close(1); if (open("/dev/null", O_WRONLY) != 1) { perror("open /dev/null for writing failed"); - exit(1); + std::_Exit(1); } dup2(1, 2); if (setsid() < 0) { perror("setsid"); - exit(1); + std::_Exit(1); } struct sigaction act; struct sigaction oact; @@ -482,15 +482,14 @@ int main(int argc, char *argv[]) } while (!gotstopsig && restart > 0); } catch (MsgException& ex) { LOG(error, "exception: '%s'", ex.what()); - exit(1); + return 1; } if (restart > 0) { LOG(debug, "final exit status: %d", stat); } mypf.cleanUp(); - exit(stat); + return stat; } - if (rsp < 0) { perror("fork"); return 1; |