summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-11-12 15:12:23 +0100
committerLennart Poettering <lennart@poettering.net>2021-11-16 17:01:58 +0100
commitd1cd465e21eb3fd100819378e906483dded1ce71 (patch)
tree02ce79e4fd416c87be0c820f7c7832b90996a547
parent1e146d738232acbe7f72903e9c5e4d1166ea67f5 (diff)
downloadsystemd-d1cd465e21eb3fd100819378e906483dded1ce71.tar.gz
smack make mac_smack_fix_at() useful when called with dir_fd=AT_FDCWD
-rw-r--r--src/shared/smack-util.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/shared/smack-util.c b/src/shared/smack-util.c
index d7fbbdc913..b8434b068c 100644
--- a/src/shared/smack-util.c
+++ b/src/shared/smack-util.c
@@ -176,7 +176,7 @@ static int smack_fix_fd(int fd, const char *abspath, LabelFixFlags flags) {
return 0;
}
-int mac_smack_fix_at(int dirfd, const char *path, LabelFixFlags flags) {
+int mac_smack_fix_at(int dir_fd, const char *path, LabelFixFlags flags) {
_cleanup_free_ char *p = NULL;
_cleanup_close_ int fd = -1;
int r;
@@ -186,7 +186,14 @@ int mac_smack_fix_at(int dirfd, const char *path, LabelFixFlags flags) {
if (!mac_smack_use())
return 0;
- fd = openat(dirfd, path, O_NOFOLLOW|O_CLOEXEC|O_PATH);
+ if (dir_fd < 0) {
+ if (dir_fd != AT_FDCWD)
+ return -EBADF;
+
+ return mac_smack_fix(path, flags);
+ }
+
+ fd = openat(dir_fd, path, O_NOFOLLOW|O_CLOEXEC|O_PATH);
if (fd < 0) {
if ((flags & LABEL_IGNORE_ENOENT) && errno == ENOENT)
return 0;