]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: port more code to namespace_open_by_type()
authorLennart Poettering <lennart@poettering.net>
Tue, 7 Jan 2025 08:29:27 +0000 (09:29 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 10 Jan 2025 13:09:48 +0000 (14:09 +0100)
src/nspawn/nspawn-mount.c
src/nspawn/nspawn-network.c
src/nspawn/nspawn.c
src/shared/machine-id-setup.c
src/shared/socket-netlink.c

index af88e82d04aabe2d635d7b5447a534562ab635aa..d5370c22b9994dcdf55d8acadf1b1b36c8a417a2 100644 (file)
@@ -1447,14 +1447,9 @@ int wipe_fully_visible_api_fs(int mntns_fd) {
 
         log_debug("Wiping fully visible API FS");
 
-        r = namespace_open(0,
-                           /* ret_pidns_fd = */ NULL,
-                           &orig_mntns_fd,
-                           /* ret_netns_fd = */ NULL,
-                           /* ret_userns_fd = */ NULL,
-                           /* ret_root_fd = */ NULL);
-        if (r < 0)
-                return log_error_errno(r, "Failed to pin originating mount namespace: %m");
+        orig_mntns_fd = namespace_open_by_type(NAMESPACE_MOUNT);
+        if (orig_mntns_fd < 0)
+                return log_error_errno(orig_mntns_fd, "Failed to pin originating mount namespace: %m");
 
         r = namespace_enter(/* pidns_fd = */ -EBADF,
                             mntns_fd,
index f46995bb646c8f8f14cdfb7564be09d05c7726a6..928b8c5d411c611c579b9a72da4a10c5d54151ae 100644 (file)
@@ -476,14 +476,9 @@ static int netns_child_begin(int netns_fd, int *ret_original_netns_fd) {
         assert(netns_fd >= 0);
 
         if (ret_original_netns_fd) {
-                r = namespace_open(0,
-                                   /* ret_pidns_fd = */ NULL,
-                                   /* ret_mntns_fd = */ NULL,
-                                   &original_netns_fd,
-                                   /* ret_userns_fd = */ NULL,
-                                   /* ret_root_fd = */ NULL);
-                if (r < 0)
-                        return log_error_errno(r, "Failed to open original network namespace: %m");
+                original_netns_fd = namespace_open_by_type(NAMESPACE_NET);
+                if (original_netns_fd < 0)
+                        return log_error_errno(original_netns_fd, "Failed to open original network namespace: %m");
         }
 
         r = namespace_enter(/* pidns_fd = */ -EBADF,
index 4977ebd19390edabb79a757ead9e445549e683b9..bc9b91d2383744c15bdfc62bc0d92e8c12d2bb6d 100644 (file)
@@ -4012,14 +4012,9 @@ static int outer_child(
                 return r;
 
         if (arg_userns_mode != USER_NAMESPACE_NO) {
-                r = namespace_open(0,
-                                   /* ret_pidns_fd = */ NULL,
-                                   &mntns_fd,
-                                   /* ret_netns_fd = */ NULL,
-                                   /* ret_userns_fd = */ NULL,
-                                   /* ret_root_fd = */ NULL);
-                if (r < 0)
-                        return log_error_errno(r, "Failed to pin outer mount namespace: %m");
+                mntns_fd = namespace_open_by_type(NAMESPACE_MOUNT);
+                if (mntns_fd < 0)
+                        return log_error_errno(mntns_fd, "Failed to pin outer mount namespace: %m");
 
                 l = send_one_fd(fd_outer_socket, mntns_fd, 0);
                 if (l < 0)
index f5e1b9ee7231129aaf8f5730dd74aaefadbefd64..4240525742872935b0461222be40984d9ac1f191 100644 (file)
@@ -301,14 +301,9 @@ int machine_id_commit(const char *root) {
         fd = safe_close(fd);
 
         /* Store current mount namespace */
-        r = namespace_open(0,
-                           /* ret_pidns_fd = */ NULL,
-                           &initial_mntns_fd,
-                           /* ret_netns_fd = */ NULL,
-                           /* ret_userns_fd = */ NULL,
-                           /* ret_root_fd = */ NULL);
-        if (r < 0)
-                return log_error_errno(r, "Can't fetch current mount namespace: %m");
+        initial_mntns_fd = namespace_open_by_type(NAMESPACE_MOUNT);
+        if (initial_mntns_fd < 0)
+                return log_error_errno(initial_mntns_fd, "Can't fetch current mount namespace: %m");
 
         /* Switch to a new mount namespace, isolate ourself and unmount etc_machine_id in our new namespace */
         r = detach_mount_namespace();
index b0500abd8b140e87d7d29c11429b28cf346ec02b..bdb203934b4813b13683393f83f97e2bbe3313bd 100644 (file)
@@ -428,15 +428,9 @@ int netns_get_nsid(int netnsfd, uint32_t *ret) {
         int r;
 
         if (netnsfd < 0) {
-                r = namespace_open(
-                                0,
-                                /* ret_pidns_fd = */ NULL,
-                                /* ret_mntns_fd = */ NULL,
-                                &_netns_fd,
-                                /* ret_userns_fd = */ NULL,
-                                /* ret_root_fd = */ NULL);
-                if (r < 0)
-                        return r;
+                _netns_fd = namespace_open_by_type(NAMESPACE_NET);
+                if (_netns_fd < 0)
+                        return _netns_fd;
 
                 netnsfd = _netns_fd;
         }