git://git.onelab.eu
/
util-vserver.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
471f8ae
)
Add method to enter a vserver
author
Steve Muir
<smuir@cs.princeton.edu>
Mon, 23 May 2005 19:22:42 +0000
(19:22 +0000)
committer
Steve Muir
<smuir@cs.princeton.edu>
Mon, 23 May 2005 19:22:42 +0000
(19:22 +0000)
python/vserver.py
patch
|
blob
|
history
diff --git
a/python/vserver.py
b/python/vserver.py
index
feeb026
..
282de70
100644
(file)
--- a/
python/vserver.py
+++ b/
python/vserver.py
@@
-7,8
+7,9
@@
import re
import linuxcaps
import passfdimpl
import linuxcaps
import passfdimpl
+import vserverimpl
-from vserver_vars import *
+from
util_
vserver_vars import *
CAP_SAFE = (linuxcaps.CAP_CHOWN |
linuxcaps.CAP_DAC_OVERRIDE |
CAP_SAFE = (linuxcaps.CAP_CHOWN |
linuxcaps.CAP_DAC_OVERRIDE |
@@
-25,16
+26,16
@@
CAP_SAFE = (linuxcaps.CAP_CHOWN |
linuxcaps.CAP_SYS_PTRACE)
#
linuxcaps.CAP_SYS_PTRACE)
#
-# XXX - these are the flags taken from chcontext.c, but they don't match
-# up with those apparently used by the kernel
+# these are the flags taken from the kernel linux/vserver/legacy.h
#
FLAGS_LOCK = 1
#
FLAGS_LOCK = 1
-FLAGS_SCHED = 2
+FLAGS_SCHED = 2
# XXX - defined in util-vserver/src/chcontext.c
FLAGS_NPROC = 4
FLAGS_PRIVATE = 8
FLAGS_NPROC = 4
FLAGS_PRIVATE = 8
-FLAGS_
FAKE
INIT = 16
+FLAGS_INIT = 16
FLAGS_HIDEINFO = 32
FLAGS_ULIMIT = 64
FLAGS_HIDEINFO = 32
FLAGS_ULIMIT = 64
+FLAGS_NAMESPACE = 128
@@
-53,7
+54,7
@@
class VServer:
if "nproc" in flags:
self.flags |= FLAGS_NPROC
self.remove_caps = ~CAP_SAFE
if "nproc" in flags:
self.flags |= FLAGS_NPROC
self.remove_caps = ~CAP_SAFE
-
print "%x %x" % (self.flags, ~self.remove_caps
)
+
self.ctx = int(self.config["S_CONTEXT"]
)
config_var_re = re.compile(r"^ *([A-Z_]+)=(.*)\n?$", re.MULTILINE)
config_var_re = re.compile(r"^ *([A-Z_]+)=(.*)\n?$", re.MULTILINE)
@@
-68,6
+69,10
@@
class VServer:
config[key] = val.strip('"')
return config
config[key] = val.strip('"')
return config
+ def __do_chroot(self):
+
+ return os.chroot("%s/%s" % (VROOTDIR, self.name))
+
def open(self, filename, mode = "r"):
(sendsock, recvsock) = passfdimpl.socketpair()
def open(self, filename, mode = "r"):
(sendsock, recvsock) = passfdimpl.socketpair()
@@
-75,7
+80,7
@@
class VServer:
if child_pid == 0:
try:
# child process
if child_pid == 0:
try:
# child process
-
os.chroot("%s/%s" % (VROOTDIR, self.name)
)
+
self.__do_chroot(
)
f = open(filename, mode)
passfdimpl.sendmsg(f.fileno(), sendsock)
os._exit(0)
f = open(filename, mode)
passfdimpl.sendmsg(f.fileno(), sendsock)
os._exit(0)
@@
-124,3
+129,12
@@
class VServer:
throw()
return os.fdopen(fd)
throw()
return os.fdopen(fd)
+
+ def enter(self):
+
+ state_file = open("/var/run/vservers/%s.ctx" % self.name, "w")
+ self.__do_chroot()
+ vserverimpl.chcontext(self.ctx, self.remove_caps)
+ print >>state_file, "S_CONTEXT=%d" % self.ctx
+ print >>state_file, "S_PROFILE=%s" % self.config.get("S_PROFILE", "")
+ state_file.close()