From d98471ded0ac3a5c4903d218ccc8a54d66181442 Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Wed, 30 Dec 2015 22:18:14 +0000 Subject: [PATCH] Record shutdown type (halt, poweroff, reboot) in the service set. --- service-constants.h | 7 +++++++ service.h | 10 +++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/service-constants.h b/service-constants.h index 0836106..f54720b 100644 --- a/service-constants.h +++ b/service-constants.h @@ -28,5 +28,12 @@ enum class ServiceEvent { STOPCANCELLED // Service was set to be stopped but a start was requested }; +/* Shutdown types */ +enum class ShutdownType { + CONTINUE, // Continue normal boot sequence (used after single-user shell) + HALT, // Halt system without powering down + POWEROFF, // Power off system + REBOOT // Reboot system +}; #endif diff --git a/service.h b/service.h index 5f533f5..e9809fc 100644 --- a/service.h +++ b/service.h @@ -364,6 +364,8 @@ class ServiceSet bool restart_enabled; // whether automatic restart is enabled (allowed) ControlConn *rollback_handler; // recieves notification when all services stopped + ShutdownType shutdown_type = ShutdownType::CONTINUE; // Shutdown type, if stopping + // Private methods // Load a service description, and dependencies, if there is no existing @@ -426,9 +428,10 @@ class ServiceSet return active_services; } - void stop_all_services() noexcept + void stop_all_services(ShutdownType type = ShutdownType::HALT) noexcept { restart_enabled = false; + shutdown_type = type; for (std::list::iterator i = records.begin(); i != records.end(); ++i) { (*i)->stop(); } @@ -444,6 +447,11 @@ class ServiceSet return restart_enabled; } + ShutdownType getShutdownType() noexcept + { + return shutdown_type; + } + // Set the rollback handler, which will be notified when all services have stopped. // There can be only one rollback handler; attempts to set it when already set will // fail. Returns true if successful. -- 2.25.1