X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Finstall.c;h=fa064c230fdeb98de6e06bc8fb1340ae5a834a42;hb=aa08982d62cf45b59ea6a06c915391f5db1fb86e;hp=4b09a69456fd71fab4bf9c7bb113607d3747c9e2;hpb=59ccf93d97f0a37522e5f4fbf5cc0288dbedf495;p=elogind.git diff --git a/src/shared/install.c b/src/shared/install.c index 4b09a6945..fa064c230 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -105,10 +105,14 @@ static int get_config_path(UnitFileScope scope, bool runtime, const char *root_d case UNIT_FILE_USER: - if (root_dir || runtime) + if (root_dir) return -EINVAL; - r = user_config_home(&p); + if (runtime) + r = user_runtime_dir(&p); + else + r = user_config_home(&p); + if (r <= 0) return r < 0 ? r : -ENOENT; @@ -179,7 +183,7 @@ static int mark_symlink_for_removal( assert(p); - r = set_ensure_allocated(remove_symlinks_to, string_hash_func, string_compare_func); + r = set_ensure_allocated(remove_symlinks_to, &string_hash_ops); if (r < 0) return r; @@ -527,36 +531,33 @@ static int find_symlinks_in_scope( UnitFileState *state) { int r; - _cleanup_free_ char *path2 = NULL; + _cleanup_free_ char *path = NULL; bool same_name_link_runtime = false, same_name_link = false; assert(scope >= 0); assert(scope < _UNIT_FILE_SCOPE_MAX); assert(name); - if (scope == UNIT_FILE_SYSTEM || scope == UNIT_FILE_GLOBAL) { - _cleanup_free_ char *path = NULL; - /* First look in runtime config path */ - r = get_config_path(scope, true, root_dir, &path); - if (r < 0) - return r; + /* First look in runtime config path */ + r = get_config_path(scope, true, root_dir, &path); + if (r < 0) + return r; - r = find_symlinks(name, path, &same_name_link_runtime); - if (r < 0) - return r; - else if (r > 0) { - *state = UNIT_FILE_ENABLED_RUNTIME; - return r; - } + r = find_symlinks(name, path, &same_name_link_runtime); + if (r < 0) + return r; + else if (r > 0) { + *state = UNIT_FILE_ENABLED_RUNTIME; + return r; } /* Then look in the normal config path */ - r = get_config_path(scope, false, root_dir, &path2); + r = get_config_path(scope, false, root_dir, &path); if (r < 0) return r; - r = find_symlinks(name, path2, &same_name_link); + r = find_symlinks(name, path, &same_name_link); if (r < 0) return r; else if (r > 0) { @@ -884,7 +885,7 @@ static int install_info_add( hashmap_get(c->will_install, name)) return 0; - r = hashmap_ensure_allocated(&c->will_install, string_hash_func, string_compare_func); + r = hashmap_ensure_allocated(&c->will_install, &string_hash_ops); if (r < 0) return r; @@ -1025,8 +1026,10 @@ static int config_parse_default_instance( if (r < 0) return r; - if (!unit_instance_is_valid(printed)) + if (!unit_instance_is_valid(printed)) { + free(printed); return -EINVAL; + } free(i->default_instance); i->default_instance = printed; @@ -1393,7 +1396,7 @@ static int install_context_apply( while ((i = hashmap_first(c->will_install))) { - q = hashmap_ensure_allocated(&c->have_installed, string_hash_func, string_compare_func); + q = hashmap_ensure_allocated(&c->have_installed, &string_hash_ops); if (q < 0) return q; @@ -1434,7 +1437,7 @@ static int install_context_mark_for_removal( while ((i = hashmap_first(c->will_install))) { - q = hashmap_ensure_allocated(&c->have_installed, string_hash_func, string_compare_func); + q = hashmap_ensure_allocated(&c->have_installed, &string_hash_ops); if (q < 0) return q; @@ -2072,6 +2075,7 @@ int unit_file_get_list( for (;;) { _cleanup_(unit_file_list_free_onep) UnitFileList *f = NULL; struct dirent *de; + _cleanup_free_ char *path = NULL; errno = 0; de = readdir(d); @@ -2121,7 +2125,11 @@ int unit_file_get_list( goto found; } - r = unit_file_can_install(&paths, root_dir, f->path, true); + path = path_make_absolute(de->d_name, *i); + if (!path) + return -ENOMEM; + + r = unit_file_can_install(&paths, root_dir, path, true); if (r == -EINVAL || /* Invalid setting? */ r == -EBADMSG || /* Invalid format? */ r == -ENOENT /* Included file not found? */)