chiark / gitweb /
sd-event: treat NULL callback for timer events like sig events
authorTom Gundersen <teg@jklm.no>
Sun, 1 Feb 2015 17:06:40 +0000 (18:06 +0100)
committerTom Gundersen <teg@jklm.no>
Mon, 2 Feb 2015 10:57:52 +0000 (11:57 +0100)
In both cases exit the event loop.

src/libsystemd/sd-event/sd-event.c

index f9fa54d..25089a0 100644 (file)
@@ -891,6 +891,12 @@ static int event_setup_timer_fd(
         return 0;
 }
 
+static int time_exit_callback(sd_event_source *s, uint64_t usec, void *userdata) {
+        assert(s);
+
+        return sd_event_exit(sd_event_source_get_event(s), PTR_TO_INT(userdata));
+}
+
 _public_ int sd_event_add_time(
                 sd_event *e,
                 sd_event_source **ret,
@@ -908,10 +914,12 @@ _public_ int sd_event_add_time(
         assert_return(e, -EINVAL);
         assert_return(usec != (uint64_t) -1, -EINVAL);
         assert_return(accuracy != (uint64_t) -1, -EINVAL);
-        assert_return(callback, -EINVAL);
         assert_return(e->state != SD_EVENT_FINISHED, -ESTALE);
         assert_return(!event_pid_changed(e), -ECHILD);
 
+        if (!callback)
+                callback = time_exit_callback;
+
         type = clock_to_event_source_type(clock);
         assert_return(type >= 0, -ENOTSUP);