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:
needs-restarting -s (dnf-utils);
else needrestart -b -r l, with NEEDRESTART_MODE=l as well, so it only lists, whatever needrestart.conf says;
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.
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).
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.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
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 -cargument with no stdin:needs-restarting -s(dnf-utils);needrestart -b -r l, withNEEDRESTART_MODE=las well, so it only lists, whateverneedrestart.confsays;/proc/<pid>/mapshas an executable mapping of a deleted file under/usr,/lib*,/bin,/sbinor/opt(DELETED_CODE_PATTERN). Shared memory, memfd, temporary files and data such as the locale archive do not count.For the
/procscan each PID becomes its systemd service through/proc/<pid>/cgroup, with the listening sockets' helpers. A process of a user's own systemd counts asuser@<uid>, a container's process is left out, and a process in no service (a login session, PID 1) is listed underprocesses. 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 realsh, and so is needrestart's list-only invocation. There are also tests for the deleted-code pattern againstgrep -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).