summaryrefslogtreecommitdiffstats
path: root/src/basic
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2024-10-06 06:50:11 +0200
committerGitHub <noreply@github.com>2024-10-06 06:50:11 +0200
commit61c7f38f1044fc6abe309b4001bdd7da83e2c851 (patch)
tree499bc667d2d2b6af8ed7bc3e556211f7a910eb4a /src/basic
parentMerge pull request #34639 from DaanDeMeyer/repart-fix (diff)
parentfs-util: rename laccess to access_nofollow (diff)
downloadsystemd-61c7f38f1044fc6abe309b4001bdd7da83e2c851.tar.xz
systemd-61c7f38f1044fc6abe309b4001bdd7da83e2c851.zip
Merge pull request #34638 from YHNdnzj/laccess-error-check
various: correct laccess() error check
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/cgroup-util.c2
-rw-r--r--src/basic/fs-util.h2
-rw-r--r--src/basic/os-util.c5
-rw-r--r--src/basic/path-lookup.c9
4 files changed, 10 insertions, 8 deletions
diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c
index b3cd2c27a6..223bcdfbcf 100644
--- a/src/basic/cgroup-util.c
+++ b/src/basic/cgroup-util.c
@@ -623,7 +623,7 @@ static int controller_is_v1_accessible(const char *root, const char *controller)
* - we can modify the hierarchy. */
cpath = strjoina("/sys/fs/cgroup/", dn, root, root ? "/cgroup.procs" : NULL);
- return laccess(cpath, root ? W_OK : F_OK);
+ return access_nofollow(cpath, root ? W_OK : F_OK);
}
int cg_get_path_and_check(const char *controller, const char *path, const char *suffix, char **ret) {
diff --git a/src/basic/fs-util.h b/src/basic/fs-util.h
index 2ec4b196f8..82e865180b 100644
--- a/src/basic/fs-util.h
+++ b/src/basic/fs-util.h
@@ -49,7 +49,7 @@ int futimens_opath(int fd, const struct timespec ts[2]);
int fd_warn_permissions(const char *path, int fd);
int stat_warn_permissions(const char *path, const struct stat *st);
-#define laccess(path, mode) \
+#define access_nofollow(path, mode) \
RET_NERRNO(faccessat(AT_FDCWD, (path), (mode), AT_SYMLINK_NOFOLLOW))
int touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gid, mode_t mode);
diff --git a/src/basic/os-util.c b/src/basic/os-util.c
index 4eec2f6014..21b6f669e6 100644
--- a/src/basic/os-util.c
+++ b/src/basic/os-util.c
@@ -97,8 +97,9 @@ int path_is_extension_tree(ImageClass image_class, const char *path, const char
/* Does the path exist at all? If not, generate an error immediately. This is useful so that a missing root dir
* always results in -ENOENT, and we can properly distinguish the case where the whole root doesn't exist from
* the case where just the os-release file is missing. */
- if (laccess(path, F_OK) < 0)
- return -errno;
+ r = access_nofollow(path, F_OK);
+ if (r < 0)
+ return r;
/* We use /usr/lib/extension-release.d/extension-release[.NAME] as flag for something being a system extension,
* /etc/extension-release.d/extension-release[.NAME] as flag for something being a system configuration, and finally,
diff --git a/src/basic/path-lookup.c b/src/basic/path-lookup.c
index 540256b73b..234b197394 100644
--- a/src/basic/path-lookup.c
+++ b/src/basic/path-lookup.c
@@ -904,6 +904,7 @@ char **env_generator_binary_paths(RuntimeScope runtime_scope) {
int find_portable_profile(const char *name, const char *unit, char **ret_path) {
const char *dot;
+ int r;
assert(name);
assert(ret_path);
@@ -917,13 +918,13 @@ int find_portable_profile(const char *name, const char *unit, char **ret_path) {
if (!joined)
return -ENOMEM;
- if (laccess(joined, F_OK) >= 0) {
+ r = access_nofollow(joined, F_OK);
+ if (r >= 0) {
*ret_path = TAKE_PTR(joined);
return 0;
}
-
- if (errno != ENOENT)
- return -errno;
+ if (r != -ENOENT)
+ return r;
}
return -ENOENT;