return bus_send_error_reply(connection, message, &error, r);
multiple_sessions = r > 0;
- inhibit = !!(manager_inhibit_what(m) & INHIBIT_SHUTDOWN);
+ inhibit = manager_is_inhibited(m, INHIBIT_SHUTDOWN, NULL);
if (multiple_sessions) {
action = streq(dbus_message_get_member(message), "PowerOff") ?
return bus_send_error_reply(connection, message, &error, r);
multiple_sessions = r > 0;
- inhibit = !!(manager_inhibit_what(m) & INHIBIT_SHUTDOWN);
+ inhibit = manager_is_inhibited(m, INHIBIT_SHUTDOWN, NULL);
if (multiple_sessions) {
action = streq(dbus_message_get_member(message), "CanPowerOff") ?
if (i->started)
return 0;
+ dual_timestamp_get(&i->since);
+
log_debug("Inhibitor %s (%s) pid=%lu uid=%lu started.",
strna(i->who), strna(i->why),
(unsigned long) i->pid, (unsigned long) i->uid);
return what;
}
+bool manager_is_inhibited(Manager *m, InhibitWhat w, dual_timestamp *since) {
+ Inhibitor *i;
+ Iterator j;
+ struct dual_timestamp ts = { 0, 0 };
+ bool inhibited = false;
+
+ assert(m);
+ assert(w > 0 && w < _INHIBIT_WHAT_MAX);
+
+ HASHMAP_FOREACH(i, m->inhibitor_fds, j) {
+ if (!(i->what & w))
+ continue;
+
+ if (!inhibited ||
+ i->since.monotonic < ts.monotonic)
+ ts = i->since;
+
+ inhibited = true;
+ }
+
+ if (since)
+ *since = ts;
+
+ return inhibited;
+}
+
const char *inhibit_what_to_string(InhibitWhat w) {
static const char* const table[_INHIBIT_WHAT_MAX] = {
pid_t pid;
uid_t uid;
+ dual_timestamp since;
+
char *fifo_path;
int fifo_fd;
};
void inhibitor_remove_fifo(Inhibitor *i);
InhibitWhat manager_inhibit_what(Manager *m);
+bool manager_is_inhibited(Manager *m, InhibitWhat w, dual_timestamp *since);
const char *inhibit_what_to_string(InhibitWhat k);
InhibitWhat inhibit_what_from_string(const char *s);
int manager_get_idle_hint(Manager *m, dual_timestamp *t) {
Session *s;
- bool idle_hint = true;
+ bool idle_hint;
dual_timestamp ts = { 0, 0 };
Iterator i;
assert(m);
+ idle_hint = !manager_is_inhibited(m, INHIBIT_IDLE, t);
+
HASHMAP_FOREACH(s, m->sessions, i) {
dual_timestamp k;
int ih;