[pve-devel] [PATCH v2 container 4/9] split open_namespace out of enter_namespace

Wolfgang Bumiller w.bumiller at proxmox.com
Wed Nov 13 10:33:14 CET 2019


Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
No changes.

 src/PVE/LXC.pm | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index c51e59e..c07a597 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -1033,12 +1033,18 @@ sub update_ipconfig {
 
 }
 
+my $open_namespace = sub {
+    my ($vmid, $pid, $kind) = @_;
+    sysopen my $fd, "/proc/$pid/ns/$kind", O_RDONLY
+	or die "failed to open $kind namespace of container $vmid: $!\n";
+    return $fd;
+};
+
 my $enter_namespace = sub {
-    my ($vmid, $pid, $which, $type) = @_;
-    sysopen my $fd, "/proc/$pid/ns/$which", O_RDONLY
-	or die "failed to open $which namespace of container $vmid: $!\n";
+    my ($vmid, $pid, $kind, $type) = @_;
+    my $fd = $open_namespace->($vmid, $pid, $kind);
     PVE::Tools::setns(fileno($fd), $type)
-	or die "failed to enter $which namespace of container $vmid: $!\n";
+	or die "failed to enter $kind namespace of container $vmid: $!\n";
     close $fd;
 };
 
-- 
2.20.1





More information about the pve-devel mailing list