chiark / gitweb /
sd-event: fix typo
[elogind.git] / src / libsystemd / sd-event / sd-event.c
index 993ef202def8467075faff57618704904d733f5d..a270849cd7d914a829bcd5076130a4937d8cf389 100644 (file)
@@ -22,7 +22,6 @@
 #include <sys/epoll.h>
 #include <sys/timerfd.h>
 #include <sys/wait.h>
-#include <pthread.h>
 
 #include "sd-id128.h"
 #include "sd-daemon.h"
@@ -37,7 +36,6 @@
 
 #include "sd-event.h"
 
-#define EPOLL_QUEUE_MAX 512U
 #define DEFAULT_ACCURACY_USEC (250 * USEC_PER_MSEC)
 
 typedef enum EventSourceType {
@@ -463,7 +461,7 @@ _public_ sd_event* sd_event_unref(sd_event *e) {
 static bool event_pid_changed(sd_event *e) {
         assert(e);
 
-        /* We don't support people creating am event loop and keeping
+        /* We don't support people creating an event loop and keeping
          * it around over a fork(). Let's complain. */
 
         return e->original_pid != getpid();
@@ -891,6 +889,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 +912,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);
 
@@ -2158,9 +2164,9 @@ static int source_dispatch(sd_event_source *s) {
 
         if (r < 0) {
                 if (s->description)
-                        log_debug_errno(-r, "Event source '%s' returned error, disabling: %m", s->description);
+                        log_debug_errno(r, "Event source '%s' returned error, disabling: %m", s->description);
                 else
-                        log_debug_errno(-r, "Event source %p returned error, disabling: %m", s);
+                        log_debug_errno(r, "Event source %p returned error, disabling: %m", s);
         }
 
         if (s->n_ref == 0)
@@ -2196,9 +2202,9 @@ static int event_prepare(sd_event *e) {
 
                 if (r < 0) {
                         if (s->description)
-                                log_debug_errno(-r, "Prepare callback of event source '%s' returned error, disabling: %m", s->description);
+                                log_debug_errno(r, "Prepare callback of event source '%s' returned error, disabling: %m", s->description);
                         else
-                                log_debug_errno(-r, "Prepare callback of event source %p returned error, disabling: %m", s);
+                                log_debug_errno(r, "Prepare callback of event source %p returned error, disabling: %m", s);
                 }
 
                 if (s->n_ref == 0)
@@ -2359,7 +2365,7 @@ _public_ int sd_event_wait(sd_event *e, uint64_t timeout) {
                 return 1;
         }
 
-        ev_queue_max = CLAMP(e->n_sources, 1U, EPOLL_QUEUE_MAX);
+        ev_queue_max = MAX(e->n_sources, 1u);
         ev_queue = newa(struct epoll_event, ev_queue_max);
 
         m = epoll_wait(e->epoll_fd, ev_queue, ev_queue_max,