]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
base-filesystem: use FOREACH_ELEMENT()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 5 Sep 2024 10:37:52 +0000 (19:37 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 6 Sep 2024 04:09:36 +0000 (13:09 +0900)
src/shared/base-filesystem.c

index 0d5075e1e6d5afdaf863028c4c6f49148ee4adf1..389c77eee0ea3fe42955edf448ed65181f4ab753 100644 (file)
@@ -136,23 +136,23 @@ int base_filesystem_create_fd(int fd, const char *root, uid_t uid, gid_t gid) {
 
         /* The "root" parameter is decoration only – it's only used as part of log messages */
 
-        for (size_t i = 0; i < ELEMENTSOF(table); i++) {
-                if (faccessat(fd, table[i].dir, F_OK, AT_SYMLINK_NOFOLLOW) >= 0)
+        FOREACH_ELEMENT(i, table) {
+                if (faccessat(fd, i->dir, F_OK, AT_SYMLINK_NOFOLLOW) >= 0)
                         continue;
 
-                if (table[i].target) { /* Create as symlink? */
+                if (i->target) { /* Create as symlink? */
                         const char *target = NULL;
 
                         /* check if one of the targets exists */
-                        NULSTR_FOREACH(s, table[i].target) {
+                        NULSTR_FOREACH(s, i->target) {
                                 if (faccessat(fd, s, F_OK, AT_SYMLINK_NOFOLLOW) < 0)
                                         continue;
 
                                 /* check if a specific file exists at the target path */
-                                if (table[i].exists) {
+                                if (i->exists) {
                                         _cleanup_free_ char *p = NULL;
 
-                                        p = path_join(s, table[i].exists);
+                                        p = path_join(s, i->exists);
                                         if (!p)
                                                 return log_oom();
 
@@ -167,16 +167,16 @@ int base_filesystem_create_fd(int fd, const char *root, uid_t uid, gid_t gid) {
                         if (!target)
                                 continue;
 
-                        r = RET_NERRNO(symlinkat(target, fd, table[i].dir));
+                        r = RET_NERRNO(symlinkat(target, fd, i->dir));
                 } else {
                         /* Create as directory. */
                         WITH_UMASK(0000)
-                                r = RET_NERRNO(mkdirat(fd, table[i].dir, table[i].mode));
+                                r = RET_NERRNO(mkdirat(fd, i->dir, i->mode));
                 }
                 if (r < 0) {
-                        bool ignore = IN_SET(r, -EEXIST, -EROFS) || table[i].ignore_failure;
+                        bool ignore = IN_SET(r, -EEXIST, -EROFS) || i->ignore_failure;
                         log_full_errno(ignore ? LOG_DEBUG : LOG_ERR, r,
-                                       "Failed to create %s/%s: %m", root, table[i].dir);
+                                       "Failed to create %s/%s: %m", root, i->dir);
                         if (ignore)
                                 continue;
 
@@ -184,8 +184,8 @@ int base_filesystem_create_fd(int fd, const char *root, uid_t uid, gid_t gid) {
                 }
 
                 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 %s/%s: %m", root, table[i].dir);
+                        if (fchownat(fd, i->dir, uid, gid, AT_SYMLINK_NOFOLLOW) < 0)
+                                return log_error_errno(errno, "Failed to chown %s/%s: %m", root, i->dir);
         }
 
         return 0;