logind: log operation details when starting actions

For some reason, systemd-logind is trying to handle idle action in one of my containers:

Jun 07 10:28:08 rawhide systemd-logind[42]: System idle. Taking action.
Jun 07 10:28:08 rawhide systemd-logind[42]: Requested operation not supported, ignoring.

But we didn't log what exactly was being done. Let's put the name of the action in messages.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2019-06-13 18:11:56 +02:00
parent f2330acda4
commit b81b40d4c4
2 changed files with 24 additions and 25 deletions

View file

@ -78,7 +78,9 @@ int manager_handle_action(
/* If the key handling is inhibited, don't do anything */
if (inhibit_key > 0) {
if (manager_is_inhibited(m, inhibit_key, INHIBIT_BLOCK, NULL, true, false, 0, NULL)) {
log_debug("Refusing operation, %s is inhibited.", inhibit_what_to_string(inhibit_key));
log_debug("Refusing %s operation, %s is inhibited.",
handle_action_to_string(handle),
inhibit_what_to_string(inhibit_key));
return 0;
}
}
@ -109,20 +111,21 @@ int manager_handle_action(
if (!supported && IN_SET(handle, HANDLE_HIBERNATE, HANDLE_HYBRID_SLEEP, HANDLE_SUSPEND_THEN_HIBERNATE)) {
supported = can_sleep("suspend") > 0;
if (supported) {
log_notice("Operation '%s' requested but not supported, using regular suspend instead.", handle_action_to_string(handle));
log_notice("Requested %s operation is not supported, using regular suspend instead.",
handle_action_to_string(handle));
handle = HANDLE_SUSPEND;
}
}
if (!supported) {
log_warning("Requested operation not supported, ignoring.");
return -EOPNOTSUPP;
}
if (!supported)
return log_warning_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"Requested %s operation not supported, ignoring.", handle_action_to_string(handle));
if (m->action_what > 0) {
log_debug("Action already in progress, ignoring.");
return -EALREADY;
}
if (m->action_what > 0)
return log_debug_errno(SYNTHETIC_ERRNO(EALREADY),
"Action already in progress (%s), ignoring requested %s operation.",
inhibit_what_to_string(m->action_what),
handle_action_to_string(handle));
assert_se(target = manager_target_for_action(handle));
@ -139,27 +142,23 @@ int manager_handle_action(
u = uid_to_name(offending->uid);
/* If this is just a recheck of the lid switch then don't warn about anything */
if (!is_edge) {
log_debug("Refusing operation, %s is inhibited by UID "UID_FMT"/%s, PID "PID_FMT"/%s.",
inhibit_what_to_string(inhibit_operation),
offending->uid, strna(u),
offending->pid, strna(comm));
return 0;
}
log_full(is_edge ? LOG_ERR : LOG_DEBUG,
"Refusing %s operation, %s is inhibited by UID "UID_FMT"/%s, PID "PID_FMT"/%s.",
handle_action_to_string(handle),
inhibit_what_to_string(inhibit_operation),
offending->uid, strna(u),
offending->pid, strna(comm));
log_error("Refusing operation, %s is inhibited by UID "UID_FMT"/%s, PID "PID_FMT"/%s.",
inhibit_what_to_string(inhibit_operation),
offending->uid, strna(u),
offending->pid, strna(comm));
return -EPERM;
return is_edge ? -EPERM : 0;
}
log_info("%s", message_table[handle]);
r = bus_manager_shutdown_or_sleep_now_or_later(m, target, inhibit_operation, &error);
if (r < 0)
return log_error_errno(r, "Failed to execute operation: %s", bus_error_message(&error, r));
return log_error_errno(r, "Failed to execute %s operation: %s",
handle_action_to_string(handle),
bus_error_message(&error, r));
return 1;
}

View file

@ -1021,7 +1021,7 @@ static int manager_dispatch_idle_action(sd_event_source *s, uint64_t t, void *us
if (n >= since.monotonic + m->idle_action_usec &&
(m->idle_action_not_before_usec <= 0 || n >= m->idle_action_not_before_usec + m->idle_action_usec)) {
log_info("System idle. Taking action.");
log_info("System idle. Doing %s operation.", handle_action_to_string(m->idle_action));
manager_handle_action(m, 0, m->idle_action, false, false);
m->idle_action_not_before_usec = n;