chiark / gitweb /
logind: hook up inhibit logic with idle hint logic
[elogind.git] / src / login / logind-inhibit.c
index 2f7a758e7cf2bba48efe87b6b500eee00f84b483..78afee3139e13dcd76645f44adae74dbddae4bdb 100644 (file)
@@ -150,6 +150,8 @@ int inhibitor_start(Inhibitor *i) {
         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);
@@ -325,6 +327,32 @@ InhibitWhat manager_inhibit_what(Manager *m) {
         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] = {