]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
namespace: simplify apply_one_mount() a bit
authorLennart Poettering <lennart@poettering.net>
Mon, 10 Mar 2025 10:33:50 +0000 (11:33 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 17 Mar 2025 15:03:18 +0000 (16:03 +0100)
Drop a bunch of unnecessary casts, format strings, and {} blocks.

src/core/namespace.c

index 0943e0818fae497285bb67aee3f9f84b4f768ddd..64f773b2c29724e09f71dc38ccc2302c82474aa3 100644 (file)
@@ -1899,23 +1899,21 @@ static int apply_one_mount(
                 log_debug("Setting an id-mapped mount on %s", mount_entry_path(m));
 
                 /* Do mapping from nobody (in setup_exec_directory()) -> this uid */
-                if (strextendf(&uid_map, UID_FMT " " UID_FMT " " UID_FMT "\n", UID_NOBODY, (uid_t)m->idmap_uid, (uid_t)1u) < 0)
+                if (strextendf(&uid_map, UID_FMT " " UID_FMT " 1\n", UID_NOBODY, m->idmap_uid) < 0)
                         return log_oom();
 
                 /* Consider StateDirectory=xxx aaa xxx:aaa/222
                  * To allow for later symlink creation (by root) in create_symlinks_from_tuples(), map root as well. */
-                if (m->idmap_uid != (uid_t)0) {
-                        if (strextendf(&uid_map, UID_FMT " " UID_FMT " " UID_FMT "\n", (uid_t)0, (uid_t)0, (uid_t)1u) < 0)
+                if (m->idmap_uid != 0)
+                        if (!strextend(&uid_map, "0 0 1\n"))
                                 return log_oom();
-                }
 
-                if (strextendf(&gid_map, GID_FMT " " GID_FMT " " GID_FMT "\n", GID_NOBODY, (gid_t)m->idmap_gid, (gid_t)1u) < 0)
+                if (strextendf(&gid_map, GID_FMT " " GID_FMT " 1\n", GID_NOBODY, m->idmap_gid) < 0)
                         return log_oom();
 
-                if (m->idmap_gid != (gid_t)0) {
-                        if (strextendf(&gid_map, GID_FMT " " GID_FMT " " GID_FMT "\n", (gid_t)0, (gid_t)0, (gid_t)1u) < 0)
+                if (m->idmap_gid != 0)
+                        if (!strextend(&gid_map, "0 0 1\n"))
                                 return log_oom();
-                }
 
                 userns_fd = userns_acquire(uid_map, gid_map, /* setgroups_deny= */ true);
                 if (userns_fd < 0)