+static void evloop_run(int signum, void *arg)
+{
+ int rc;
+ struct sd_event *se;
+ struct evloop *el = arg;
+
+ if (!signum) {
+ current_evloop = el;
+ __atomic_store_n(&el->state, EVLOOP_STATE_LOCK|EVLOOP_STATE_RUN|EVLOOP_STATE_WAIT, __ATOMIC_RELAXED);
+ se = el->sdev;
+ rc = sd_event_prepare(se);
+ if (rc < 0) {
+ errno = -rc;
+ ERROR("sd_event_prepare returned an error (state: %d): %m", sd_event_get_state(se));
+ } else {
+ if (rc == 0) {
+ rc = sd_event_wait(se, (uint64_t)(int64_t)-1);
+ if (rc < 0) {
+ errno = -rc;
+ ERROR("sd_event_wait returned an error (state: %d): %m", sd_event_get_state(se));
+ }
+ }
+ __atomic_and_fetch(&el->state, ~(EVLOOP_STATE_WAIT), __ATOMIC_RELAXED);
+
+ if (rc > 0) {
+ rc = sd_event_dispatch(se);
+ if (rc < 0) {
+ errno = -rc;
+ ERROR("sd_event_dispatch returned an error (state: %d): %m", sd_event_get_state(se));
+ }
+ }
+ }
+ }
+ __atomic_and_fetch(&el->state, ~(EVLOOP_STATE_WAIT|EVLOOP_STATE_RUN), __ATOMIC_RELAXED);
+}
+
+
+#if defined(REMOVE_SYSTEMD_EVENT)
+/**
+ * Monitored normal loop for waiting events.
+ * @param signum 0 on normal flow or the number
+ * of the signal that interrupted the normal
+ * flow
+ * @param arg the events to run
+ */
+static void monitored_wait_and_dispatch(int signum, void *arg)