install: use automatic cleanup in find_symlinks_fd()

parent e3ded78b
...@@ -375,7 +375,7 @@ static int find_symlinks_fd( ...@@ -375,7 +375,7 @@ static int find_symlinks_fd(
bool *same_name_link) { bool *same_name_link) {
int r = 0; int r = 0;
DIR *d; DIR _cleanup_closedir_ *d = NULL;
assert(name); assert(name);
assert(fd >= 0); assert(fd >= 0);
...@@ -395,13 +395,11 @@ static int find_symlinks_fd( ...@@ -395,13 +395,11 @@ static int find_symlinks_fd(
union dirent_storage buf; union dirent_storage buf;
k = readdir_r(d, &buf.de, &de); k = readdir_r(d, &buf.de, &de);
if (k != 0) { if (k != 0)
r = -errno; return -errno;
break;
}
if (!de) if (!de)
break; return r;
if (ignore_file(de->d_name)) if (ignore_file(de->d_name))
continue; continue;
...@@ -410,7 +408,7 @@ static int find_symlinks_fd( ...@@ -410,7 +408,7 @@ static int find_symlinks_fd(
if (de->d_type == DT_DIR) { if (de->d_type == DT_DIR) {
int nfd, q; int nfd, q;
char *p; char _cleanup_free_ *p = NULL;
nfd = openat(fd, de->d_name, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW); nfd = openat(fd, de->d_name, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW);
if (nfd < 0) { if (nfd < 0) {
...@@ -425,39 +423,31 @@ static int find_symlinks_fd( ...@@ -425,39 +423,31 @@ static int find_symlinks_fd(
p = path_make_absolute(de->d_name, path); p = path_make_absolute(de->d_name, path);
if (!p) { if (!p) {
close_nointr_nofail(nfd); close_nointr_nofail(nfd);
r = -ENOMEM; return -ENOMEM;
break;
} }
/* This will close nfd, regardless whether it succeeds or not */ /* This will close nfd, regardless whether it succeeds or not */
q = find_symlinks_fd(name, nfd, p, config_path, same_name_link); q = find_symlinks_fd(name, nfd, p, config_path, same_name_link);
free(p);
if (q > 0) { if (q > 0)
r = 1; return 1;
break;
}
if (r == 0) if (r == 0)
r = q; r = q;
} else if (de->d_type == DT_LNK) { } else if (de->d_type == DT_LNK) {
char *p, *dest; char _cleanup_free_ *p = NULL, *dest = NULL;
bool found_path, found_dest, b = false; bool found_path, found_dest, b = false;
int q; int q;
/* Acquire symlink name */ /* Acquire symlink name */
p = path_make_absolute(de->d_name, path); p = path_make_absolute(de->d_name, path);
if (!p) { if (!p)
r = -ENOMEM; return -ENOMEM;
break;
}
/* Acquire symlink destination */ /* Acquire symlink destination */
q = readlink_and_canonicalize(p, &dest); q = readlink_and_canonicalize(p, &dest);
if (q < 0) { if (q < 0) {
free(p);
if (q == -ENOENT) if (q == -ENOENT)
continue; continue;
...@@ -480,37 +470,25 @@ static int find_symlinks_fd( ...@@ -480,37 +470,25 @@ static int find_symlinks_fd(
else else
found_dest = streq(path_get_file_name(dest), name); found_dest = streq(path_get_file_name(dest), name);
free(dest);
if (found_path && found_dest) { if (found_path && found_dest) {
char *t; char _cleanup_free_ *t = NULL;
/* Filter out same name links in the main /* Filter out same name links in the main
* config path */ * config path */
t = path_make_absolute(name, config_path); t = path_make_absolute(name, config_path);
if (!t) { if (!t)
free(p); return -ENOMEM;
r = -ENOMEM;
break;
}
b = path_equal(t, p); b = path_equal(t, p);
free(t);
} }
free(p);
if (b) if (b)
*same_name_link = true; *same_name_link = true;
else if (found_path || found_dest) { else if (found_path || found_dest)
r = 1; return 1;
break;
}
} }
} }
closedir(d);
return r; return r;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment