Module: Mountfd::Namespace
- Defined in:
- lib/mountfd/namespace.rb,
sig/mountfd.rbs
Class Method Summary collapse
- .reexec_user! ⇒ nil
- .unshare_mount!(propagation: :private) ⇒ nil
- .unshare_user!(map_root: true) ⇒ nil
Class Method Details
.reexec_user! ⇒ nil
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/mountfd/namespace.rb', line 7 def self.reexec_user! return if ENV["MOUNTFD_IN_USERNS"] raise UnsupportedError, "user namespaces are unavailable on this platform" unless Native.linux? command = begin File.binread("/proc/self/cmdline").split("\0") rescue Errno::EACCES, Errno::ENOENT [] end command = [RbConfig.ruby, $PROGRAM_NAME, *ARGV] if command.empty? exec({"MOUNTFD_IN_USERNS" => "1"}, "unshare", "-Ur", *command) end |
.unshare_mount!(propagation: :private) ⇒ nil
20 21 22 23 24 25 26 27 |
# File 'lib/mountfd/namespace.rb', line 20 def self.unshare_mount!(propagation: :private) raise ArgumentError, "propagation must be :private or nil" unless propagation.nil? || propagation == :private warn_unless_main_thread Native.unshare(Native::CLONE_NEWNS) Native.change_propagation("/", Native::MS_PRIVATE | Native::MS_REC) if propagation == :private nil end |
.unshare_user!(map_root: true) ⇒ nil
29 30 31 32 |
# File 'lib/mountfd/namespace.rb', line 29 def self.unshare_user!(map_root: true) warn_unless_main_thread Native.unshare_user(map_root) end |