Skip to content

Commit 544fe85

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) (cherry picked from commit 6c14211)
1 parent ac30752 commit 544fe85

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 *p, *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
@@ -1986,11 +1986,11 @@ static int wait_for_devlink(const char *path) {
19861986
_cleanup_free_ char *dn = NULL;
19871987
usec_t w;
19881988

1989-
if (laccess(path, F_OK) < 0) {
1990-
if (errno != ENOENT)
1991-
return log_error_errno(errno, "Failed to determine whether %s exists: %m", path);
1992-
} else
1989+
r = laccess(path, F_OK);
1990+
if (r >= 0)
19931991
return 0; /* Found it */
1992+
if (r != -ENOENT)
1993+
return log_error_errno(r, "Failed to determine whether %s exists: %m", path);
19941994

19951995
if (inotify_fd < 0) {
19961996
/* 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
@@ -616,17 +616,18 @@ _public_ int sd_notifyf(int unset_environment, const char *format, ...) {
616616
}
617617

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

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

626-
if (errno == ENOENT)
624+
r = laccess("/run/systemd/system/", F_OK);
625+
if (r >= 0)
626+
return true;
627+
if (r == -ENOENT)
627628
return false;
628629

629-
return -errno;
630+
return r;
630631
}
631632

632633
_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
@@ -172,10 +172,11 @@ static int condition_test_credential(Condition *c, char **env) {
172172
if (!j)
173173
return -ENOMEM;
174174

175-
if (laccess(j, F_OK) >= 0)
175+
r = laccess(j, F_OK);
176+
if (r >= 0)
176177
return true; /* yay! */
177-
if (errno != ENOENT)
178-
return -errno;
178+
if (r != -ENOENT)
179+
return r;
179180

180181
/* not found in this dir */
181182
}

src/shared/mount-util.c

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

447447
fs = mnt_table_find_target(table, path, MNT_ITER_FORWARD);
448448
if (!fs) {
449-
if (laccess(path, F_OK) < 0) /* Hmm, it's not in the mount table, but does it exist at all? */
450-
return -errno;
449+
r = laccess(path, F_OK); /* Hmm, it's not in the mount table, but does it exist at all? */
450+
if (r < 0)
451+
return r;
451452

452453
return -EINVAL; /* Not a mount point we recognize */
453454
}

src/sysext/sysext.c

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

679-
if (laccess(p, F_OK) < 0) {
680-
if (errno != ENOENT)
681-
return log_error_errno(errno, "Failed to check if '%s' exists: %m", p);
682-
683-
/* Hierarchy apparently was empty in all extensions, and wasn't mounted, ignoring. */
679+
r = laccess(p, F_OK);
680+
if (r == -ENOENT) /* Hierarchy apparently was empty in all extensions, and wasn't mounted, ignoring. */
684681
continue;
685-
}
682+
if (r < 0)
683+
return log_error_errno(r, "Failed to check if '%s' exists: %m", p);
686684

687685
r = chase_symlinks(*h, arg_root, CHASE_PREFIX_ROOT|CHASE_NONEXISTENT, &resolved, NULL);
688686
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
@@ -20,12 +20,14 @@ static const char *arg_dest = NULL;
2020

2121
static int generate_symlink(void) {
2222
const char *p = NULL;
23+
int r;
2324

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

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

0 commit comments

Comments
 (0)