X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Finstall.c;h=2c119e2dcad2b8697cf741c92aa6cdb9568640d6;hb=e8372f7e3e3a5aba053b1b5b944cb84d6d525877;hp=9722ed4e1c7df42057f02d58c940f2a68cfab5c6;hpb=19f6d710772305610b928bc2678b9d77fe11e770;p=elogind.git diff --git a/src/shared/install.c b/src/shared/install.c index 9722ed4e1..2c119e2dc 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -38,16 +38,14 @@ #include "conf-files.h" #include "specifier.h" #include "install-printf.h" +#include "special.h" typedef struct { Hashmap *will_install; Hashmap *have_installed; } InstallContext; -#define _cleanup_lookup_paths_free_ \ - __attribute__((cleanup(lookup_paths_free))) -#define _cleanup_install_context_done_ \ - __attribute__((cleanup(install_context_done))) +#define _cleanup_install_context_done_ _cleanup_(install_context_done) static int lookup_paths_init_from_scope(LookupPaths *paths, UnitFileScope scope) { assert(paths); @@ -1563,7 +1561,7 @@ int unit_file_reenable( int unit_file_set_default( UnitFileScope scope, const char *root_dir, - char *file, + const char *file, UnitFileChange **changes, unsigned *n_changes) { @@ -1576,6 +1574,7 @@ int unit_file_set_default( assert(scope >= 0); assert(scope < _UNIT_FILE_SCOPE_MAX); + assert(file); if (unit_name_to_type(file) != UNIT_TARGET) return -EINVAL; @@ -1592,13 +1591,14 @@ int unit_file_set_default( if (r < 0) return r; - i = (InstallInfo*)hashmap_first(c.will_install); + assert_se(i = hashmap_first(c.will_install)); r = unit_file_search(&c, i, &paths, root_dir, false); if (r < 0) return r; - path = strappenda(config_path, "/default.target"); + path = strappenda(config_path, "/" SPECIAL_DEFAULT_TARGET); + r = create_symlink(i->path, path, true, changes, n_changes); if (r < 0) return r; @@ -1615,17 +1615,22 @@ int unit_file_get_default( char **p; int r; + assert(scope >= 0); + assert(scope < _UNIT_FILE_SCOPE_MAX); + assert(name); + r = lookup_paths_init_from_scope(&paths, scope); if (r < 0) return r; STRV_FOREACH(p, paths.unit_path) { _cleanup_free_ char *path = NULL, *tmp = NULL; + char *n; if (isempty(root_dir)) - path = strappend(*p, "/default.target"); + path = strappend(*p, "/" SPECIAL_DEFAULT_TARGET); else - path = strjoin(root_dir, "/", *p, "/default.target", NULL); + path = strjoin(root_dir, "/", *p, "/" SPECIAL_DEFAULT_TARGET, NULL); if (!path) return -ENOMEM; @@ -1633,13 +1638,18 @@ int unit_file_get_default( r = readlink_malloc(path, &tmp); if (r == -ENOENT) continue; + else if (r == -EINVAL) + /* not a symlink */ + n = strdup(SPECIAL_DEFAULT_TARGET); else if (r < 0) return r; + else + n = strdup(path_get_file_name(tmp)); - *name = strdup(path_get_file_name(tmp)); - if (!*name) + if (!n) return -ENOMEM; + *name = n; return 0; } @@ -1874,6 +1884,7 @@ static void unitfilelist_free(UnitFileList **f) { free((*f)->path); free(*f); } +#define _cleanup_unitfilelist_free_ _cleanup_(unitfilelist_free) int unit_file_get_list( UnitFileScope scope, @@ -1925,8 +1936,7 @@ int unit_file_get_list( for (;;) { struct dirent *de; union dirent_storage buffer; - UnitFileList __attribute__((cleanup(unitfilelist_free))) - *f = NULL; + _cleanup_unitfilelist_free_ UnitFileList *f = NULL; r = readdir_r(d, &buffer.de, &de); if (r != 0)