Compare commits
4 Commits
b19b0dc170
...
e5a91b3e4a
Author | SHA1 | Date |
---|---|---|
Zbigniew Jędrzejewski-Szmek | e5a91b3e4a | |
Luca Boccassi | b7eefa1996 | |
Zbigniew Jędrzejewski-Szmek | 0e54562082 | |
Zbigniew Jędrzejewski-Szmek | 03af199aaf |
|
@ -799,7 +799,7 @@ int cg_pid_get_path(const char *controller, pid_t pid, char **ret_path) {
|
|||
continue;
|
||||
}
|
||||
|
||||
char *path = strdup(e + 1);
|
||||
_cleanup_free_ char *path = strdup(e + 1);
|
||||
if (!path)
|
||||
return -ENOMEM;
|
||||
|
||||
|
@ -812,7 +812,7 @@ int cg_pid_get_path(const char *controller, pid_t pid, char **ret_path) {
|
|||
if (e)
|
||||
*e = 0;
|
||||
|
||||
*ret_path = path;
|
||||
*ret_path = TAKE_PTR(path);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -234,7 +234,7 @@ static int handle_action_execute(
|
|||
/* 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, false, 0, &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);
|
||||
|
@ -372,7 +372,7 @@ 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, /* block= */ true, NULL, true, false, 0, 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));
|
||||
|
|
|
@ -411,7 +411,7 @@ int manager_get_idle_hint(Manager *m, dual_timestamp *t) {
|
|||
|
||||
assert(m);
|
||||
|
||||
idle_hint = !manager_is_inhibited(m, INHIBIT_IDLE, /* block= */ true, t, false, false, 0, NULL);
|
||||
idle_hint = !manager_is_inhibited(m, INHIBIT_IDLE, t, /* flags= */ 0, UID_INVALID, NULL);
|
||||
|
||||
HASHMAP_FOREACH(s, m->sessions) {
|
||||
dual_timestamp k;
|
||||
|
|
|
@ -1931,7 +1931,12 @@ int manager_dispatch_delayed(Manager *manager, bool timeout) {
|
|||
if (!manager->delayed_action || manager->action_job)
|
||||
return 0;
|
||||
|
||||
if (manager_is_inhibited(manager, manager->delayed_action->inhibit_what, /* block= */ false, NULL, false, false, 0, &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)
|
||||
|
@ -2033,7 +2038,7 @@ int bus_manager_shutdown_or_sleep_now_or_later(
|
|||
|
||||
delayed =
|
||||
m->inhibit_delay_max > 0 &&
|
||||
manager_is_inhibited(m, a->inhibit_what, /* block= */ false, NULL, false, false, 0, 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
|
||||
|
@ -2077,7 +2082,7 @@ static int verify_shutdown_creds(
|
|||
return r;
|
||||
|
||||
multiple_sessions = r > 0;
|
||||
blocked = manager_is_inhibited(m, a->inhibit_what, /* block= */ true, NULL, false, true, uid, &offending);
|
||||
blocked = manager_is_inhibited(m, a->inhibit_what, NULL, /* flags= */ 0, uid, &offending);
|
||||
interactive = flags & SD_LOGIND_INTERACTIVE;
|
||||
|
||||
if (multiple_sessions) {
|
||||
|
@ -2820,7 +2825,7 @@ static int method_can_shutdown_or_sleep(
|
|||
return r;
|
||||
|
||||
multiple_sessions = r > 0;
|
||||
blocked = manager_is_inhibited(m, a->inhibit_what, /* block= */ true, NULL, false, true, 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;
|
||||
|
|
|
@ -399,11 +399,9 @@ static int pidref_is_active_session(Manager *m, const PidRef *pid) {
|
|||
bool manager_is_inhibited(
|
||||
Manager *m,
|
||||
InhibitWhat w,
|
||||
bool block,
|
||||
dual_timestamp *since,
|
||||
bool ignore_inactive,
|
||||
bool ignore_uid,
|
||||
uid_t uid,
|
||||
ManagerIsInhibitedFlags flags,
|
||||
uid_t uid_to_ignore,
|
||||
Inhibitor **ret_offending) {
|
||||
|
||||
Inhibitor *i, *offending = NULL;
|
||||
|
@ -421,18 +419,19 @@ bool manager_is_inhibited(
|
|||
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 && ignore_uid && i->uid == uid)
|
||||
if (i->mode == INHIBIT_BLOCK_WEAK &&
|
||||
uid_is_valid(uid_to_ignore) &&
|
||||
uid_to_ignore == i->uid)
|
||||
continue;
|
||||
|
||||
if (!inhibited ||
|
||||
i->since.monotonic < ts.monotonic)
|
||||
if (!inhibited || i->since.monotonic < ts.monotonic)
|
||||
ts = i->since;
|
||||
|
||||
inhibited = true;
|
||||
|
|
|
@ -67,7 +67,20 @@ int inhibitor_create_fifo(Inhibitor *i);
|
|||
bool inhibitor_is_orphan(Inhibitor *i);
|
||||
|
||||
InhibitWhat manager_inhibit_what(Manager *m, InhibitMode mode);
|
||||
bool manager_is_inhibited(Manager *m, InhibitWhat w, bool block, dual_timestamp *since, bool ignore_inactive, bool ignore_uid, uid_t uid, Inhibitor **offending);
|
||||
|
||||
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,
|
||||
dual_timestamp *since,
|
||||
ManagerIsInhibitedFlags flags,
|
||||
uid_t uid_to_ignore,
|
||||
Inhibitor **ret_offending);
|
||||
|
||||
static inline bool inhibit_what_is_valid(InhibitWhat w) {
|
||||
return w > 0 && w < _INHIBIT_WHAT_MAX;
|
||||
|
|
Loading…
Reference in New Issue