Skip to content

Commit 6c14211

Browse files
YHNdnzjbluca
authored andcommitted
various: correct laccess() error check
laccess is our own macro that uses RET_NERRNO. (cherry picked from commit 7c1dd9e) (cherry picked from commit 4296a56) (cherry picked from commit 9cf6035) (cherry picked from commit 8770e09)
1 parent d3683ff commit 6c14211

File tree

8 files changed

+36
-31
lines changed

8 files changed

+36
-31
lines changed

src/basic/os-util.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ int path_is_extension_tree(const char *path, const char *extension, bool relax_e
4444
/* Does the path exist at all? If not, generate an error immediately. This is useful so that a missing root dir
4545
* always results in -ENOENT, and we can properly distinguish the case where the whole root doesn't exist from
4646
* the case where just the os-release file is missing. */
47-
if (laccess(path, F_OK) < 0)
48-
return -errno;
47+
r = laccess(path, F_OK);
48+
if (r < 0)
49+
return r;
4950

5051
/* We use /usr/lib/extension-release.d/extension-release[.NAME] as flag for something being a system extension,
5152
* and {/etc|/usr/lib}/os-release as a flag for something being an OS (when not an extension). */

src/basic/path-lookup.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,7 @@ char **env_generator_binary_paths(bool is_system) {
881881

882882
int find_portable_profile(const char *name, const char *unit, char **ret_path) {
883883
const char *dot;
884+
int r;
884885

885886
assert(name);
886887
assert(ret_path);
@@ -894,13 +895,13 @@ int find_portable_profile(const char *name, const char *unit, char **ret_path) {
894895
if (!joined)
895896
return -ENOMEM;
896897

897-
if (laccess(joined, F_OK) >= 0) {
898+
r = laccess(joined, F_OK);
899+
if (r >= 0) {
898900
*ret_path = TAKE_PTR(joined);
899901
return 0;
900902
}
901-
902-
if (errno != ENOENT)
903-
return -errno;
903+
if (r != -ENOENT)
904+
return r;
904905
}
905906

906907
return -ENOENT;

src/home/homework-luks.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,11 +1992,11 @@ static int wait_for_devlink(const char *path) {
19921992
_cleanup_free_ char *dn = NULL;
19931993
usec_t w;
19941994

1995-
if (laccess(path, F_OK) < 0) {
1996-
if (errno != ENOENT)
1997-
return log_error_errno(errno, "Failed to determine whether %s exists: %m", path);
1998-
} else
1995+
r = laccess(path, F_OK);
1996+
if (r >= 0)
19991997
return 0; /* Found it */
1998+
if (r != -ENOENT)
1999+
return log_error_errno(r, "Failed to determine whether %s exists: %m", path);
20002000

20012001
if (inotify_fd < 0) {
20022002
/* We need to wait for the device symlink to show up, let's create an inotify watch for it */

src/libsystemd/sd-daemon/sd-daemon.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -668,17 +668,18 @@ _public_ int sd_notifyf(int unset_environment, const char *format, ...) {
668668
}
669669

670670
_public_ int sd_booted(void) {
671-
/* We test whether the runtime unit file directory has been
672-
* created. This takes place in mount-setup.c, so is
673-
* guaranteed to happen very early during boot. */
671+
int r;
674672

675-
if (laccess("/run/systemd/system/", F_OK) >= 0)
676-
return true;
673+
/* We test whether the runtime unit file directory has been created. This takes place in mount-setup.c,
674+
* so is guaranteed to happen very early during boot. */
677675

678-
if (errno == ENOENT)
676+
r = laccess("/run/systemd/system/", F_OK);
677+
if (r >= 0)
678+
return true;
679+
if (r == -ENOENT)
679680
return false;
680681

681-
return -errno;
682+
return r;
682683
}
683684

684685
_public_ int sd_watchdog_enabled(int unset_environment, uint64_t *usec) {

src/shared/condition.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,11 @@ static int condition_test_credential(Condition *c, char **env) {
174174
if (!j)
175175
return -ENOMEM;
176176

177-
if (laccess(j, F_OK) >= 0)
177+
r = laccess(j, F_OK);
178+
if (r >= 0)
178179
return true; /* yay! */
179-
if (errno != ENOENT)
180-
return -errno;
180+
if (r != -ENOENT)
181+
return r;
181182

182183
/* not found in this dir */
183184
}

src/shared/mount-util.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,9 @@ int bind_remount_one_with_mountinfo(
402402

403403
fs = mnt_table_find_target(table, path, MNT_ITER_FORWARD);
404404
if (!fs) {
405-
if (laccess(path, F_OK) < 0) /* Hmm, it's not in the mount table, but does it exist at all? */
406-
return -errno;
405+
r = laccess(path, F_OK); /* Hmm, it's not in the mount table, but does it exist at all? */
406+
if (r < 0)
407+
return r;
407408

408409
return -EINVAL; /* Not a mount point we recognize */
409410
}

src/sysext/sysext.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -683,13 +683,11 @@ static int merge_subprocess(Hashmap *images, const char *workspace) {
683683
if (!p)
684684
return log_oom();
685685

686-
if (laccess(p, F_OK) < 0) {
687-
if (errno != ENOENT)
688-
return log_error_errno(errno, "Failed to check if '%s' exists: %m", p);
689-
690-
/* Hierarchy apparently was empty in all extensions, and wasn't mounted, ignoring. */
686+
r = laccess(p, F_OK);
687+
if (r == -ENOENT) /* Hierarchy apparently was empty in all extensions, and wasn't mounted, ignoring. */
691688
continue;
692-
}
689+
if (r < 0)
690+
return log_error_errno(r, "Failed to check if '%s' exists: %m", p);
693691

694692
r = chase_symlinks(*h, arg_root, CHASE_PREFIX_ROOT|CHASE_NONEXISTENT, &resolved, NULL);
695693
if (r < 0)

src/system-update-generator/system-update-generator.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ static const char *arg_dest = NULL;
1919

2020
static int generate_symlink(void) {
2121
const char *p = NULL;
22+
int r;
2223

23-
if (laccess("/system-update", F_OK) < 0) {
24-
if (errno == ENOENT)
24+
r = laccess("/system-update", F_OK);
25+
if (r < 0) {
26+
if (r == -ENOENT)
2527
return 0;
2628

27-
log_error_errno(errno, "Failed to check for system update: %m");
29+
log_error_errno(r, "Failed to check for system update: %m");
2830
return -EINVAL;
2931
}
3032

0 commit comments

Comments
 (0)