]> err.no Git - systemd/commitdiff
rework config file load logic
authorLennart Poettering <lennart@poettering.net>
Thu, 28 Jan 2010 01:44:47 +0000 (02:44 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 28 Jan 2010 01:44:47 +0000 (02:44 +0100)
automount.c
load-fragment.c
main.c
mount.c
service.c
socket.c
target.c
timer.c
unit.c

index 7b397c9b9bfbd73b89d36806b9317aeb3b1300f9..eb9c3d3c1d3071d2ed95e0e09d95afca5227c45b 100644 (file)
@@ -17,7 +17,7 @@ static int automount_init(Unit *u) {
         exec_context_init(&a->exec_context);
 
         /* Load a .automount file */
-        if ((r = unit_load_fragment(u)) < 0 && errno != -ENOENT)
+        if ((r = unit_load_fragment(u)) < 0)
                 return r;
 
         /* Load entry from /etc/fstab */
index 2757506aba0d309f39fc737d2ea0b3fd30ba98da..9273fc8b83dceed7f71b8d99d47e2e8ca7b737c7 100644 (file)
@@ -824,7 +824,7 @@ finish:
 }
 
 int unit_load_fragment(Unit *u) {
-        int r = -ENOENT;
+        int r = 0;
         ExecContext *c;
 
         assert(u);
@@ -851,14 +851,16 @@ int unit_load_fragment(Unit *u) {
 
         if (r >= 0 && c &&
             (c->output == EXEC_KERNEL || c->output == EXEC_SYSLOG)) {
+                int k;
+
                 /* If syslog or kernel logging is requested, make sure
                  * our own logging daemon is run first. */
 
-                if ((r = unit_add_dependency(u, UNIT_AFTER, u->meta.manager->special_units[SPECIAL_LOGGER_SOCKET])) < 0)
-                        return r;
+                if ((k = unit_add_dependency(u, UNIT_AFTER, u->meta.manager->special_units[SPECIAL_LOGGER_SOCKET])) < 0)
+                        return k;
 
-                if ((r = unit_add_dependency(u, UNIT_REQUIRES, u->meta.manager->special_units[SPECIAL_LOGGER_SOCKET])) < 0)
-                        return r;
+                if ((k = unit_add_dependency(u, UNIT_REQUIRES, u->meta.manager->special_units[SPECIAL_LOGGER_SOCKET])) < 0)
+                        return k;
         }
 
         return r;
diff --git a/main.c b/main.c
index 624a73e1783c9e2fbebef353db35dc107c5cc6a6..2486f06292144d4e4ea941c18cf826e731bcc701 100644 (file)
--- a/main.c
+++ b/main.c
@@ -26,14 +26,14 @@ int main(int argc, char *argv[]) {
                 goto finish;
         }
 
+        printf("→ By units:\n");
+        manager_dump_units(m, stdout, "\t");
+
         if ((r = manager_add_job(m, JOB_START, target, JOB_REPLACE, false, &job)) < 0) {
                 log_error("Failed to start default target: %s", strerror(-r));
                 goto finish;
         }
 
-        printf("→ By units:\n");
-        manager_dump_units(m, stdout, "\t");
-
         printf("→ By jobs:\n");
         manager_dump_jobs(m, stdout, "\t");
 
diff --git a/mount.c b/mount.c
index f4a6d6f2469ce94ee17e7b9271759132b03f6722..7a1ec087e7a5f6e20bf2384c6577660736d54d22 100644 (file)
--- a/mount.c
+++ b/mount.c
@@ -15,7 +15,7 @@ static int mount_init(Unit *u) {
         assert(m);
 
         /* Load a .mount file */
-        if ((r = unit_load_fragment(u)) < 0 && errno != -ENOENT)
+        if ((r = unit_load_fragment(u)) < 0)
                 return r;
 
         /* Load entry from /etc/fstab */
index 1cbfb3dcebdc2db9db6204573a0bae4db2d76e41..70299dd065f472d1f0a52435b982f41d8632a990 100644 (file)
--- a/service.c
+++ b/service.c
@@ -101,17 +101,18 @@ static int service_init(Unit *u) {
         s->state = SERVICE_DEAD;
 
         /* Load a .service file */
-        r = unit_load_fragment(u);
-
-        /* Load a classic init script as a fallback */
-        if (r == -ENOENT)
-                r = service_load_sysv(s);
-
-        if (r < 0) {
+        if ((r = unit_load_fragment(u)) < 0) {
                 service_done(u);
                 return r;
         }
 
+        /* Load a classic init script as a fallback, if we couldn*t find anything */
+        if (r == 0)
+                if ((r = service_load_sysv(s)) <= 0) {
+                        service_done(u);
+                        return r < 0 ? r : -ENOENT;
+                }
+
         /* Load dropin directory data */
         if ((r = unit_load_dropin(u)) < 0) {
                 service_done(u);
index 7bcd112739c36f5261bb77e961beb960f63998b4..926a0fb646d8dddfefc53458c46a792a4bfcde2c 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -88,8 +88,11 @@ static int socket_init(Unit *u) {
         s->timeout_usec = DEFAULT_TIMEOUT_USEC;
         exec_context_init(&s->exec_context);
 
-        if ((r = unit_load_fragment_and_dropin(u)) < 0)
+        if ((r = unit_load_fragment_and_dropin(u)) <= 0) {
+                if (r == 0)
+                        r = -ENOENT;
                 goto fail;
+        }
 
         if (!(t = unit_name_change_suffix(unit_id(u), ".service"))) {
                 r = -ENOMEM;
index 748dfeef1a281be946622f05db07aada1454223d..03f092e35c112fe8afa81245c272632b4df31b50 100644 (file)
--- a/target.c
+++ b/target.c
@@ -1,5 +1,7 @@
 /*-*- Mode: C; c-basic-offset: 8 -*-*/
 
+#include <errno.h>
+
 #include "unit.h"
 #include "target.h"
 #include "load-fragment.h"
@@ -15,6 +17,18 @@ static const char* const state_string_table[_TARGET_STATE_MAX] = {
         [TARGET_ACTIVE] = "active"
 };
 
+static int target_init(Unit *u) {
+        int r;
+        assert(u);
+
+        /* Make sure this config file actually exists */
+
+        if ((r = unit_load_fragment_and_dropin(u)) <= 0)
+                return r < 0 ? r : -ENOENT;
+
+        return 0;
+}
+
 static void target_dump(Unit *u, FILE *f, const char *prefix) {
         Target *t = TARGET(u);
 
@@ -67,7 +81,7 @@ static UnitActiveState target_active_state(Unit *u) {
 const UnitVTable target_vtable = {
         .suffix = ".target",
 
-        .init = unit_load_fragment_and_dropin,
+        .init = target_init,
 
         .dump = target_dump,
 
diff --git a/timer.c b/timer.c
index 29346204f808a7a4927bf78f9911b6a32b77a16b..c3ebba0d1ba80220cfd97112bd91cdee6c21a7b7 100644 (file)
--- a/timer.c
+++ b/timer.c
@@ -1,5 +1,7 @@
 /*-*- Mode: C; c-basic-offset: 8 -*-*/
 
+#include <errno.h>
+
 #include "unit.h"
 #include "timer.h"
 
@@ -9,6 +11,19 @@ static void timer_done(Unit *u) {
         assert(t);
 }
 
+static int timer_init(Unit *u) {
+        int r;
+
+        assert(u);
+
+        /* Make sure this config file actually exists */
+
+        if ((r = unit_load_fragment_and_dropin(u)) <= 0)
+                return r < 0 ? r : -ENOENT;
+
+        return 0;
+}
+
 static UnitActiveState timer_active_state(Unit *u) {
 
         static const UnitActiveState table[_TIMER_STATE_MAX] = {
@@ -23,7 +38,7 @@ static UnitActiveState timer_active_state(Unit *u) {
 const UnitVTable timer_vtable = {
         .suffix = ".timer",
 
-        .init = unit_load_fragment_and_dropin,
+        .init = timer_init,
         .done = timer_done,
 
         .active_state = timer_active_state
diff --git a/unit.c b/unit.c
index 88615319d7c28ee64e1db4a84abe0836c5ebddd9..40761209202455c2efe3056843f077c84771c83a 100644 (file)
--- a/unit.c
+++ b/unit.c
@@ -372,7 +372,7 @@ void unit_dump(Unit *u, FILE *f, const char *prefix) {
 
 /* Common implementation for multiple backends */
 int unit_load_fragment_and_dropin(Unit *u) {
-        int r;
+        int r, ret;
 
         assert(u);
 
@@ -380,11 +380,13 @@ int unit_load_fragment_and_dropin(Unit *u) {
         if ((r = unit_load_fragment(u)) < 0)
                 return r;
 
+        ret = r > 0;
+
         /* Load drop-in directory data */
         if ((r = unit_load_dropin(u)) < 0)
                 return r;
 
-        return 0;
+        return ret;
 }
 
 int unit_load(Unit *u) {