X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=unit.c;h=c722717fe66045b411fd1da243e50aa35f38bc5e;hp=15401e24fe0660cd3540b146e00b84ffcf439715;hb=0301abf48ed3be921c33d409c73b554435cf6378;hpb=87f0e418cf2c58b3201d06a60e3696ec672d2662 diff --git a/unit.c b/unit.c index 15401e24f..c722717fe 100644 --- a/unit.c +++ b/unit.c @@ -6,6 +6,8 @@ #include #include #include +#include +#include #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; +}