core: only set event source name when we create an event source
authorLennart Poettering <lennart@poettering.net>
Wed, 13 May 2015 16:30:14 +0000 (18:30 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 13 May 2015 16:30:14 +0000 (18:30 +0200)
src/core/busname.c
src/core/scope.c
src/core/socket.c
src/core/timer.c

index eb95c8e..17b8513 100644 (file)
@@ -287,20 +287,24 @@ static int busname_watch_fd(BusName *n) {
         if (n->starter_fd < 0)
                 return 0;
 
-        if (n->starter_event_source)
+        if (n->starter_event_source) {
                 r = sd_event_source_set_enabled(n->starter_event_source, SD_EVENT_ON);
-        else
+                if (r < 0)
+                        goto fail;
+        } else {
                 r = sd_event_add_io(UNIT(n)->manager->event, &n->starter_event_source, n->starter_fd, EPOLLIN, busname_dispatch_io, n);
+                if (r < 0)
+                        goto fail;
 
-        if (r < 0) {
-                log_unit_warning_errno(UNIT(n), r, "Failed to watch starter fd: %m");
-                busname_unwatch_fd(n);
-                return r;
+                (void) sd_event_source_set_description(n->starter_event_source, "busname-starter");
         }
 
-        (void) sd_event_source_set_description(n->starter_event_source, "busname-starter");
-
         return 0;
+
+fail:
+        log_unit_warning_errno(UNIT(n), r, "Failed to watch starter fd: %m");
+        busname_unwatch_fd(n);
+        return r;
 }
 
 static int busname_open_fd(BusName *n) {
index 9ab54ee..ab1769b 100644 (file)
@@ -81,7 +81,7 @@ static int scope_arm_timer(Scope *s) {
                 return sd_event_source_set_enabled(s->timer_event_source, SD_EVENT_ONESHOT);
         }
 
-        r =  sd_event_add_time(
+        r = sd_event_add_time(
                         UNIT(s)->manager->event,
                         &s->timer_event_source,
                         CLOCK_MONOTONIC,
index a655ec9..17b8a50 100644 (file)
@@ -1268,22 +1268,23 @@ static int socket_watch_fds(Socket *s) {
                 if (p->fd < 0)
                         continue;
 
-                if (p->event_source)
+                if (p->event_source) {
                         r = sd_event_source_set_enabled(p->event_source, SD_EVENT_ON);
-                else
+                        if (r < 0)
+                                goto fail;
+                } else {
                         r = sd_event_add_io(UNIT(s)->manager->event, &p->event_source, p->fd, EPOLLIN, socket_dispatch_io, p);
+                        if (r < 0)
+                                goto fail;
 
-                if (r < 0) {
-                        log_unit_warning_errno(UNIT(s), r, "Failed to watch listening fds: %m");
-                        goto fail;
+                        (void) sd_event_source_set_description(p->event_source, "socket-port-io");
                 }
-
-                (void) sd_event_source_set_description(p->event_source, "socket-port-io");
         }
 
         return 0;
 
 fail:
+        log_unit_warning_errno(UNIT(s), r, "Failed to watch listening fds: %m");
         socket_unwatch_fds(s);
         return r;
 }
index d427956..7f4a2eb 100644 (file)
@@ -429,17 +429,21 @@ static void timer_enter_waiting(Timer *t, bool initial) {
                                 goto fail;
 
                         r = sd_event_source_set_enabled(t->monotonic_event_source, SD_EVENT_ONESHOT);
-                } else
+                        if (r < 0)
+                                goto fail;
+                } else {
+
                         r = sd_event_add_time(
                                         UNIT(t)->manager->event,
                                         &t->monotonic_event_source,
                                         t->wake_system ? CLOCK_BOOTTIME_ALARM : CLOCK_MONOTONIC,
                                         t->next_elapse_monotonic_or_boottime, t->accuracy_usec,
                                         timer_dispatch, t);
-                if (r < 0)
-                        goto fail;
+                        if (r < 0)
+                                goto fail;
 
-                (void) sd_event_source_set_description(t->monotonic_event_source, "timer-monotonic");
+                        (void) sd_event_source_set_description(t->monotonic_event_source, "timer-monotonic");
+                }
 
         } else if (t->monotonic_event_source) {
 
@@ -458,17 +462,20 @@ static void timer_enter_waiting(Timer *t, bool initial) {
                                 goto fail;
 
                         r = sd_event_source_set_enabled(t->realtime_event_source, SD_EVENT_ONESHOT);
-                } else
+                        if (r < 0)
+                                goto fail;
+                } else {
                         r = sd_event_add_time(
                                         UNIT(t)->manager->event,
                                         &t->realtime_event_source,
                                         t->wake_system ? CLOCK_REALTIME_ALARM : CLOCK_REALTIME,
                                         t->next_elapse_realtime, t->accuracy_usec,
                                         timer_dispatch, t);
-                if (r < 0)
-                        goto fail;
+                        if (r < 0)
+                                goto fail;
 
-                (void) sd_event_source_set_description(t->realtime_event_source, "timer-realtime");
+                        (void) sd_event_source_set_description(t->realtime_event_source, "timer-realtime");
+                }
 
         } else if (t->realtime_event_source) {