2 This file is part of elogind.
4 Copyright 2017 Sven Eden
6 elogind is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 elogind is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with elogind; If not, see <http://www.gnu.org/licenses/>.
21 #include "elogind-action.h"
23 #include "process-util.h"
25 #include "sleep-config.h"
28 static int run_helper(const char *helper) {
31 return log_error_errno(errno, "Failed to fork: %m");
37 close_all_fds(NULL, 0);
39 execlp(helper, helper, NULL);
40 log_error_errno(errno, "Failed to execute %s: %m", helper);
44 return wait_for_terminate_and_warn(helper, pid, true);
47 int shutdown_or_sleep(Manager *m, HandleAction action) {
53 return run_helper(HALT);
55 return run_helper(REBOOT);
57 return run_helper(HALT);
59 return run_helper(KEXEC);
61 return do_sleep("suspend", m->suspend_mode, m->suspend_state);
62 case HANDLE_HIBERNATE:
63 return do_sleep("hibernate", m->hibernate_mode, m->hibernate_state);
64 case HANDLE_HYBRID_SLEEP:
65 return do_sleep("hybrid-sleep", m->hybrid_sleep_mode, m->hybrid_sleep_state);