#include <sys/epoll.h>
#include <sys/timerfd.h>
#include <sys/wait.h>
-#include <pthread.h>
#include "sd-id128.h"
#include "sd-daemon.h"
#include "sd-event.h"
-#define EPOLL_QUEUE_MAX 512U
#define DEFAULT_ACCURACY_USEC (250 * USEC_PER_MSEC)
typedef enum EventSourceType {
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();
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,
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);
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)
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)
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,