statd: backport finit patch to fix 'show services'

Service descriptions or command arguments may contain special characters
that need to be escaped in JSON strings.

Example:

{
  ...
  "command": "udhcpc -f -p /run/dhcp-client-wan.pid -t 3 -T 5 -A 30 -a1000 -S -R -o -O 1 -O 3 -O 6 -O 12 -O 15 -O 28 -O 42 -i wan -V "NanoPi R2S"",
  ...
}

Also, wrap add_services() in a try/except instead of testing for keys.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2026-01-18 23:31:45 +01:00
parent d105178992
commit f23b14d15e
2 changed files with 144 additions and 14 deletions
+13 -14
View File
@@ -183,22 +183,21 @@ def add_services(out):
services = []
for d in data:
if "pid" not in d or "status" not in d or "identity" not in d or "description" not in d:
try:
services.append({
"pid": d["pid"],
"name": d["identity"],
"status": d["status"],
"description": d["description"],
"statistics": {
"memory-usage": str(d.get("memory", 0)),
"uptime": str(d.get("uptime", 0)),
"restart-count": int(d.get("restarts", 0))
}
})
except KeyError:
continue
entry = {
"pid": d["pid"],
"name": d["identity"],
"status": d["status"],
"description": d["description"],
"statistics": {
"memory-usage": str(d.get("memory", 0)),
"uptime": str(d.get("uptime", 0)),
"restart-count": int(d.get("restarts", 0))
}
}
services.append(entry)
insert(out, "infix-system:services", "service", services)
def add_software(out):