From d33a2523eeebcc26149535c38d8607a39a4c51df Mon Sep 17 00:00:00 2001 From: Viacheslav Sychov Date: Thu, 6 Oct 2022 10:01:21 +0200 Subject: [PATCH] fix: Handle /proc/1/sched missing error Reviewed-By: Rob Crittenden Reviewed-By: Alexander Bokovoy --- ipaserver/install/installutils.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/ipaserver/install/installutils.py b/ipaserver/install/installutils.py index 235645e79..36b04e870 100644 --- a/ipaserver/install/installutils.py +++ b/ipaserver/install/installutils.py @@ -1044,18 +1044,24 @@ def in_container(): systemd-detect-virt requires the whole systemd subsystem which isn't a reasonable require in a container. """ + data_sched = None if not is_hidepid(): - with open('/proc/1/sched', 'r') as sched: - data_sched = sched.readline() - else: - data_sched = [] + try: + with open('/proc/1/sched', 'r') as sched: + data_sched = sched.readline() + except (FileNotFoundError, PermissionError): + pass - with open('/proc/self/cgroup', 'r') as cgroup: - data_cgroup = cgroup.readline() + data_cgroup = None + try: + with open('/proc/self/cgroup', 'r') as cgroup: + data_cgroup = cgroup.readline() + except (FileNotFoundError, PermissionError): + pass checks = [ - data_sched.split()[0] not in ('systemd', 'init',), - data_cgroup.split()[0] in ('libpod'), + data_sched and data_sched.split()[0] not in ('systemd', 'init',), + data_cgroup and data_cgroup.split()[0] in ('libpod'), os.path.exists('/.dockerenv'), os.path.exists('/.dockerinit'), os.getenv('container', None) is not None