[pve-devel] [PATCH v3 container 06/12] split open_namespace out of enter_namespace

Wolfgang Bumiller w.bumiller at proxmox.com
Tue Nov 19 10:34:38 CET 2019


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

 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 e5b765a..2a79327 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -1029,12 +1029,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