logind-action.c revision 15411c0cb1192799b37ec8f25d6f30e8d7292fc6
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster This file is part of systemd.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Copyright 2012 Lennart Poettering
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster systemd is free software; you can redistribute it and/or modify it
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster under the terms of the GNU Lesser General Public License as published by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster the Free Software Foundation; either version 2.1 of the License, or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster (at your option) any later version.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster systemd is distributed in the hope that it will be useful, but
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster WITHOUT ANY WARRANTY; without even the implied warranty of
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Lesser General Public License for more details.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster You should have received a copy of the GNU Lesser General Public License
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster along with systemd; If not, see <http://www.gnu.org/licenses/>.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static const char * const message_table[_HANDLE_ACTION_MAX] = {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster [HANDLE_HYBRID_SLEEP] = "Hibernating and suspending..."
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static const char * const target_table[_HANDLE_ACTION_MAX] = {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster [HANDLE_HYBRID_SLEEP] = SPECIAL_HYBRID_SLEEP_TARGET
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* If the key handling is turned off, don't do anything */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster log_debug("Refusing operation, as it is turned off.");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (inhibit_key == INHIBIT_HANDLE_LID_SWITCH) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* If the last system suspend or startup is too close,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * let's not suspend for now, to give USB docking
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * stations some time to settle so that we can
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * properly watch its displays. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster log_debug("Ignoring lid switch request, system startup or resume too close.");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* If the key handling is inhibited, don't do anything */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (manager_is_inhibited(m, inhibit_key, INHIBIT_BLOCK, NULL, true, false, 0, NULL)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster log_debug("Refusing operation, %s is inhibited.", inhibit_what_to_string(inhibit_key));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* Locking is handled differently from the rest. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster log_warning("Requested operation not supported, ignoring.");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster log_debug("Action already in progress, ignoring.");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster inhibit_operation = handle == HANDLE_SUSPEND || handle == HANDLE_HIBERNATE || handle == HANDLE_HYBRID_SLEEP ? INHIBIT_SLEEP : INHIBIT_SHUTDOWN;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* If the actual operation is inhibited, warn and fail */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster manager_is_inhibited(m, inhibit_operation, INHIBIT_BLOCK, NULL, false, false, 0, &offending)) {
if (!is_edge) {
warn_melody();
return -EPERM;
DEFINE_CONFIG_PARSE_ENUM(config_parse_handle_action, handle_action, HandleAction, "Failed to parse handle action setting");