The most common case of block=true, ignore_inactive=false is mapped to flags=0.
For https://github.com/systemd/systemd/issues/34091.
/* If the actual operation is inhibited, warn and fail */
if (inhibit_what_is_valid(inhibit_operation) &&
!ignore_inhibited &&
- manager_is_inhibited(m, inhibit_operation, /* block= */ true, NULL, false, UID_INVALID, &offending)) {
+ manager_is_inhibited(m, inhibit_operation, NULL, /* flags= */ 0, UID_INVALID, &offending)) {
_cleanup_free_ char *comm = NULL, *u = NULL;
(void) pidref_get_comm(&offending->pid, &comm);
/* If the key handling is inhibited, don't do anything */
if (inhibit_key > 0) {
- if (manager_is_inhibited(m, inhibit_key, /* block= */ true, NULL, true, UID_INVALID, NULL)) {
+ if (manager_is_inhibited(m, inhibit_key, NULL, MANAGER_IS_INHIBITED_IGNORE_INACTIVE, UID_INVALID, NULL)) {
log_debug("Refusing %s operation, %s is inhibited.",
handle_action_to_string(handle),
inhibit_what_to_string(inhibit_key));
assert(m);
- idle_hint = !manager_is_inhibited(m, INHIBIT_IDLE, /* block= */ true, t, false, UID_INVALID, NULL);
+ idle_hint = !manager_is_inhibited(m, INHIBIT_IDLE, t, /* flags= */ 0, UID_INVALID, NULL);
HASHMAP_FOREACH(s, m->sessions) {
dual_timestamp k;
if (!manager->delayed_action || manager->action_job)
return 0;
- if (manager_is_inhibited(manager, manager->delayed_action->inhibit_what, /* block= */ false, NULL, false, UID_INVALID, &offending)) {
+ if (manager_is_inhibited(manager,
+ manager->delayed_action->inhibit_what,
+ NULL,
+ MANAGER_IS_INHIBITED_CHECK_DELAY,
+ UID_INVALID,
+ &offending)) {
_cleanup_free_ char *comm = NULL, *u = NULL;
if (!timeout)
delayed =
m->inhibit_delay_max > 0 &&
- manager_is_inhibited(m, a->inhibit_what, /* block= */ false, NULL, false, UID_INVALID, NULL);
+ manager_is_inhibited(m, a->inhibit_what, NULL, MANAGER_IS_INHIBITED_CHECK_DELAY, UID_INVALID, NULL);
if (delayed)
/* Shutdown is delayed, keep in mind what we
return r;
multiple_sessions = r > 0;
- blocked = manager_is_inhibited(m, a->inhibit_what, /* block= */ true, NULL, false, uid, &offending);
+ blocked = manager_is_inhibited(m, a->inhibit_what, NULL, /* flags= */ 0, uid, &offending);
interactive = flags & SD_LOGIND_INTERACTIVE;
if (multiple_sessions) {
return r;
multiple_sessions = r > 0;
- blocked = manager_is_inhibited(m, a->inhibit_what, /* block= */ true, NULL, false, uid, NULL);
+ blocked = manager_is_inhibited(m, a->inhibit_what, NULL, /* flags= */ 0, uid, NULL);
if (check_unit_state && a->target) {
_cleanup_free_ char *load_state = NULL;
bool manager_is_inhibited(
Manager *m,
InhibitWhat w,
- bool block,
dual_timestamp *since,
- bool ignore_inactive,
+ ManagerIsInhibitedFlags flags,
uid_t uid_to_ignore,
Inhibitor **ret_offending) {
if (!(i->what & w))
continue;
- if ((block && !IN_SET(i->mode, INHIBIT_BLOCK, INHIBIT_BLOCK_WEAK)) ||
- (!block && i->mode != INHIBIT_DELAY))
+ if ((flags & MANAGER_IS_INHIBITED_CHECK_DELAY) != (i->mode == INHIBIT_DELAY))
continue;
- if (ignore_inactive && pidref_is_active_session(m, &i->pid) <= 0)
+ if ((flags & MANAGER_IS_INHIBITED_IGNORE_INACTIVE) &&
+ pidref_is_active_session(m, &i->pid) <= 0)
continue;
if (i->mode == INHIBIT_BLOCK_WEAK &&
bool inhibitor_is_orphan(Inhibitor *i);
InhibitWhat manager_inhibit_what(Manager *m, InhibitMode mode);
+
+typedef enum ManagerIsInhibitedFlags {
+ MANAGER_IS_INHIBITED_CHECK_DELAY = 1 << 0, /* When set, we only check delay inhibitors.
+ * Otherwise, we only check block inhibitors. */
+ MANAGER_IS_INHIBITED_IGNORE_INACTIVE = 1 << 1, /* When set, ignore inactive sessions. */
+} ManagerIsInhibitedFlags;
+
bool manager_is_inhibited(
Manager *m,
InhibitWhat w,
- bool block,
dual_timestamp *since,
- bool ignore_inactive,
+ ManagerIsInhibitedFlags flags,
uid_t uid_to_ignore,
Inhibitor **ret_offending);