chiark / gitweb /
Prep v233.3: Moved shutdown_or_sleep() and run_helper() to elogind-dbus.c, so elogind...
authorSven Eden <yamakuzure@gmx.net>
Thu, 20 Jul 2017 15:16:50 +0000 (17:16 +0200)
committerSven Eden <yamakuzure@gmx.net>
Thu, 20 Jul 2017 15:19:28 +0000 (17:19 +0200)
Makefile.am
cb/elogind.cbp
src/login/elogind-action.c [deleted file]
src/login/elogind-action.h [deleted file]
src/login/elogind-dbus.c
src/login/logind-action.h

index 977d44d..33bb9fd 100644 (file)
@@ -1093,8 +1093,6 @@ libelogind_core_la_SOURCES = \
        src/core/mount-setup.c \
         src/login/elogind.c \
         src/login/elogind.h \
-        src/login/elogind-action.c \
-        src/login/elogind-action.h \
        src/login/elogind-dbus.c \
        src/login/elogind-dbus.h \
        src/login/logind-core.c \
index f92a5fe..b1171e3 100644 (file)
                        <Option compilerVar="CC" />
                </Unit>
                <Unit filename="../src/login/eloginctl.h" />
-               <Unit filename="../src/login/elogind-action.c">
-                       <Option compilerVar="CC" />
-               </Unit>
-               <Unit filename="../src/login/elogind-action.h" />
                <Unit filename="../src/login/elogind-dbus.c">
                        <Option compilerVar="CC" />
                </Unit>
diff --git a/src/login/elogind-action.c b/src/login/elogind-action.c
deleted file mode 100644 (file)
index 17e1dd2..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/***
-  This file is part of elogind.
-
-  Copyright 2017 Sven Eden
-
-  elogind is free software; you can redistribute it and/or modify it
-  under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or
-  (at your option) any later version.
-
-  elogind is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with elogind; If not, see <http://www.gnu.org/licenses/>.
-***/
-
-
-#include "elogind-action.h"
-#include "fd-util.h"
-#include "process-util.h"
-#include "sleep.h"
-#include "sleep-config.h"
-
-
-static int run_helper(const char *helper) {
-        int pid = fork();
-        if (pid < 0) {
-                return log_error_errno(errno, "Failed to fork: %m");
-        }
-
-        if (pid == 0) {
-                /* Child */
-
-                close_all_fds(NULL, 0);
-
-                execlp(helper, helper, NULL);
-                log_error_errno(errno, "Failed to execute %s: %m", helper);
-                _exit(EXIT_FAILURE);
-        }
-
-        return wait_for_terminate_and_warn(helper, pid, true);
-}
-
-int shutdown_or_sleep(Manager *m, HandleAction action) {
-
-        assert(m);
-
-        switch (action) {
-        case HANDLE_POWEROFF:
-                return run_helper(HALT);
-        case HANDLE_REBOOT:
-                return run_helper(REBOOT);
-        case HANDLE_HALT:
-                return run_helper(HALT);
-        case HANDLE_KEXEC:
-                return run_helper(KEXEC);
-        case HANDLE_SUSPEND:
-                return do_sleep("suspend", m->suspend_mode, m->suspend_state);
-        case HANDLE_HIBERNATE:
-                return do_sleep("hibernate", m->hibernate_mode, m->hibernate_state);
-        case HANDLE_HYBRID_SLEEP:
-                return do_sleep("hybrid-sleep", m->hybrid_sleep_mode, m->hybrid_sleep_state);
-        default:
-                return -EINVAL;
-        }
-}
diff --git a/src/login/elogind-action.h b/src/login/elogind-action.h
deleted file mode 100644 (file)
index 8df7aad..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-#pragma once
-#ifndef ELOGIND_SRC_LOGIN_ELOGIND_ACTION_H_INCLUDED
-#define ELOGIND_SRC_LOGIN_ELOGIND_ACTION_H_INCLUDED
-
-/***
-  This file is part of elogind.
-
-  Copyright 2017 Sven Eden
-
-  elogind is free software; you can redistribute it and/or modify it
-  under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or
-  (at your option) any later version.
-
-  elogind is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with elogind; If not, see <http://www.gnu.org/licenses/>.
-***/
-
-#include "logind.h"
-
-
-int shutdown_or_sleep(Manager *m, HandleAction action);
-
-
-#endif // ELOGIND_SRC_LOGIN_ELOGIND_ACTION_H_INCLUDED
index 23ea9bd..7f0f706 100644 (file)
 #include "bus-error.h"
 #include "bus-util.h"
 #include "elogind-dbus.h"
+#include "fd-util.h"
 #include "process-util.h"
 #include "sd-messages.h"
+#include "sleep.h"
 #include "sleep-config.h"
 #include "string-util.h"
 #include "strv.h"
@@ -118,6 +120,51 @@ static int send_prepare_for(Manager *m, InhibitWhat w, bool _active) {
                                   active);
 }
 
+/* elogind specific helper to make HALT and REBOOT possible. */
+static int run_helper(const char *helper) {
+        int pid = fork();
+        if (pid < 0) {
+                return log_error_errno(errno, "Failed to fork: %m");
+        }
+
+        if (pid == 0) {
+                /* Child */
+
+                close_all_fds(NULL, 0);
+
+                execlp(helper, helper, NULL);
+                log_error_errno(errno, "Failed to execute %s: %m", helper);
+                _exit(EXIT_FAILURE);
+        }
+
+        return wait_for_terminate_and_warn(helper, pid, true);
+}
+
+/* elogind specific executor */
+static int shutdown_or_sleep(Manager *m, HandleAction action) {
+
+        assert(m);
+
+        switch (action) {
+        case HANDLE_POWEROFF:
+                return run_helper(HALT);
+        case HANDLE_REBOOT:
+                return run_helper(REBOOT);
+        case HANDLE_HALT:
+                return run_helper(HALT);
+        case HANDLE_KEXEC:
+                return run_helper(KEXEC);
+        case HANDLE_SUSPEND:
+                return do_sleep("suspend", m->suspend_mode, m->suspend_state);
+        case HANDLE_HIBERNATE:
+                return do_sleep("hibernate", m->hibernate_mode, m->hibernate_state);
+        case HANDLE_HYBRID_SLEEP:
+                return do_sleep("hybrid-sleep", m->hybrid_sleep_mode, m->hybrid_sleep_state);
+        default:
+                return -EINVAL;
+        }
+}
+
 static int execute_shutdown_or_sleep(
                 Manager *m,
                 InhibitWhat w,
index d33b9de..fb40ae4 100644 (file)
@@ -36,9 +36,6 @@ typedef enum HandleAction {
 #include "logind-inhibit.h"
 #include "logind.h"
 
-/// Additional includes needed by elogind
-#include "elogind-action.h"
-
 int manager_handle_action(
                 Manager *m,
                 InhibitWhat inhibit_key,