X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Finstall.c;h=f30bf8317b802cb171193ec5f0ae6f862d48cf6c;hb=67445f4e22ad924394acdd4fd49e6f238244a5ca;hp=ef1c3f584d3a4d28c9c76eb4326d37070a31cdc8;hpb=29283ea4cf5df20aa0ea9e24e3cb7035bf4c4a04;p=elogind.git diff --git a/src/shared/install.c b/src/shared/install.c index ef1c3f584..f30bf8317 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -59,7 +59,7 @@ static int lookup_paths_init_from_scope(LookupPaths *paths, UnitFileScope scope) zero(*paths); return lookup_paths_init(paths, - scope == UNIT_FILE_SYSTEM ? MANAGER_SYSTEM : MANAGER_USER, + scope == UNIT_FILE_SYSTEM ? SYSTEMD_SYSTEM : SYSTEMD_USER, scope == UNIT_FILE_USER, NULL, NULL, NULL); } @@ -524,8 +524,11 @@ static int find_symlinks( assert(same_name_link); fd = open(config_path, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW); - if (fd < 0) + if (fd < 0) { + if (errno == ENOENT) + return 0; return -errno; + } /* This takes possession of fd and closes it */ return find_symlinks_fd(name, fd, config_path, config_path, same_name_link); @@ -538,7 +541,7 @@ static int find_symlinks_in_scope( UnitFileState *state) { int r; - char *path; + char _cleanup_free_ *path = NULL; bool same_name_link_runtime = false, same_name_link = false; assert(scope >= 0); @@ -553,8 +556,6 @@ static int find_symlinks_in_scope( return r; r = find_symlinks(name, path, &same_name_link_runtime); - free(path); - if (r < 0) return r; else if (r > 0) { @@ -569,8 +570,6 @@ static int find_symlinks_in_scope( return r; r = find_symlinks(name, path, &same_name_link); - free(path); - if (r < 0) return r; else if (r > 0) { @@ -600,7 +599,8 @@ int unit_file_mask( UnitFileChange **changes, unsigned *n_changes) { - char **i, *prefix; + char **i; + char _cleanup_free_ *prefix; int r; assert(scope >= 0); @@ -611,7 +611,7 @@ int unit_file_mask( return r; STRV_FOREACH(i, files) { - char *path; + char _cleanup_free_ *path = NULL; if (!unit_name_is_valid(*i, true)) { if (r == 0) @@ -628,16 +628,13 @@ int unit_file_mask( if (symlink("/dev/null", path) >= 0) { add_file_change(changes, n_changes, UNIT_FILE_SYMLINK, path, "/dev/null"); - free(path); continue; } if (errno == EEXIST) { - if (null_or_empty_path(path) > 0) { - free(path); + if (null_or_empty_path(path) > 0) continue; - } if (force) { unlink(path); @@ -647,7 +644,6 @@ int unit_file_mask( add_file_change(changes, n_changes, UNIT_FILE_UNLINK, path, NULL); add_file_change(changes, n_changes, UNIT_FILE_SYMLINK, path, "/dev/null"); - free(path); continue; } } @@ -658,12 +654,8 @@ int unit_file_mask( if (r == 0) r = -errno; } - - free(path); } - free(prefix); - return r; } @@ -2003,25 +1995,24 @@ int unit_file_get_list( free(f->path); free(f); goto finish; - } else if (r > 0) + } else if (r > 0) { + f->state = UNIT_FILE_ENABLED; goto found; + } r = unit_file_can_install(&paths, root_dir, f->path, true); - if (r < 0) { + if (r == -EINVAL || /* Invalid setting? */ + r == -EBADMSG || /* Invalid format? */ + r == -ENOENT /* Included file not found? */) + f->state = UNIT_FILE_INVALID; + else if (r < 0) { free(f->path); free(f); goto finish; - } else if (r > 0) { + } else if (r > 0) f->state = UNIT_FILE_DISABLED; - goto found; - } else { + else f->state = UNIT_FILE_STATIC; - goto found; - } - - free(f->path); - free(f); - continue; found: r = hashmap_put(h, path_get_file_name(f->path), f); @@ -2051,7 +2042,8 @@ static const char* const unit_file_state_table[_UNIT_FILE_STATE_MAX] = { [UNIT_FILE_MASKED] = "masked", [UNIT_FILE_MASKED_RUNTIME] = "masked-runtime", [UNIT_FILE_STATIC] = "static", - [UNIT_FILE_DISABLED] = "disabled" + [UNIT_FILE_DISABLED] = "disabled", + [UNIT_FILE_INVALID] = "invalid", }; DEFINE_STRING_TABLE_LOOKUP(unit_file_state, UnitFileState);