Skip to content

Commit 47465e6

Browse files
committed
linux: fix parsing of old systemd 'type' right after boot
With old systemd (before 240), just after boot, the get_systemd_status_raw function fails with the following exception: ValueError: invalid literal for int() with base 10: '2 "star' Calling `print(path_and_id)` before parsing prints the following: /org/freedesktop/systemd1/unit/syslog_2eservice" 0 " /org/freedesktop/systemd1/unit/alsa_2drestore_2eservice" 0 " /org/freedesktop/systemd1/unit/dev_2dram0_2edevice" 0 " /org/freedesktop/systemd1/unit/multi_2duser_2etarget" 2 "start The last line causes the error which is fixed by this patch. Signed-off-by: Adam Trhon <[email protected]>
1 parent b2c745d commit 47465e6

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

labgridhelper/linux.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,10 @@ def get_systemd_status_raw(command):
8585
services[name]["active"] = next(data)
8686
services[name]["sub"] = next(data)
8787
services[name]["follow"] = next(data)
88-
path_and_id = next(data)
89-
pos = path_and_id.index('"')
90-
services[name]["path"] = path_and_id[:pos]
91-
services[name]["id"] = int(path_and_id[pos+1:-1].strip(" "))
92-
services[name]["type"] = path_and_id[path_and_id.rfind('"'):]
88+
path_and_id = next(data).split('\"')
89+
services[name]["path"] = path_and_id[0]
90+
services[name]["id"] = int(path_and_id[1].strip(" "))
91+
services[name]["type"] = path_and_id[2]
9392
services[name]["objpath"] = next(data)
9493

9594
return services

0 commit comments

Comments
 (0)