chiark / gitweb /
Prep v239: Fix main() to call manager_new() again.
[elogind.git] / src / login / elogind.c
index 2fae0f193a9ae239502d0840108cdf7ef67832b4..9fe52a94c1e9005aee93c96f4f979cf10625fe92 100644 (file)
@@ -97,7 +97,7 @@ static int elogind_daemonize(void) {
         pid_t SID;
         int r;
 
-#ifdef ENABLE_DEBUG_ELOGIND
+#if ENABLE_DEBUG_ELOGIND
         log_notice("Double forking elogind");
         log_notice("Parent PID     : %5d", getpid_cached());
         log_notice("Parent SID     : %5d", getsid(getpid_cached()));
@@ -115,7 +115,7 @@ static int elogind_daemonize(void) {
         if (r)
                 return child;
 
-#ifdef ENABLE_DEBUG_ELOGIND
+#if ENABLE_DEBUG_ELOGIND
         log_notice("Child PID      : %5d", getpid_cached());
         log_notice("Child SID      : %5d", getsid(getpid_cached()));
 #endif // ENABLE_DEBUG_ELOGIND
@@ -124,7 +124,7 @@ static int elogind_daemonize(void) {
         if ((pid_t)-1 == SID)
                 return log_error_errno(errno, "Failed to create new SID: %m");
 
-#ifdef ENABLE_DEBUG_ELOGIND
+#if ENABLE_DEBUG_ELOGIND
         log_notice("Child new SID  : %5d", getsid(getpid_cached()));
 #endif // ENABLE_DEBUG_ELOGIND
 
@@ -142,7 +142,7 @@ static int elogind_daemonize(void) {
 
         umask(0022);
 
-#ifdef ENABLE_DEBUG_ELOGIND
+#if ENABLE_DEBUG_ELOGIND
         log_notice("Grand child PID: %5d", getpid_cached());
         log_notice("Grand child SID: %5d", getsid(getpid_cached()));
 #endif // ENABLE_DEBUG_ELOGIND
@@ -319,7 +319,7 @@ int elogind_startup(int argc, char *argv[]) {
 
         /* Note: At this point, the logging is not initialized, so we can not
                  use log_debug_elogind(). */
-#ifdef ENABLE_DEBUG_ELOGIND
+#if ENABLE_DEBUG_ELOGIND
         log_notice("elogind startup: Daemonize: %s, Show Help: %s, Wrong arg: %s",
                 daemonize ? "True" : "False",
                 show_help ? "True" : "False",
@@ -379,12 +379,13 @@ int elogind_manager_new(Manager* m) {
         m->test_run_flags   = 0;
 
         /* Init sleep modes and states */
-        m->suspend_mode       = NULL;
-        m->suspend_state      = NULL;
-        m->hibernate_mode     = NULL;
-        m->hibernate_state    = NULL;
-        m->hybrid_sleep_mode  = NULL;
-        m->hybrid_sleep_state = NULL;
+        m->suspend_mode        = NULL;
+        m->suspend_state       = NULL;
+        m->hibernate_mode      = NULL;
+        m->hibernate_state     = NULL;
+        m->hybrid_sleep_mode   = NULL;
+        m->hybrid_sleep_state  = NULL;
+        m->hibernate_delay_sec = 0;
 
         /* If elogind should be its own controller, mount its cgroup */
         if (streq(SYSTEMD_CGROUP_CONTROLLER, "_elogind")) {
@@ -404,7 +405,7 @@ int elogind_manager_new(Manager* m) {
 /// Add-On for manager_reset_config()
 void elogind_manager_reset_config(Manager* m) {
 
-#ifdef ENABLE_DEBUG_ELOGIND
+#if ENABLE_DEBUG_ELOGIND
         int dbg_cnt;
 #endif // ENABLE_DEBUG_ELOGIND
 
@@ -419,8 +420,10 @@ void elogind_manager_reset_config(Manager* m) {
                 m->hybrid_sleep_mode = strv_new("suspend", "platform", "shutdown", NULL);
         if (!m->hybrid_sleep_state)
                 m->hybrid_sleep_state = strv_new("disk", NULL);
+        if (!m->hibernate_delay_sec)
+                m->hibernate_delay_sec = 180 * USEC_PER_MINUTE;
 
-#ifdef ENABLE_DEBUG_ELOGIND
+#if ENABLE_DEBUG_ELOGIND
         dbg_cnt = -1;
         while (m->suspend_mode && m->suspend_mode[++dbg_cnt])
                 log_debug_elogind("suspend_mode[%d] = %s",
@@ -445,6 +448,9 @@ void elogind_manager_reset_config(Manager* m) {
         while (m->hybrid_sleep_state[++dbg_cnt])
                 log_debug_elogind("hybrid_sleep_state[%d] = %s",
                                   dbg_cnt, m->hybrid_sleep_state[dbg_cnt]);
+        log_debug_elogind("hibernate_delay_sec: %lu seconds (%lu minutes)",
+                          m->hibernate_delay_sec / USEC_PER_SEC,
+                          m->hibernate_delay_sec / USEC_PER_MINUTE);
 #endif // ENABLE_DEBUG_ELOGIND
 }