diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2019-04-04 06:05:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-04 06:05:12 +0200 |
commit | ad2d50f84025ab1df3b05a6a28877763c17bc972 (patch) | |
tree | ec5895059e10f18a961ae40f46d663d53ff5d6ca | |
parent | Merge pull request #12207 from poettering/portable-bus-policy-fix (diff) | |
parent | shared: be friendly to EROFS images (diff) | |
download | systemd-ad2d50f84025ab1df3b05a6a28877763c17bc972.tar.xz systemd-ad2d50f84025ab1df3b05a6a28877763c17bc972.zip |
Merge pull request #12208 from poettering/base-file-system-tweaks
base-filesystem: be nicer to read-only fs images
-rw-r--r-- | src/shared/base-filesystem.c | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/shared/base-filesystem.c b/src/shared/base-filesystem.c index 52460cacad..657407da2d 100644 --- a/src/shared/base-filesystem.c +++ b/src/shared/base-filesystem.c @@ -14,6 +14,7 @@ #include "log.h" #include "macro.h" #include "nulstr-util.h" +#include "path-util.h" #include "string-util.h" #include "umask-util.h" #include "user-util.h" @@ -45,8 +46,8 @@ static const BaseFilesystem table[] = { int base_filesystem_create(const char *root, uid_t uid, gid_t gid) { _cleanup_close_ int fd = -1; - int r = 0; size_t i; + int r; fd = open(root, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW); if (fd < 0) @@ -68,7 +69,7 @@ int base_filesystem_create(const char *root, uid_t uid, gid_t gid) { if (table[i].exists) { _cleanup_free_ char *p = NULL; - p = strjoin(s, "/", table[i].exists); + p = path_join(s, table[i].exists); if (!p) return log_oom(); @@ -83,9 +84,15 @@ int base_filesystem_create(const char *root, uid_t uid, gid_t gid) { if (!target) continue; - r = symlinkat(target, fd, table[i].dir); - if (r < 0 && errno != EEXIST) - return log_error_errno(errno, "Failed to create symlink at %s/%s: %m", root, table[i].dir); + if (symlinkat(target, fd, table[i].dir) < 0) { + log_full_errno(IN_SET(errno, EEXIST, EROFS) || table[i].ignore_failure ? LOG_DEBUG : LOG_ERR, errno, + "Failed to create symlink at %s/%s: %m", root, table[i].dir); + + if (IN_SET(errno, EEXIST, EROFS) || table[i].ignore_failure) + continue; + + return -errno; + } if (uid_is_valid(uid) || gid_is_valid(gid)) { if (fchownat(fd, table[i].dir, uid, gid, AT_SYMLINK_NOFOLLOW) < 0) @@ -97,14 +104,14 @@ int base_filesystem_create(const char *root, uid_t uid, gid_t gid) { RUN_WITH_UMASK(0000) r = mkdirat(fd, table[i].dir, table[i].mode); - if (r < 0 && errno != EEXIST) { - log_full_errno(table[i].ignore_failure ? LOG_DEBUG : LOG_ERR, errno, + if (r < 0) { + log_full_errno(IN_SET(errno, EEXIST, EROFS) || table[i].ignore_failure ? LOG_DEBUG : LOG_ERR, errno, "Failed to create directory at %s/%s: %m", root, table[i].dir); - if (!table[i].ignore_failure) - return -errno; + if (IN_SET(errno, EEXIST, EROFS) || table[i].ignore_failure) + continue; - continue; + return -errno; } if (uid != UID_INVALID || gid != UID_INVALID) { |