]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nsresource: add constants for the only supported UID range size allocations
authorLennart Poettering <lennart@poettering.net>
Tue, 21 Oct 2025 21:00:46 +0000 (23:00 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 21 Oct 2025 21:09:50 +0000 (23:09 +0200)
As requested: https://github.com/systemd/systemd/pull/39322#discussion_r2447366728

src/dissect/dissect.c
src/nspawn/nspawn.c
src/shared/nsresource.h

index 332471a4099c82c0111388b404151952b106cd24..ca69b36c22849f7b0bd110ac6c1f40d4bb636fb5 100644 (file)
@@ -2302,7 +2302,7 @@ static int run(int argc, char *argv[]) {
 
                         /* Don't run things in private userns, if the mount shall be attached to the host */
                         if (!IN_SET(arg_action, ACTION_MOUNT, ACTION_WITH)) {
-                                userns_fd = nsresource_allocate_userns(/* name= */ NULL, UINT64_C(0x10000)); /* allocate 64K users by default */
+                                userns_fd = nsresource_allocate_userns(/* name= */ NULL, NSRESOURCE_UIDS_64K); /* allocate 64K users by default */
                                 if (userns_fd < 0)
                                         return log_error_errno(userns_fd, "Failed to allocate user namespace with 64K users: %m");
                         }
index 3e4565e4a2825d7cf4a1ac21c1d878aac0e95785..5de826c44a9aa9ce4ce82b0be41894913b7d8278 100644 (file)
@@ -6007,7 +6007,7 @@ static int run(int argc, char *argv[]) {
                         goto finish;
                 }
 
-                userns_fd = nsresource_allocate_userns(userns_name, UINT64_C(0x10000));
+                userns_fd = nsresource_allocate_userns(userns_name, NSRESOURCE_UIDS_64K); /* allocate 64K UIDs */
                 if (userns_fd < 0) {
                         r = log_error_errno(userns_fd, "Failed to allocate user namespace with 64K users: %m");
                         goto finish;
@@ -6019,7 +6019,7 @@ static int run(int argc, char *argv[]) {
                         goto finish;
                 }
 
-                arg_uid_range = UINT32_C(0x10000);
+                arg_uid_range = NSRESOURCE_UIDS_64K;
         }
 
         if (arg_directory) {
index c06025761a5c7d2de046eac6ee5d6318374c09e2..136b1f85ac12c8f9aa545efa894629c4cce424b2 100644 (file)
@@ -3,6 +3,10 @@
 
 #include "shared-forward.h"
 
+/* Helpful constants for the only numbers of UIDs that can currently be allocated */
+#define NSRESOURCE_UIDS_64K 0x10000U
+#define NSRESOURCE_UIDS_1 1U
+
 int nsresource_allocate_userns(const char *name, uint64_t size);
 int nsresource_register_userns(const char *name, int userns_fd);
 int nsresource_add_mount(int userns_fd, int mount_fd);