- raise Exception('Could not determine architecture')
-
-def umount(fs_dir):
- output = os.popen('/bin/umount %s 2>&1'%fs_dir).read()
- return ('device is busy' not in fs_dir)
-
-parser = OptionParser()
-parser.add_option("-n", "--nonet",
- action="store_true", dest="netns", default=False,
- help="Don't enter network namespace")
-parser.add_option("-m", "--nomnt",
- action="store_true", dest="mntns", default=False,
- help="Don't enter mount namespace")
-parser.add_option("-p", "--nopid",
- action="store_true", dest="pidns", default=False,
- help="Don't enter pid namespace")
-parser.add_option("-r", "--root",
- action="store_true", dest="root", default=False,
- help="Enter as root: be careful")
-
-(options, args) = parser.parse_args()
-
-try:
- slice_name = args[0]
-except IndexError:
- print "You must specify a vm name"
- exit(1)
-
-try:
- cmd = 'grep %s /proc/*/cgroup | grep freezer'%slice_name
- output = os.popen(cmd).readlines()
-except:
- print "Error finding slice %s"%slice_name
- exit(1)
-
-slice_spec = None
-
-for e in output:
+ raise Exception('Could not determine architecture for pid %s' % pid)
+
+
+def get_cgroup_subdirs_for_pid(pid):
+ cgroup_info_file = '/proc/%s/cgroup' % pid
+ cgroup_lines = open(cgroup_info_file).read().splitlines()
+
+ subdirs = {}
+ for line in cgroup_lines:
+ try:
+ _, cgroup_name, subdir = line.split(':')
+ subdirs[cgroup_name] = subdir
+ except Exception as e:
+ print("Error reading cgroup info: %s" % str(e))
+ pass
+
+ return subdirs
+
+
+def umount(fs_dir, opts=''):
+ output = os.popen('/bin/umount %s %s 2>&1' % (opts, fs_dir)).read()
+ return ('device is busy' not in output)
+
+
+def main():
+ parser = ArgumentParser()
+ parser.add_argument("-n", "--nonet",
+ action="store_true", dest="no_netns", default=False,
+ help="Don't enter network namespace")
+ parser.add_argument("-m", "--nomnt",
+ action="store_true", dest="no_mntns", default=False,
+ help="Don't enter mount namespace")
+ parser.add_argument("-p", "--nopid",
+ action="store_true", dest="no_pidns", default=False,
+ help="Don't enter pid namespace")
+ parser.add_argument("-r", "--root",
+ action="store_true", dest="root", default=False,
+ help="Enter as root: be careful")
+ parser.add_argument("-i", "--internal",
+ action="store_true", dest="internal", default=False,
+ help="does *not* prepend '-- -c' to arguments - or invoke lxcsu-internal")
+ parser.add_argument("-d", "--debug",
+ action='store_true', dest='debug', default=False,
+ help="debug option")
+ parser.add_argument("-s", "--nosliceuid",
+ action='store_true', dest="nosliceuid", default=False,
+ help="do not change to slice uid inside of slice")
+ parser.add_argument("-o", "--noslicehome",
+ action='store_true', dest="noslicehome", default=False,
+ help="do not change to slice home directory inside of slice")
+
+ if os.path.exists("/etc/lxcsu_default"):
+ defaults = parser.parse_args(
+ file("/etc/lxcsu_default", "r").read().split())
+ parser.set_defaults(**defaults.__dict__)
+
+ parser.add_argument("slice_name")
+ parser.add_argument("command_to_run", nargs="*")
+
+ args = parser.parse_args()
+ slice_name = args.slice_name
+
+ # support for either setting debug at the top of this file, or on the command-line
+ if args.debug:
+ global debug
+ debug = True
+
+ # somehow some older nodes won't be able to find the login name in /etc/passwd
+ # when this is done down the road, so compute slice_uid while in a safe env
+ # even though we don't use the slice_uid any more, this is still
+ # checked later on as a means to ensure existence of the slice account