chiark / gitweb /
manager: add basic support for loading name fragment files
authorLennart Poettering <lennart@poettering.net>
Thu, 19 Nov 2009 01:52:17 +0000 (02:52 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 19 Nov 2009 01:52:17 +0000 (02:52 +0100)
Makefile
manager.c
manager.h

index 6f41e8878cc9c5039c607f9fc4d05a0afeb0919e..45123a8b302c0b4c99565f955bc1e0bb77d63e8f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 CFLAGS=-Wall -Wextra -O0 -g -pipe -D_GNU_SOURCE -fdiagnostics-show-option -Wno-unused-parameter
 LIBS=-lrt
 
 CFLAGS=-Wall -Wextra -O0 -g -pipe -D_GNU_SOURCE -fdiagnostics-show-option -Wno-unused-parameter
 LIBS=-lrt
 
-systemd: main.o name.o util.o set.o hashmap.o strv.o job.o manager.o conf-parser.o
+systemd: main.o name.o util.o set.o hashmap.o strv.o job.o manager.o conf-parser.o load-fragment.o
        $(CC) $(CFLAGS) -o $@ $^  $(LIBS)
 
 clean:
        $(CC) $(CFLAGS) -o $@ $^  $(LIBS)
 
 clean:
index d6bc35a289d04034f8fe275a1400f0b5ebd20184..97c99e50465538f100b39f46c4a53cce70956c3a 100644 (file)
--- a/manager.c
+++ b/manager.c
@@ -7,6 +7,7 @@
 #include "hashmap.h"
 #include "macro.h"
 #include "strv.h"
 #include "hashmap.h"
 #include "macro.h"
 #include "strv.h"
+#include "load-fragment.h"
 
 Manager* manager_new(void) {
         Manager *m;
 
 Manager* manager_new(void) {
         Manager *m;
@@ -166,27 +167,20 @@ static int detect_type(Name *name) {
         return 0;
 }
 
         return 0;
 }
 
-static int fragment_load(Name *n) {
-        assert(n);
-
-        /*... */
-
-        return 0;
-}
-
-static int sysv_load(Service *s) {
+static int service_load_sysv(Service *s) {
         assert(s);
 
         assert(s);
 
-        /*... */
+        /* Load service data from SysV init scripts, preferably with
+         * LSB headers ... */
 
         return 0;
 }
 
 
         return 0;
 }
 
-static int fstab_load(Name *n) {
+static int name_load_fstab(Name *n) {
         assert(n);
         assert(n->meta.type == NAME_MOUNT || n->meta.type == NAME_AUTOMOUNT);
 
         assert(n);
         assert(n->meta.type == NAME_MOUNT || n->meta.type == NAME_AUTOMOUNT);
 
-        /*... */
+        /* Load mount data from /etc/fstab */
 
         return 0;
 }
 
         return 0;
 }
@@ -194,7 +188,15 @@ static int fstab_load(Name *n) {
 static int snapshot_load(Snapshot *s) {
         assert(s);
 
 static int snapshot_load(Snapshot *s) {
         assert(s);
 
-        /*... */
+        /* Load snapshots from disk */
+
+        return 0;
+}
+
+static int name_load_dropin(Name *n) {
+        assert(n);
+
+        /* Load dependencies from drop-in directories */
 
         return 0;
 }
 
         return 0;
 }
@@ -213,18 +215,18 @@ static int load(Name *name) {
         if (name->meta.type == NAME_SERVICE) {
 
                 /* Load a .service file */
         if (name->meta.type == NAME_SERVICE) {
 
                 /* Load a .service file */
-                if ((r = fragment_load(name)) == 0)
+                if ((r = name_load_fragment(name)) == 0)
                         goto finish;
 
                 /* Load a classic init script */
                 if (r == -ENOENT)
                         goto finish;
 
                 /* Load a classic init script */
                 if (r == -ENOENT)
-                        if ((r = sysv_load(SERVICE(name))) == 0)
+                        if ((r = service_load_sysv(SERVICE(name))) == 0)
                                 goto finish;
 
         } else if (name->meta.type == NAME_MOUNT ||
                    name->meta.type == NAME_AUTOMOUNT) {
 
                                 goto finish;
 
         } else if (name->meta.type == NAME_MOUNT ||
                    name->meta.type == NAME_AUTOMOUNT) {
 
-                if ((r = fstab_load(name)) == 0)
+                if ((r = name_load_fstab(name)) == 0)
                         goto finish;
 
         } else if (name->meta.type == NAME_SNAPSHOT) {
                         goto finish;
 
         } else if (name->meta.type == NAME_SNAPSHOT) {
@@ -233,7 +235,7 @@ static int load(Name *name) {
                         goto finish;
 
         } else {
                         goto finish;
 
         } else {
-                if ((r = fragment_load(name)) == 0)
+                if ((r = name_load_fragment(name)) == 0)
                         goto finish;
         }
 
                         goto finish;
         }
 
@@ -241,6 +243,9 @@ static int load(Name *name) {
         return r;
 
 finish:
         return r;
 
 finish:
+        if ((r = name_load_dropin(name)) < 0)
+                return r;
+
         name->meta.state = NAME_LOADED;
         return 0;
 }
         name->meta.state = NAME_LOADED;
         return 0;
 }
@@ -250,6 +255,12 @@ static int dispatch_load_queue(Manager *m) {
 
         assert(m);
 
 
         assert(m);
 
+        /* Make sure we are not run recursively */
+        if (m->dispatching_load_queue)
+                return 0;
+
+        m->dispatching_load_queue = true;
+
         /* Dispatches the load queue. Takes a name from the queue and
          * tries to load its data until the queue is empty */
 
         /* Dispatches the load queue. Takes a name from the queue and
          * tries to load its data until the queue is empty */
 
@@ -258,11 +269,11 @@ static int dispatch_load_queue(Manager *m) {
                 LIST_REMOVE(Meta, m->load_queue, meta);
         }
 
                 LIST_REMOVE(Meta, m->load_queue, meta);
         }
 
+        m->dispatching_load_queue = false;
+
         return 0;
 }
 
         return 0;
 }
 
-
-
 int manager_load_name(Manager *m, const char *name, Name **_ret) {
         Name *ret;
         NameType t;
 int manager_load_name(Manager *m, const char *name, Name **_ret) {
         Name *ret;
         NameType t;
@@ -271,9 +282,12 @@ int manager_load_name(Manager *m, const char *name, Name **_ret) {
         assert(m);
         assert(name);
         assert(_ret);
         assert(m);
         assert(name);
         assert(_ret);
-/* This will load the service information files, but not actually
- * start any services or anything */
 
 
+        if (!name_is_valid(name))
+                return -EINVAL;
+
+        /* This will load the service information files, but not actually
+         * start any services or anything */
 
         if ((ret = manager_get_name(m, name)))
                 goto finish;
 
         if ((ret = manager_get_name(m, name)))
                 goto finish;
index 53cacdfb2e9d8ccab896ac7fcc9a7135c777e807..9cd131d5adb5eb87bda2837878d03e3e31923d2b 100644 (file)
--- a/manager.h
+++ b/manager.h
@@ -27,6 +27,8 @@ struct Manager {
         /* Jobs to be added resp. removed. */
         Hashmap *jobs_to_add;  /* Name object => Job object 1:1 */
         Set *jobs_to_remove;
         /* Jobs to be added resp. removed. */
         Hashmap *jobs_to_add;  /* Name object => Job object 1:1 */
         Set *jobs_to_remove;
+
+        bool dispatching_load_queue:1;
 };
 
 Manager* manager_new(void);
 };
 
 Manager* manager_new(void);