logind-action.c revision 23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye This file is part of systemd.
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye Copyright 2012 Lennart Poettering
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye systemd is free software; you can redistribute it and/or modify it
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye under the terms of the GNU Lesser General Public License as published by
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye the Free Software Foundation; either version 2.1 of the License, or
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye (at your option) any later version.
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye systemd is distributed in the hope that it will be useful, but
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye WITHOUT ANY WARRANTY; without even the implied warranty of
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye Lesser General Public License for more details.
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye You should have received a copy of the GNU Lesser General Public License
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye along with systemd; If not, see <http://www.gnu.org/licenses/>.
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye static const char * const message_table[_HANDLE_ACTION_MAX] = {
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye [HANDLE_HYBRID_SLEEP] = "Hibernating and suspending..."
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye static const char * const target_table[_HANDLE_ACTION_MAX] = {
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye [HANDLE_HYBRID_SLEEP] = SPECIAL_HYBRID_SLEEP_TARGET
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye /* If the key handling is turned off, don't do anything */
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye log_debug("Refusing operation, as it is turned off.");
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye /* If the key handling is inhibited, don't do anything */
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye if (manager_is_inhibited(m, inhibit_key, INHIBIT_BLOCK, NULL, true, false, 0)) {
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye log_debug("Refusing operation, %s is inhibited.", inhibit_what_to_string(inhibit_key));
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye /* Locking is handled differently from the rest. */
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye inhibit_operation = handle == HANDLE_SUSPEND || handle == HANDLE_HIBERNATE || handle == HANDLE_HYBRID_SLEEP ? INHIBIT_SLEEP : INHIBIT_SHUTDOWN;
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye /* If the actual operation is inhibited, warn and fail */
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye manager_is_inhibited(m, inhibit_operation, INHIBIT_BLOCK, NULL, false, false, 0)) {
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye /* If this is just a recheck of the lid switch then don't warn about anything */
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye log_debug("Refusing operation, %s is inhibited.", inhibit_what_to_string(inhibit_operation));
c7eb123c8b2081a261deff3c401fbf92ddba1b58Jorgen Austvik log_error("Refusing operation, %s is inhibited.", inhibit_what_to_string(inhibit_operation));
d3d2404f9a49bf70b124053feabe666f85ef5361Knut Anders Hatlen r = bus_manager_shutdown_or_sleep_now_or_later(m, target_table[handle], inhibit_operation, &error);
780cc7d1b57609ff15fb283201e93cb501ebe9e6Jorgen Austvik log_error("Failed to execute operation: %s", bus_error_message(&error));
5a0c5ad4116f5a4dd0dd5a0a4e6d02973cd5eef9Lubos Koscostatic const char* const handle_action_table[_HANDLE_ACTION_MAX] = {
c7eb123c8b2081a261deff3c401fbf92ddba1b58Jorgen AustvikDEFINE_STRING_TABLE_LOOKUP(handle_action, HandleAction);
5a0c5ad4116f5a4dd0dd5a0a4e6d02973cd5eef9Lubos KoscoDEFINE_CONFIG_PARSE_ENUM(config_parse_handle_action, handle_action, HandleAction, "Failed to parse handle action setting");