#include "alloc-util.h"
#include "architecture.h"
#include "base-filesystem.h"
+#include "errno-util.h"
#include "fd-util.h"
#include "log.h"
#include "macro.h"
if (faccessat(fd, table[i].dir, F_OK, AT_SYMLINK_NOFOLLOW) >= 0)
continue;
- if (table[i].target) {
+ if (table[i].target) { /* Create as symlink? */
const char *target = NULL;
/* check if one of the targets exists */
if (!target)
continue;
- 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)
- return log_error_errno(errno, "Failed to chown symlink at %s/%s: %m", root, table[i].dir);
-
- continue;
+ r = RET_NERRNO(symlinkat(target, fd, table[i].dir));
+ } else {
+ /* Create as directory. */
+ WITH_UMASK(0000)
+ r = RET_NERRNO(mkdirat(fd, table[i].dir, table[i].mode));
}
-
- WITH_UMASK(0000)
- r = mkdirat(fd, table[i].dir, table[i].mode);
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 (IN_SET(errno, EEXIST, EROFS) || table[i].ignore_failure)
+ bool ignore = IN_SET(r, -EEXIST, -EROFS) || table[i].ignore_failure;
+ log_full_errno(ignore ? LOG_DEBUG : LOG_ERR, r,
+ "Failed to create %s/%s: %m", root, table[i].dir);
+ if (ignore)
continue;
- return -errno;
+ return r;
}
if (uid_is_valid(uid) || gid_is_valid(gid))
if (fchownat(fd, table[i].dir, uid, gid, AT_SYMLINK_NOFOLLOW) < 0)
- return log_error_errno(errno, "Failed to chown directory at %s/%s: %m", root, table[i].dir);
+ return log_error_errno(errno, "Failed to chown %s/%s: %m", root, table[i].dir);
}
return 0;