static int is_symlink_with_known_name(const InstallInfo *i, const char *name) {
int r;
+ assert(i);
+ assert(name);
+
if (streq(name, i->name))
return true;
const char *config_path,
bool *same_name_link) {
- int r = 0;
+ int r, ret = 0;
+
+ assert(dir);
+ assert(dir_path);
+ assert(info);
+ assert(unit_name_is_valid(info->name, UNIT_NAME_ANY));
+ assert(config_path);
+ assert(same_name_link);
FOREACH_DIRENT(de, dir, return -errno) {
bool found_path = false, found_dest = false, b = false;
- int q;
if (de->d_type != DT_LNK)
continue;
_cleanup_free_ char *dest = NULL;
/* Acquire symlink destination */
- q = readlinkat_malloc(dirfd(dir), de->d_name, &dest);
- if (q == -ENOENT)
- continue;
- if (q < 0) {
- if (r == 0)
- r = q;
+ r = readlinkat_malloc(dirfd(dir), de->d_name, &dest);
+ if (r < 0) {
+ if (r != -ENOENT)
+ RET_GATHER(ret, r);
continue;
}
- /* Make absolute */
- if (!path_is_absolute(dest)) {
- char *x;
-
- x = path_join(dir_path, dest);
- if (!x)
- return -ENOMEM;
-
- free_and_replace(dest, x);
- }
-
/* Check if what the symlink points to matches what we are looking for */
- found_dest = streq(basename(dest), info->name);
+ found_dest = path_equal_filename(dest, info->name);
}
- assert(unit_name_is_valid(info->name, UNIT_NAME_ANY));
-
/* Check if the symlink itself matches what we are looking for.
*
* If ignore_destination is specified, we only look at the source name.
if (!found_path && ignore_destination) {
_cleanup_free_ char *template = NULL;
- q = unit_name_template(de->d_name, &template);
- if (q < 0 && q != -EINVAL)
- return q;
- if (q >= 0)
+ r = unit_name_template(de->d_name, &template);
+ if (r < 0 && r != -EINVAL)
+ return r;
+ if (r >= 0)
found_dest = streq(template, info->name);
}
/* Filter out same name links in the main config path */
p = path_make_absolute(de->d_name, dir_path);
t = path_make_absolute(info->name, config_path);
-
if (!p || !t)
return -ENOMEM;
return 1;
/* Check if symlink name is in the set of names used by [Install] */
- q = is_symlink_with_known_name(info, de->d_name);
- if (q < 0)
- return q;
- if (q > 0)
- return 1;
+ r = is_symlink_with_known_name(info, de->d_name);
+ if (r != 0)
+ return r;
}
}
- return r;
+ return ret;
}
static int find_symlinks(
bool *same_name_link) {
_cleanup_closedir_ DIR *config_dir = NULL;
- int r = 0;
+ int r;
assert(i);
assert(config_path);
same_name_link);
if (r > 0)
return 1;
- else if (r < 0)
+ if (r < 0)
log_debug_errno(r, "Failed to look up symlinks in \"%s\": %m", path);
}