chiark / gitweb /
implement drop-in directories
[elogind.git] / unit.c
diff --git a/unit.c b/unit.c
index 15401e2..c722717 100644 (file)
--- a/unit.c
+++ b/unit.c
@@ -6,6 +6,8 @@
 #include <sys/epoll.h>
 #include <sys/timerfd.h>
 #include <sys/poll.h>
 #include <sys/epoll.h>
 #include <sys/timerfd.h>
 #include <sys/poll.h>
+#include <stdlib.h>
+#include <unistd.h>
 
 #include "set.h"
 #include "unit.h"
 
 #include "set.h"
 #include "unit.h"
@@ -206,6 +208,7 @@ void unit_free(Unit *u) {
                 bidi_set_free(u, u->meta.dependencies[d]);
 
         free(u->meta.description);
                 bidi_set_free(u, u->meta.dependencies[d]);
 
         free(u->meta.description);
+        free(u->meta.load_path);
 
         while ((t = set_steal_first(u->meta.names)))
                 free(t);
 
         while ((t = set_steal_first(u->meta.names)))
                 free(t);
@@ -338,6 +341,9 @@ void unit_dump(Unit *u, FILE *f, const char *prefix) {
                 prefix, load_state_table[u->meta.load_state],
                 prefix, active_state_table[unit_active_state(u)]);
 
                 prefix, load_state_table[u->meta.load_state],
                 prefix, active_state_table[unit_active_state(u)]);
 
+        if (u->meta.load_path)
+                fprintf(f, "%s\tLoad Path: %s\n", prefix, u->meta.load_path);
+
         SET_FOREACH(t, u->meta.names, i)
                 fprintf(f, "%s\tName: %s\n", prefix, t);
 
         SET_FOREACH(t, u->meta.names, i)
                 fprintf(f, "%s\tName: %s\n", prefix, t);
 
@@ -805,3 +811,42 @@ int unit_add_dependency(Unit *u, UnitDependency d, Unit *other) {
 
         return 0;
 }
 
         return 0;
 }
+
+const char *unit_path(void) {
+        char *e;
+
+        if ((e = getenv("UNIT_PATH")))
+                if (path_is_absolute(e))
+                    return e;
+
+        return UNIT_PATH;
+}
+
+int set_unit_path(const char *p) {
+        char *cwd, *c;
+        int r;
+
+        /* This is mostly for debug purposes */
+
+        if (path_is_absolute(p)) {
+                if (!(c = strdup(p)))
+                        return -ENOMEM;
+        } else {
+                if (!(cwd = get_current_dir_name()))
+                        return -errno;
+
+                r = asprintf(&c, "%s/%s", cwd, p);
+                free(cwd);
+
+                if (r < 0)
+                        return -ENOMEM;
+        }
+
+        if (setenv("UNIT_PATH", c, 0) < 0) {
+                r = -errno;
+                free(c);
+                return r;
+        }
+
+        return 0;
+}