diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2019-08-26 12:19:58 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2019-08-26 12:19:58 +0000 |
commit | 58cfb5e88daf7bed3f5b235325eeae5f81983a21 (patch) | |
tree | c5983a05e628d0121078bd76006c651e3c901585 /vespalog | |
parent | df25abf6f2498d90498ae2f84643aa1dd61fae9b (diff) |
Avoid the last usages of time(0/NULL/nullptr) in the codebase.
Diffstat (limited to 'vespalog')
-rw-r--r-- | vespalog/src/logger/runserver.cpp | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/vespalog/src/logger/runserver.cpp b/vespalog/src/logger/runserver.cpp index be61ee2551d..8ea669697ee 100644 --- a/vespalog/src/logger/runserver.cpp +++ b/vespalog/src/logger/runserver.cpp @@ -1,25 +1,22 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <stdlib.h> -#include <string.h> -#include <stdio.h> +#include <cstdlib> +#include <cstring> +#include <cstdio> #include <fcntl.h> -#include <errno.h> +#include <cerrno> #include <unistd.h> -#include <time.h> -#include <csignal> #include <sys/select.h> #include <sys/types.h> #include <sys/wait.h> -#include <sys/time.h> #include <sys/resource.h> #include <sys/file.h> -#include <fcntl.h> #include <vespa/defaults.h> #include <vespa/log/llparser.h> #include "llreader.h" #include <vespa/log/log.h> +#include <chrono> LOG_SETUP("runserver"); @@ -38,6 +35,16 @@ void termsig(int sig) { } } +namespace { + +using namespace std::chrono; + +time_t steady_time() { + return duration_cast<seconds>(steady_clock::now().time_since_epoch()).count(); +} + +} + class PidFile { private: @@ -461,14 +468,14 @@ int main(int argc, char *argv[]) try { mypf.writePid(); do { - time_t laststart = time(NULL); + time_t laststart = steady_time(); stat = loop(service, argv+optind); if (restart > 0 && !gotstopsig) { - int wt = restart + laststart - time(NULL); + int wt = restart + laststart - steady_time(); if (wt < 0) wt = 0; LOG(info, "will restart in %d seconds", wt); } - while (!gotstopsig && time(NULL) - laststart < restart) { + while (!gotstopsig && steady_time() - laststart < restart) { sleep(1); } } while (!gotstopsig && restart > 0); |