loggerd: clean exit on SIGPWR (#20100)

* loggerd: clean exit on SIGPRW

* no SIGPWR on macos
old-commit-hash: d3dfb47d0e
This commit is contained in:
Willem Melching
2021-02-18 17:46:46 +01:00
committed by GitHub
parent 5df5262f3b
commit a98a06c1f8
2 changed files with 16 additions and 1 deletions

View File

@@ -109,14 +109,24 @@ public:
ExitHandler() {
std::signal(SIGINT, (sighandler_t)set_do_exit);
std::signal(SIGTERM, (sighandler_t)set_do_exit);
#ifndef __APPLE__
std::signal(SIGPWR, (sighandler_t)set_do_exit);
#endif
};
inline static std::atomic<bool> power_failure = false;
inline operator bool() { return do_exit; }
inline ExitHandler& operator=(bool v) {
do_exit = v;
return *this;
}
private:
static void set_do_exit(int sig) { do_exit = true; }
static void set_do_exit(int sig) {
#ifndef __APPLE__
power_failure = (sig == SIGPWR);
#endif
do_exit = true;
}
inline static std::atomic<bool> do_exit = false;
};

View File

@@ -493,6 +493,11 @@ int main(int argc, char** argv) {
LOGW("closing logger");
logger_close(&s.logger);
if (do_exit.power_failure){
LOGE("power failure");
sync();
}
// messaging cleanup
for (auto sock : socks) delete sock;
delete poller;