X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lxcsu;h=3f22cc3c1d97e4bafd27fbad3fbe424952d2195f;hb=f350306fc4725bd74aa7a8ddc42d9ef8d29ec15b;hp=5756162e7bbf50a393913544679e0acd025ad9c9;hpb=e0abda420d460dc1a717193b2eabc564bd81feb1;p=lxc-userspace.git diff --git a/lxcsu b/lxcsu old mode 100755 new mode 100644 index 5756162..3f22cc3 --- a/lxcsu +++ b/lxcsu @@ -112,6 +112,7 @@ def main (): arch = 'x86_64' # Set sysctls specific to slice + sysctls = [] sysctl_dir = '/etc/planetlab/vsys-attributes/%s'%slice_name if (os.access(sysctl_dir,0)): entries = os.listdir(sysctl_dir) @@ -121,8 +122,8 @@ def main (): sysctl_file = '/'.join([sysctl_dir,e]) sysctl_name = e[len(prefix):] sysctl_val = open(sysctl_file).read() - os.system('sysctl -w %s=%s'%(sysctl_name,sysctl_val)) - + sysctls.append((sysctl_file, sysctl_name, sysctl_val)) + # Enter cgroups try: for subsystem in ['cpuset','memory','blkio']: @@ -164,14 +165,20 @@ def main (): if (not args.mntns): setns.chcontext('/proc/%s/ns/mnt'%pid) - - proc_mounted = False if (not os.access('/proc/self',0)): proc_mounted = True setns.proc_mount() - + for (sysctl_file, sysctl_name, sysctl_val) in sysctls: + for fn in ["/sbin/sysctl", "/usr/sbin/sysctl", "/bin/sysctl", "/usr/bin/sysctl"]: + if os.path.exists(fn): + os.system("mount -o remount,rw none /proc/sys") + os.system('%s -w %s=%s'%(fn, sysctl_name,sysctl_val)) + os.system("mount -o remount,ro none /proc/sys") + break + else: + print "Error: image does not have a sysctl binary" # cgroups is not yet LXC-safe, so we need to use the coarse grained access control # strategy of unmounting the filesystem @@ -215,7 +222,7 @@ def main (): if (not args.root): uid = getuid (slice_name) if not uid: - print "lxcsu-internal could not spot %s in /etc/passwd - exiting"%slice_name + print "lxcsu could not spot %s in /etc/passwd - exiting"%slice_name exit(1) exec_args = [arch,'/usr/sbin/capsh',cap_arg,'--uid=%s'%uid,'--','--login',]+args.command_to_run # once we can drop f12, it would be nicer to instead go for @@ -227,7 +234,7 @@ def main (): os.environ['HOME'] = '/home/%s'%slice_name os.environ['LD_PRELOAD'] = '/etc/planetlab/lib/bind_public.so' os.chdir("/home/%s"%(slice_name)) - print 'lxcsu-internal:execv:','/usr/bin/setarch',exec_args + if debug: print 'lxcsu:execv:','/usr/bin/setarch',exec_args os.execv('/usr/bin/setarch',exec_args) else: setns.proc_umount()