terminal: signal object removal during sysview_context_stop()
authorDavid Herrmann <dh.herrmann@gmail.com>
Mon, 22 Sep 2014 16:05:19 +0000 (18:05 +0200)
committerDavid Herrmann <dh.herrmann@gmail.com>
Mon, 22 Sep 2014 16:14:44 +0000 (18:14 +0200)
Now that we no longer propagate callback return values, we can safely call
into user-callbacks during sysview_context_stop(). This way, users can
rely on all objects to be removed via callbacks (except if they failed
during object creation). This avoids duplicating any object hashtables on
the users' side and reduces memory consumption.

src/libsystemd-terminal/evcat.c
src/libsystemd-terminal/modeset.c
src/libsystemd-terminal/sysview.c

index b3f08e60bf8614819bc467637a035aea008145a8..62556f6a2b4e83f1b9d1025ba373115b6d91b2dd 100644 (file)
@@ -330,7 +330,8 @@ static int evcat_sysview_fn(sysview_context *c, void *userdata, sysview_event *e
         case SYSVIEW_EVENT_SESSION_REMOVE:
                 idev_session_disable(e->idev_session);
                 e->idev_session = idev_session_free(e->idev_session);
-                sd_event_exit(e->event, 0);
+                if (sd_event_get_exit_code(e->event, &r) == -ENODATA)
+                        sd_event_exit(e->event, 0);
                 break;
         case SYSVIEW_EVENT_SESSION_ATTACH:
                 d = ev->session_attach.device;
index 7a28e7ab97ff941f59a70dee831182c8356d0584..f564fa0f6513d34a475c43bd0a5f35f43621f467 100644 (file)
@@ -332,7 +332,8 @@ static int modeset_sysview_fn(sysview_context *c, void *userdata, sysview_event
                 grdev_session_restore(m->grdev_session);
                 grdev_session_disable(m->grdev_session);
                 m->grdev_session = grdev_session_free(m->grdev_session);
-                sd_event_exit(m->event, 0);
+                if (sd_event_get_exit_code(m->event, &r) == -ENODATA)
+                        sd_event_exit(m->event, 0);
                 break;
         case SYSVIEW_EVENT_SESSION_ATTACH:
                 d = ev->session_attach.device;
index 969514ad9de9370ac84f8ba1d4cd796f97969a64..cd776f62d8c162ce8b5b2a5c11b1535d83bdd67f 100644 (file)
@@ -1437,20 +1437,6 @@ void sysview_context_stop(sysview_context *c) {
 
         log_debug("sysview: stop");
 
-        c->running = false;
-        c->scanned = false;
-        c->event_fn = NULL;
-        c->userdata = NULL;
-        c->scan_src = sd_event_source_unref(c->scan_src);
-        context_ud_stop(c);
-        context_ld_stop(c);
-
-        /*
-         * Event-callbacks are already cleared, hence we can safely ignore
-         * return codes of the context_remove_*() helpers. They cannot be
-         * originated from user-callbacks, so we already handled them.
-         */
-
         while ((device = hashmap_first(c->device_map)))
                 context_remove_device(c, device);
 
@@ -1459,6 +1445,14 @@ void sysview_context_stop(sysview_context *c) {
 
         while ((seat = hashmap_first(c->seat_map)))
                 context_remove_seat(c, seat);
+
+        c->running = false;
+        c->scanned = false;
+        c->event_fn = NULL;
+        c->userdata = NULL;
+        c->scan_src = sd_event_source_unref(c->scan_src);
+        context_ud_stop(c);
+        context_ld_stop(c);
 }
 
 static int context_scan_fn(sd_event_source *s, void *userdata) {