From 72e6e794076adbb2dfb4fd69eb548fb16f4f1ea9 Mon Sep 17 00:00:00 2001 From: Ryan Voots Date: Wed, 3 May 2017 17:02:48 -0700 Subject: [PATCH] Make it reload syscall.ph so both places get the functions --- lib/Sys/Linux/Mount.pm | 8 ++++++-- lib/Sys/Linux/Namespace.pm | 14 +++++++++++--- lib/Sys/Linux/Unshare.pm | 12 ++++++++++-- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/lib/Sys/Linux/Mount.pm b/lib/Sys/Linux/Mount.pm index 242370b..6360302 100644 --- a/lib/Sys/Linux/Mount.pm +++ b/lib/Sys/Linux/Mount.pm @@ -5,7 +5,11 @@ use warnings; require Exporter; our @ISA = qw/Exporter/; -require 'syscall.ph'; +BEGIN { + # Force reloading of all .ph files + delete $INC{$_} for (grep {/\.ph$/} keys %INC); + require 'syscall.ph'; +} my @mount_consts = qw/MS_RDONLY MS_NOSUID MS_NODEV MS_NOEXEC MS_SYNCHRONOUS MS_REMOUNT MS_MANDLOCK MS_DIRSYNC MS_NOATIME MS_NODIRATIME MS_BIND MS_MOVE MS_REC MS_SILENT MS_POSIXACL MS_UNBINDABLE MS_PRIVATE MS_SLAVE MS_SHARED MS_RELATIME MS_KERNMOUNT MS_I_VERSION MS_STRICTATIME MS_LAZYTIME MS_ACTIVE MS_NOUSER/; @@ -21,7 +25,7 @@ sub mount { my $options_str = join ',', map {"$_=".$options_hr->{$_}} keys %$options_hr; - my $ret = syscall(SYS_mount(), $source, $target, $filesystem, $flags, $options_str); + my $ret = syscall(SYS_mount(), $source, $target, $filesystem//undef, $flags, $options_str); if ($ret != 0) { die "mount failed: $ret $!"; diff --git a/lib/Sys/Linux/Namespace.pm b/lib/Sys/Linux/Namespace.pm index db553a1..b879b0f 100644 --- a/lib/Sys/Linux/Namespace.pm +++ b/lib/Sys/Linux/Namespace.pm @@ -7,6 +7,11 @@ use Sys::Linux::Mount qw/:all/; use Sys::Linux::Unshare qw/:all/; use POSIX qw/_exit/; +require Exporter; +our @ISA = qw/Exporter/; + +our @EXPORT_OK=qw/namespace/; + sub namespace { my ($options) = @_; @@ -25,6 +30,7 @@ sub namespace { } elsif (ref $options->{private_tmp}) { die "Bad ref type passed as private_tmp"; } else { + mount("/tmp", "/tmp", "tmpfs", 0, undef); mount("/tmp", "/tmp", "tmpfs", MS_PRIVATE, undef); } } @@ -48,9 +54,9 @@ sub namespace { my $mid_pid = fork(); unless($mid_pid == -1) { - if($mid_pid) { + if ($mid_pid) { # Original Process - waitpid($mid_pid); # WE MUST BLOCK + waitpid($mid_pid, 0); # WE MUST BLOCK return; # don't run anything else in here } else { # Middle child process @@ -60,7 +66,7 @@ sub namespace { unless($child_pid == -1) { if ($child_pid) { - waitpid($child_pid); + waitpid($child_pid, 0); } else { $options->{pid}->(); } @@ -80,3 +86,5 @@ sub namespace { $post_setup->(); } } + +1; diff --git a/lib/Sys/Linux/Unshare.pm b/lib/Sys/Linux/Unshare.pm index 1ebc283..86eebfa 100644 --- a/lib/Sys/Linux/Unshare.pm +++ b/lib/Sys/Linux/Unshare.pm @@ -1,11 +1,16 @@ package Sys::Linux::Unshare; -use strict; +#use strict; use warnings; +use Data::Dumper; require Exporter; our @ISA = qw/Exporter/; -require 'syscall.ph'; +BEGIN { + # Force reloading of all .ph files + delete $INC{$_} for (grep {/\.ph$/} keys %INC); + require 'syscall.ph'; +} my @unshare_consts = qw/CSIGNAL CLONE_VM CLONE_FS CLONE_FILES CLONE_SIGHAND CLONE_PTRACE CLONE_VFORK CLONE_PARENT CLONE_THREAD CLONE_NEWNS CLONE_SYSVSEM CLONE_SETTLS CLONE_PARENT_SETTID CLONE_CHILD_CLEARTID CLONE_DETACHED CLONE_UNTRACED CLONE_CHILD_SETTID CLONE_NEWCGROUP CLONE_NEWUTS CLONE_NEWIPC CLONE_NEWUSER CLONE_NEWPID CLONE_NEWNET CLONE_IO/; @@ -19,6 +24,9 @@ our %EXPORT_TAGS = ( sub unshare { my ($flags) = @_; + + local $! = 0; + ### FIXME XXX HACK FUCK YOU = 272 unshare syscall number on x86_64 my $ret = syscall(SYS_unshare(), $flags); if ($ret != 0) {