Class: OsCtl::Lib::Sys
- Inherits:
-
Object
- Object
- OsCtl::Lib::Sys
- Defined in:
- lib/libosctl/sys.rb
Defined Under Namespace
Modules: Int
Constant Summary collapse
- CLONE_NEWNS =
0x00020000- CLONE_NEWUTS =
0x04000000- CLONE_NEWUSER =
0x10000000- CLONE_NEWPID =
0x20000000- CLONE_NEWNET =
0x40000000- CLONE_NEWIPC =
0x08000000- MS_MGC_VAL =
0xc0ed0000- MS_RDONLY =
1- MS_NOSUID =
2- MS_NODEV =
4- MS_NOEXEC =
8- MS_REMOUNT =
32- MS_BIND =
4096- MS_MOVE =
8192- MS_REC =
16_384- MS_SLAVE =
1 << 19
- MS_SHARED =
1 << 20
- SYSLOGNS_MAX_TAG_BYTESIZE =
12
Instance Method Summary collapse
- #attach_syslogns(pid) ⇒ Object
- #bind_mount(src, dst) ⇒ Object
- #bind_mount_readonly(src, dst) ⇒ Object
- #chroot(path) ⇒ Object
- #create_syslogns(tag) ⇒ Object
- #make_rshared(dst) ⇒ Object
- #make_rslave(dst) ⇒ Object
- #make_shared(dst) ⇒ Object
- #make_slave(dst) ⇒ Object
- #mount_proc(dst) ⇒ Object
- #mount_tmpfs(dst, name: 'none', flags: MS_MGC_VAL, options: 0) ⇒ Object
- #move_mount(src, dst) ⇒ Object
- #rbind_mount(src, dst) ⇒ Object
- #setns_io(io, nstype) ⇒ Object
- #setns_path(path, nstype) ⇒ Object
- #setresgid(rgid, egid, sgid) ⇒ Object
- #setresuid(ruid, euid, suid) ⇒ Object
- #syncfs(path) ⇒ Object
- #unmount(mountpoint) ⇒ Object
- #unmount_lazy(mountpoint) ⇒ Object
- #unshare_ns(type) ⇒ Object
Instance Method Details
#attach_syslogns(pid) ⇒ Object
190 191 192 |
# File 'lib/libosctl/sys.rb', line 190 def attach_syslogns(pid) setns_path(File.join('/proc', pid.to_s, 'ns/syslog'), 0) end |
#bind_mount(src, dst) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/libosctl/sys.rb', line 69 def bind_mount(src, dst) ret = Int.mount(src, dst, 0, MS_MGC_VAL | MS_BIND, 0) raise SystemCallError, Fiddle.last_error if ret != 0 ret end |
#bind_mount_readonly(src, dst) ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/libosctl/sys.rb', line 76 def bind_mount_readonly(src, dst) bind_mount(src, dst) ret = Int.mount('none', dst, 0, MS_MGC_VAL | MS_BIND | MS_REMOUNT | MS_RDONLY, 0) raise SystemCallError, Fiddle.last_error if ret != 0 ret end |
#chroot(path) ⇒ Object
167 168 169 170 171 172 |
# File 'lib/libosctl/sys.rb', line 167 def chroot(path) ret = Int.chroot(path) raise SystemCallError, Fiddle.last_error if ret != 0 ret end |
#create_syslogns(tag) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/libosctl/sys.rb', line 175 def create_syslogns(tag) if tag.bytesize > SYSLOGNS_MAX_TAG_BYTESIZE raise ArgumentError, "tag can have at most #{SYSLOGNS_MAX_TAG_BYTESIZE} bytes" end klogctl_ret = Int.klogctl(11, tag, tag.bytesize) raise SystemCallError, Fiddle.last_error if klogctl_ret != 0 unshare_ret = Int.unshare(0) raise SystemCallError, Fiddle.last_error if unshare_ret != 0 0 end |
#make_rshared(dst) ⇒ Object
113 114 115 116 117 118 |
# File 'lib/libosctl/sys.rb', line 113 def make_rshared(dst) ret = Int.mount('none', dst, 0, MS_REC | MS_SHARED, 0) raise SystemCallError, Fiddle.last_error if ret != 0 ret end |
#make_rslave(dst) ⇒ Object
127 128 129 130 131 132 |
# File 'lib/libosctl/sys.rb', line 127 def make_rslave(dst) ret = Int.mount('none', dst, 0, MS_REC | MS_SLAVE, 0) raise SystemCallError, Fiddle.last_error if ret != 0 ret end |
#make_shared(dst) ⇒ Object
106 107 108 109 110 111 |
# File 'lib/libosctl/sys.rb', line 106 def make_shared(dst) ret = Int.mount('none', dst, 0, MS_SHARED, 0) raise SystemCallError, Fiddle.last_error if ret != 0 ret end |
#make_slave(dst) ⇒ Object
120 121 122 123 124 125 |
# File 'lib/libosctl/sys.rb', line 120 def make_slave(dst) ret = Int.mount('none', dst, 0, MS_SLAVE, 0) raise SystemCallError, Fiddle.last_error if ret != 0 ret end |
#mount_proc(dst) ⇒ Object
99 100 101 102 103 104 |
# File 'lib/libosctl/sys.rb', line 99 def mount_proc(dst) ret = Int.mount('none', dst, 'proc', MS_MGC_VAL, 0) raise SystemCallError, Fiddle.last_error if ret != 0 ret end |
#mount_tmpfs(dst, name: 'none', flags: MS_MGC_VAL, options: 0) ⇒ Object
92 93 94 95 96 97 |
# File 'lib/libosctl/sys.rb', line 92 def mount_tmpfs(dst, name: 'none', flags: MS_MGC_VAL, options: 0) ret = Int.mount(name, dst, 'tmpfs', flags, ) raise SystemCallError, Fiddle.last_error if ret != 0 ret end |
#move_mount(src, dst) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/libosctl/sys.rb', line 62 def move_mount(src, dst) ret = Int.mount(src, dst, 0, MS_MGC_VAL | MS_MOVE, 0) raise SystemCallError, Fiddle.last_error if ret != 0 ret end |
#rbind_mount(src, dst) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/libosctl/sys.rb', line 85 def rbind_mount(src, dst) ret = Int.mount(src, dst, 0, MS_MGC_VAL | MS_BIND | MS_REC, 0) raise SystemCallError, Fiddle.last_error if ret != 0 ret end |
#setns_io(io, nstype) ⇒ Object
157 158 159 160 |
# File 'lib/libosctl/sys.rb', line 157 def setns_io(io, nstype) Native.setns(io.fileno, nstype) nil end |
#setns_path(path, nstype) ⇒ Object
148 149 150 151 152 153 154 155 |
# File 'lib/libosctl/sys.rb', line 148 def setns_path(path, nstype) f = File.open(path) Native.setns(f.fileno, nstype) nil ensure f.close if f end |
#setresgid(rgid, egid, sgid) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/libosctl/sys.rb', line 55 def setresgid(rgid, egid, sgid) ret = Int.setresgid(rgid, egid, sgid) raise SystemCallError, Fiddle.last_error if ret != 0 ret end |
#setresuid(ruid, euid, suid) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/libosctl/sys.rb', line 48 def setresuid(ruid, euid, suid) ret = Int.setresuid(ruid, euid, suid) raise SystemCallError, Fiddle.last_error if ret != 0 ret end |
#syncfs(path) ⇒ Object
195 196 197 198 199 200 201 202 203 204 |
# File 'lib/libosctl/sys.rb', line 195 def syncfs(path) f = Tempfile.new('.syncfs', path) ret = Int.syncfs(f.fileno) raise SystemCallError, Fiddle.last_error if ret != 0 ret ensure f.close f.unlink end |
#unmount(mountpoint) ⇒ Object
134 135 136 137 138 139 |
# File 'lib/libosctl/sys.rb', line 134 def unmount(mountpoint) ret = Int.umount2(mountpoint, 0) # force unmount returns EACCESS raise SystemCallError, Fiddle.last_error if ret != 0 ret end |
#unmount_lazy(mountpoint) ⇒ Object
141 142 143 144 145 146 |
# File 'lib/libosctl/sys.rb', line 141 def unmount_lazy(mountpoint) ret = Int.umount2(mountpoint, Int::MNT_DETACH) raise SystemCallError, Fiddle.last_error if ret != 0 ret end |
#unshare_ns(type) ⇒ Object
162 163 164 165 |
# File 'lib/libosctl/sys.rb', line 162 def unshare_ns(type) Native.unshare(type) nil end |