Class: Haconiwa::Namespace

Inherits:
Object
  • Object
show all
Defined in:
lib/haconiwa/namespace.rb

Constant Summary collapse

UNSHARE =
272
CLONE_FS =

from linux/sched.h

0x00000200
CLONE_FILES =
0x00000400
CLONE_NEWNS =
0x00020000
CLONE_SYSVSEM =
0x00040000
CLONE_NEWCGROUP =
0x02000000
CLONE_NEWUTS =
0x04000000
CLONE_NEWIPC =
0x08000000
CLONE_NEWUSER =
0x10000000
CLONE_NEWPID =
0x20000000
CLONE_NEWNET =
0x40000000
NS_MAPPINGS =
{
  "cgroup" => CLONE_NEWCGROUP,
  "ipc"    => CLONE_NEWIPC,
  "net"    => CLONE_NEWNET,
  "mount"  => CLONE_NEWNS,
  "pid"    => CLONE_NEWPID,
  "user"   => CLONE_NEWUSER,
  "uts"    => CLONE_NEWUTS,
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNamespace

Returns a new instance of Namespace.



28
29
30
31
# File 'lib/haconiwa/namespace.rb', line 28

def initialize
  @use_ns = []
  @netns_name = nil
end

Instance Attribute Details

#use_pid_nsObject (readonly)

Returns the value of attribute use_pid_ns.



46
47
48
# File 'lib/haconiwa/namespace.rb', line 46

def use_pid_ns
  @use_pid_ns
end

Instance Method Details

#apply!Object



52
53
54
55
56
# File 'lib/haconiwa/namespace.rb', line 52

def apply!
  flag = to_ns_flag
  STDERR.puts "unshare(2) flag: 0x%s" % flag.to_s(16)
  Kernel.syscall(UNSHARE, flag)
end

#unshare(ns) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/haconiwa/namespace.rb', line 33

def unshare(ns)
  flag = case ns
         when String, Symbol
           NS_MAPPINGS[ns.to_s]
         when Integer
           ns
         end
  if flag == CLONE_NEWPID
    @use_pid_ns = true
  else
    @use_ns << flag
  end
end

#use_netns(name) ⇒ Object



48
49
50
# File 'lib/haconiwa/namespace.rb', line 48

def use_netns(name)
  @netns_name = name
end