chiark / gitweb /
logind: if a user is sitting in front of the computer and can shutdown the machine...
[elogind.git] / src / login / logind-session-device.c
index 80fd36413947ff2ae0833da58034cd28d1a59bef..b45f9ebe0cc50ba2fa5bbf9cd641dadad8697d20 100644 (file)
@@ -369,9 +369,7 @@ int session_device_new(Session *s, dev_t dev, SessionDevice **out) {
         if (r < 0)
                 goto error;
 
-        assert_cc(sizeof(unsigned long) >= sizeof(dev_t));
-
-        r = hashmap_put(s->devices, ULONG_TO_PTR((unsigned long)sd->dev), sd);
+        r = hashmap_put(s->devices, &sd->dev, sd);
         if (r < 0) {
                 r = -ENOMEM;
                 goto error;
@@ -392,7 +390,7 @@ int session_device_new(Session *s, dev_t dev, SessionDevice **out) {
         return 0;
 
 error:
-        hashmap_remove(s->devices, ULONG_TO_PTR((unsigned long)sd->dev));
+        hashmap_remove(s->devices, &sd->dev);
         free(sd->node);
         free(sd);
         return r;
@@ -407,17 +405,28 @@ void session_device_free(SessionDevice *sd) {
 
         LIST_REMOVE(SessionDevice, sd_by_device, sd->device->session_devices, sd);
 
-        hashmap_remove(sd->session->devices, ULONG_TO_PTR((unsigned long)sd->dev));
+        hashmap_remove(sd->session->devices, &sd->dev);
 
         free(sd->node);
         free(sd);
 }
 
 void session_device_complete_pause(SessionDevice *sd) {
+        SessionDevice *iter;
+        Iterator i;
+
         if (!sd->active)
                 return;
 
         session_device_stop(sd);
+
+        /* if not all devices are paused, wait for further completion events */
+        HASHMAP_FOREACH(iter, sd->session->devices, i)
+                if (iter->active)
+                        return;
+
+        /* complete any pending session switch */
+        seat_complete_switch(sd->session->seat);
 }
 
 void session_device_resume_all(Session *s) {
@@ -449,3 +458,20 @@ void session_device_pause_all(Session *s) {
                 }
         }
 }
+
+unsigned int session_device_try_pause_all(Session *s) {
+        SessionDevice *sd;
+        Iterator i;
+        unsigned int num_pending = 0;
+
+        assert(s);
+
+        HASHMAP_FOREACH(sd, s->devices, i) {
+                if (sd->active) {
+                        session_device_notify(sd, SESSION_DEVICE_TRY_PAUSE);
+                        ++num_pending;
+                }
+        }
+
+        return num_pending;
+}