chiark / gitweb /
manager: introduce watch_init() initializer for watches
authorLennart Poettering <lennart@poettering.net>
Wed, 21 Nov 2012 23:38:55 +0000 (00:38 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 21 Nov 2012 23:45:22 +0000 (00:45 +0100)
src/core/manager.c
src/core/manager.h
src/core/service.c
src/core/unit.c

index f932c79..72ce2f2 100644 (file)
@@ -1363,7 +1363,8 @@ static int process_event(Manager *m, struct epoll_event *ev) {
                 ssize_t k;
 
                 /* Some timer event, to be dispatched to the units */
-                if ((k = read(w->fd, &v, sizeof(v))) != sizeof(v)) {
+                k = read(w->fd, &v, sizeof(v));
+                if (k != sizeof(v)) {
 
                         if (k < 0 && (errno == EINTR || errno == EAGAIN))
                                 break;
@@ -2307,3 +2308,10 @@ bool manager_get_show_status(Manager *m) {
 
         return plymouth_running();
 }
+
+void watch_init(Watch *w) {
+        assert(w);
+
+        w->type = WATCH_INVALID;
+        w->fd = -1;
+}
index 2214502..1644bd6 100644 (file)
@@ -291,3 +291,5 @@ void manager_recheck_journal(Manager *m);
 
 void manager_set_show_status(Manager *m, bool b);
 bool manager_get_show_status(Manager *m);
+
+void watch_init(Watch *w);
index aad6d66..34d24ff 100644 (file)
@@ -127,9 +127,9 @@ static void service_init(Unit *u) {
         s->restart_usec = DEFAULT_RESTART_USEC;
         s->type = _SERVICE_TYPE_INVALID;
 
-        s->watchdog_watch.type = WATCH_INVALID;
+        watch_init(&s->watchdog_watch);
+        watch_init(&s->timer_watch);
 
-        s->timer_watch.type = WATCH_INVALID;
 #ifdef HAVE_SYSV_COMPAT
         s->sysv_start_priority = -1;
         s->sysv_start_priority_from_rcnd = -1;
index 99e1c27..82dd617 100644 (file)
@@ -1580,7 +1580,8 @@ int unit_watch_timer(Unit *u, usec_t delay, Watch *w) {
         } else if (w->type == WATCH_INVALID) {
 
                 ours = true;
-                if ((fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK|TFD_CLOEXEC)) < 0)
+                fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK|TFD_CLOEXEC);
+                if (fd < 0)
                         return -errno;
         } else
                 assert_not_reached("Invalid watch type");