Permalink
Browse files

tools, pyjailhouse: Fix offline mode of config generator

This addresses three issues that were introduced while factoring out the
sysfs parser from the the config generator:

 - sysfs_parser.root_dir cannot be set from outside of he module -
   introduce a setter function instead
 - we need to initialize the root dir prior to performing the jailhouse
   enabled check
 - os.path.join drops any earlier elements if a later one is an absolute
   path - switch back to plain '+'

Fixes: 20a8331 ("Splitting up helpers used in sysfs parsing")
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
  • Loading branch information...
jan-kiszka committed Jan 24, 2019
1 parent 5b7492a commit 8fe9186dc609182f50825a4958abafbc55693e65
Showing with 8 additions and 4 deletions.
  1. +6 −2 pyjailhouse/sysfs_parser.py
  2. +2 −2 tools/jailhouse-config-create
@@ -24,6 +24,10 @@

root_dir = "/"

def set_root_dir(dir):
global root_dir
root_dir = dir

inputs = {
'files': set(),
'files_opt': set(),
@@ -73,7 +77,7 @@ def check_input_listed(name, optional=False):
def input_open(name, mode='r', optional=False):
check_input_listed(name, optional)
try:
f = open(os.path.join(root_dir, name), mode)
f = open(root_dir + name, mode)
except Exception as e:
if optional:
return open("/dev/null", mode)
@@ -84,7 +88,7 @@ def input_open(name, mode='r', optional=False):
def input_listdir(dir, wildcards):
for w in wildcards:
check_input_listed(os.path.join(dir, w))
dirs = os.listdir(os.path.join(root_dir, dir))
dirs = os.listdir(root_dir + dir)
dirs.sort()
return dirs

@@ -243,6 +243,8 @@ if ((options.root is '/') and (os.geteuid() is not 0)):
print('ERROR: You have to be root to work on "/"!', file=sys.stderr)
sys.exit(1)

sysfs_parser.set_root_dir(options.root)

jh_enabled = input_readline('/sys/devices/jailhouse/enabled', True).rstrip()
if jh_enabled == '1':
print('ERROR: Jailhouse was enabled when collecting input files! '
@@ -253,8 +255,6 @@ if jh_enabled == '1':
IOAPIC_MAX_PINS = 120
int_src_count = IOAPIC_MAX_PINS

sysfs_parser.root_dir = options.root

(pcidevices, pcicaps, cnt) = sysfs_parser.parse_pcidevices()

int_src_count += cnt

0 comments on commit 8fe9186

Please sign in to comment.