feat(services-restart): the services that still run replaced code (NetOrk/netork#2700) #132

Merged
christianmanivong merged 5 commits from feature/services-need-restart into main 2026-11-26 18:31:38 +00:00
Owner

ServicesRestartMixin.get_services_need_restart(): which systemd services still run code an update replaced on disk. After an openssl or glibc update every daemon that had the library loaded keeps the old code until it restarts; netOrk reads this to warn about it (NetOrk/netork#2700, option A: read it, show it, warn).

The reading. One fixed, read-only command, as root, sent as one sh -c argument with no stdin:

  1. needs-restarting -s (dnf-utils);
  2. else needrestart -b -r l, with NEEDRESTART_MODE=l as well, so it only lists, whatever needrestart.conf says;
  3. else (neither there, or both failed) every process whose /proc/<pid>/maps has an executable mapping of a deleted file under /usr, /lib*, /bin, /sbin or /opt (DELETED_CODE_PATTERN). Shared memory, memfd, temporary files and data such as the locale archive do not count.

For the /proc scan each PID becomes its systemd service through /proc/<pid>/cgroup, with the listening sockets' helpers. A process of a user's own systemd counts as user@<uid>, a container's process is left out, and a process in no service (a login session, PID 1) is listed under processes. Without root there is no reading: the parse raises, since a reading of the login user's processes would look clean.

Shape: {"source": "needs-restarting" | "needrestart" | "maps", "units": [...without .service], "processes": [{pid, name}]}.

Tests: tests/test_services_restart.py. The three sources give the same unit list from fixtures of one host. The order of preference is checked against stub tools on a real sh, and so is needrestart's list-only invocation. There are also tests for the deleted-code pattern against grep -E, for refused root, and for a run on the test host itself. The full suite passes (1922 passed, 3 skipped).

Release 4.44.0 (separate commit). napalm-linux carries it in NAPALM/napalm-linux (same branch name).

`ServicesRestartMixin.get_services_need_restart()`: which systemd services still run code an update replaced on disk. After an openssl or glibc update every daemon that had the library loaded keeps the old code until it restarts; netOrk reads this to warn about it (NetOrk/netork#2700, option A: read it, show it, warn). **The reading.** One fixed, read-only command, as root, sent as one `sh -c` argument with no stdin: 1. `needs-restarting -s` (dnf-utils); 2. else `needrestart -b -r l`, with `NEEDRESTART_MODE=l` as well, so it only lists, whatever `needrestart.conf` says; 3. else (neither there, or both failed) every process whose `/proc/<pid>/maps` has an executable mapping of a deleted file under `/usr`, `/lib*`, `/bin`, `/sbin` or `/opt` (`DELETED_CODE_PATTERN`). Shared memory, memfd, temporary files and data such as the locale archive do not count. For the `/proc` scan each PID becomes its systemd service through `/proc/<pid>/cgroup`, with the listening sockets' helpers. A process of a user's own systemd counts as `user@<uid>`, a container's process is left out, and a process in no service (a login session, PID 1) is listed under `processes`. Without root there is no reading: the parse raises, since a reading of the login user's processes would look clean. **Shape:** `{"source": "needs-restarting" | "needrestart" | "maps", "units": [...without .service], "processes": [{pid, name}]}`. **Tests:** `tests/test_services_restart.py`. The three sources give the same unit list from fixtures of one host. The order of preference is checked against stub tools on a real `sh`, and so is needrestart's list-only invocation. There are also tests for the deleted-code pattern against `grep -E`, for refused root, and for a run on the test host itself. The full suite passes (1922 passed, 3 skipped). Release 4.44.0 (separate commit). napalm-linux carries it in NAPALM/napalm-linux (same branch name).
christianmanivong added 2 commits 2026-11-26 16:40:38 +00:00
ServicesRestartMixin.get_services_need_restart reads, as root and in one
fixed read-only command, which systemd services still run code an update
replaced on disk: needs-restarting -s on the dnf family, else needrestart
in batch list-only mode (-r l and NEEDRESTART_MODE=l, whatever its config
says), else the processes whose /proc/<pid>/maps maps deleted code, each
named by its cgroup's service as the listening sockets are. A refused root
raises instead of reading clean.
chore(release): 4.44.0
driver / lint (pull_request) Successful in 17s
driver / standard (pull_request) Failing after 20s
driver / types (pull_request) Successful in 1m1s
driver / test (3.13) (pull_request) Successful in 1m14s
driver / test (3.12) (pull_request) Successful in 1m23s
driver / lowest (pull_request) Successful in 37s
driver / build (pull_request) Successful in 30s
driver / security (pull_request) Successful in 1m2s
CI / driver (pull_request) Failing after 2m36s
driver / publish (pull_request) Skipped
5517464e1f
christianmanivong added 1 commit 2026-11-26 18:06:23 +00:00
refactor(services-restart): its shapes live in its own module, within the quality ratchet
driver / standard (pull_request) Successful in 19s
driver / lint (pull_request) Successful in 15s
driver / types (pull_request) Successful in 1m8s
driver / test (3.13) (pull_request) Successful in 1m26s
driver / test (3.12) (pull_request) Successful in 1m30s
driver / lowest (pull_request) Successful in 46s
driver / build (pull_request) Successful in 32s
driver / security (pull_request) Successful in 1m7s
CI / driver (pull_request) Successful in 2m56s
driver / publish (pull_request) Skipped
494b9ed046
models.py had grown past its recorded size; ServicesRestartDict and
RestartProcessDict move to services_restart, exported from the package.
christianmanivong added 2 commits 2026-11-26 18:24:37 +00:00
# Conflicts:
#	CHANGELOG.md
chore(release): 4.45.0
driver / lint (pull_request) Successful in 14s
driver / standard (pull_request) Successful in 18s
driver / types (pull_request) Successful in 59s
driver / test (3.13) (pull_request) Successful in 1m16s
driver / test (3.12) (pull_request) Successful in 1m20s
driver / lowest (pull_request) Successful in 41s
driver / build (pull_request) Successful in 33s
driver / security (pull_request) Successful in 1m10s
CI / driver (pull_request) Successful in 2m44s
driver / publish (pull_request) Skipped
a38f07513f
christianmanivong merged commit ddc9316fb5 into main 2026-11-26 18:31:38 +00:00
christianmanivong deleted branch feature/services-need-restart 2026-11-26 18:31:38 +00:00
Sign in to join this conversation.