X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Flogin%2Flogind-inhibit.c;h=9994084f93dc3d41427a6de22e0153a629213256;hp=6acc5c82768a60a3e0a5272dcba50dba539f66a4;hb=c6a818c82035da91e;hpb=beaafb2ea6be591882aef21fe19b88e3b2461087 diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index 6acc5c827..9994084f9 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -30,6 +30,7 @@ #include "mkdir.h" #include "path-util.h" #include "logind-inhibit.h" +#include "fileio.h" Inhibitor* inhibitor_new(Manager *m, const char* id) { Inhibitor *i; @@ -364,7 +365,9 @@ bool manager_is_inhibited( InhibitWhat w, InhibitMode mm, dual_timestamp *since, - bool only_active) { + bool ignore_inactive, + bool ignore_uid, + uid_t uid) { Inhibitor *i; Iterator j; @@ -381,7 +384,10 @@ bool manager_is_inhibited( if (i->mode != mm) continue; - if (only_active && pid_is_active(m, i->pid) <= 0) + if (ignore_inactive && pid_is_active(m, i->pid) <= 0) + continue; + + if (ignore_uid && i->uid == uid) continue; if (!inhibited || @@ -398,7 +404,7 @@ bool manager_is_inhibited( } const char *inhibit_what_to_string(InhibitWhat w) { - static __thread char buffer[73]; + static __thread char buffer[97]; char *p; if (w < 0 || w >= _INHIBIT_WHAT_MAX) @@ -413,8 +419,10 @@ const char *inhibit_what_to_string(InhibitWhat w) { p = stpcpy(p, "idle:"); if (w & INHIBIT_HANDLE_POWER_KEY) p = stpcpy(p, "handle-power-key:"); - if (w & INHIBIT_HANDLE_SLEEP_KEY) - p = stpcpy(p, "handle-sleep-key:"); + if (w & INHIBIT_HANDLE_SUSPEND_KEY) + p = stpcpy(p, "handle-suspend-key:"); + if (w & INHIBIT_HANDLE_HIBERNATE_KEY) + p = stpcpy(p, "handle-hibernate-key:"); if (w & INHIBIT_HANDLE_LID_SWITCH) p = stpcpy(p, "handle-lid-switch:"); @@ -432,17 +440,19 @@ InhibitWhat inhibit_what_from_string(const char *s) { size_t l; FOREACH_WORD_SEPARATOR(w, l, s, ":", state) { - if (l == 8 && strncmp(w, "shutdown", l) == 0) + if (l == 8 && strneq(w, "shutdown", l)) what |= INHIBIT_SHUTDOWN; - else if (l == 5 && strncmp(w, "sleep", l) == 0) + else if (l == 5 && strneq(w, "sleep", l)) what |= INHIBIT_SLEEP; - else if (l == 4 && strncmp(w, "idle", l) == 0) + else if (l == 4 && strneq(w, "idle", l)) what |= INHIBIT_IDLE; - else if (l == 16 && strncmp(w, "handle-power-key", l) == 0) + else if (l == 16 && strneq(w, "handle-power-key", l)) what |= INHIBIT_HANDLE_POWER_KEY; - else if (l == 16 && strncmp(w, "handle-sleep-key", l) == 0) - what |= INHIBIT_HANDLE_SLEEP_KEY; - else if (l == 16 && strncmp(w, "handle-lid-switch", l) == 0) + else if (l == 18 && strneq(w, "handle-suspend-key", l)) + what |= INHIBIT_HANDLE_SUSPEND_KEY; + else if (l == 20 && strneq(w, "handle-hibernate-key", l)) + what |= INHIBIT_HANDLE_HIBERNATE_KEY; + else if (l == 17 && strneq(w, "handle-lid-switch", l)) what |= INHIBIT_HANDLE_LID_SWITCH; else return _INHIBIT_WHAT_INVALID;