diff --git a/pym/cl_fill.py b/pym/cl_fill.py index 51b43ac..db8f940 100644 --- a/pym/cl_fill.py +++ b/pym/cl_fill.py @@ -607,6 +607,13 @@ class fillVars(varsShare): else: return "" + def get_cl_chroot_status(self): + """Detect chroot mode by mtab content""" + try: + return "on" if self.isChroot(os.getpid()) else "off" + except: + return "off" + def get_os_scratch(self): """Current system is scratch""" if self.Get('os_root_type') == 'livecd': diff --git a/pym/cl_vars.py b/pym/cl_vars.py index e04142d..348d3dd 100644 --- a/pym/cl_vars.py +++ b/pym/cl_vars.py @@ -61,6 +61,9 @@ class Data: # paths to clt-template files cl_template_clt_path = {'hide':True} + # is shell in chroot + cl_chroot_status = {'hide':True} + # locale (at example: ru_RU.UTF-8) os_locale_locale = {'hide':True} diff --git a/pym/cl_vars_share.py b/pym/cl_vars_share.py index 81b9da8..53926fd 100644 --- a/pym/cl_vars_share.py +++ b/pym/cl_vars_share.py @@ -505,3 +505,21 @@ class varsShare: reRes = reVer.search(kernelVersion) if reRes: return reRes.group() + + reChroot = re.compile("^(?:_=.*bin/chroot|CHROOT=on)$",re.S) + + def isChroot(self,pid): + """Recursive detect chroot mode""" + if not os.access('/proc/%d/environ'%pid,R_OK): + return False + if filter(self.reChroot.match, + open('/proc/%d/environ'%pid,'r').read().split('\x00')): + return True + else: + ppid = filter(lambda x:x.startswith('PPid:'), + open('/proc/%d/status'%pid,'r').readlines())[0] + ppid = int(ppid.strip().partition('\t')[2]) + if ppid == 0: + return False + else: + return self.isChroot(ppid)