From 96b27fdf14b959f925cfcbba4785b0c8c1303b29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Mon, 29 May 2017 05:50:10 +0200 Subject: [PATCH] tools: ignore qvm-template-postprocess calls in chroot It require qubesd running. Firstboot will take care of it. --- qubesadmin/tools/qvm_template_postprocess.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/qubesadmin/tools/qvm_template_postprocess.py b/qubesadmin/tools/qvm_template_postprocess.py index c0f790f..45c4e73 100644 --- a/qubesadmin/tools/qvm_template_postprocess.py +++ b/qubesadmin/tools/qvm_template_postprocess.py @@ -211,9 +211,29 @@ def pre_remove(args): return 0 +def is_chroot(): + '''Detect if running inside chroot''' + try: + stat_root = os.stat('/') + stat_init_root = os.stat('/proc/1/root/.') + return ( + stat_root.st_dev != stat_init_root.st_dev or + stat_root.st_ino != stat_init_root.st_ino) + except IOError: + print('Stat failed, assuming not chroot', file=sys.stderr) + return False + + def main(args=None, app=None): '''Main function of qvm-template-postprocess''' args = parser.parse_args(args, app=app) + + if is_chroot(): + print('Running in chroot, ignoring request. Import template with:', + file=sys.stderr) + print(' '.join(sys.argv), file=sys.stderr) + return + if not args.really: parser.error('Do not call this tool directly.') if args.action == 'post-install':