summaryrefslogtreecommitdiff
path: root/unit.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-01-27 00:15:56 +0100
committerLennart Poettering <lennart@poettering.net>2010-01-27 00:15:56 +0100
commit0301abf48ed3be921c33d409c73b554435cf6378 (patch)
treea519dad97ab1eb945be1999c2892aa2fe25509c3 /unit.c
parent87f0e418cf2c58b3201d06a60e3696ec672d2662 (diff)
implement drop-in directories
Diffstat (limited to 'unit.c')
-rw-r--r--unit.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/unit.c b/unit.c
index 15401e24fe..c722717fe6 100644
--- a/unit.c
+++ b/unit.c
@@ -6,6 +6,8 @@
#include <sys/epoll.h>
#include <sys/timerfd.h>
#include <sys/poll.h>
+#include <stdlib.h>
+#include <unistd.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);
+ free(u->meta.load_path);
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)]);
+ 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);
@@ -805,3 +811,42 @@ int unit_add_dependency(Unit *u, UnitDependency d, Unit *other) {
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;
+}