diff --git a/selfdrive/common/util.h b/selfdrive/common/util.h index adfcb4b91c..b3dfae7e73 100644 --- a/selfdrive/common/util.h +++ b/selfdrive/common/util.h @@ -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 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 do_exit = false; }; diff --git a/selfdrive/loggerd/loggerd.cc b/selfdrive/loggerd/loggerd.cc index 200e34e06a..be6ed3faf0 100644 --- a/selfdrive/loggerd/loggerd.cc +++ b/selfdrive/loggerd/loggerd.cc @@ -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;