Skip to content

needrestart: fix container detection on rootless podman#346

Open
89luca89 wants to merge 1 commit intoliske:masterfrom
89luca89:fix/rootless_podman_fix
Open

needrestart: fix container detection on rootless podman#346
89luca89 wants to merge 1 commit intoliske:masterfrom
89luca89:fix/rootless_podman_fix

Conversation

@89luca89
Copy link

@89luca89 89luca89 commented Sep 4, 2025

Right now /proc/1/environ might not be accessible in case of rootless podman containers, in case we're not using a pid namespace, for example:

default_distrobox:needrestart$ sudo cat /proc/1/environ
cat: /proc/1/environ: Permission denied
default_distrobox:needrestart$ sudo /usr/sbin/needrestart
readline() on closed filehandle HENV at /usr/sbin/needrestart line 79.
Use of uninitialized value in unpack at /usr/sbin/needrestart line 79.
readline() on closed filehandle HENV at /usr/sbin/needrestart line 79.
Use of uninitialized value in unpack at /usr/sbin/needrestart line 79.

This PR will instead use the current process' ppid to detect environ, so we're sure we have read access to it.

This is not a breaking change, it still works on rootful podman containers, and in namespaced pids.

Right now /proc/1/environ might not accessible in case of rootless podman
containers, in case we're not using a pid namespace, for example:

```
default_distrobox:needrestart$ sudo cat /proc/1/environ
cat: /proc/1/environ: Permission denied
default_distrobox:needrestart$ sudo /usr/sbin/needrestart
readline() on closed filehandle HENV at /usr/sbin/needrestart line 79.
Use of uninitialized value in unpack at /usr/sbin/needrestart line 79.
readline() on closed filehandle HENV at /usr/sbin/needrestart line 79.
Use of uninitialized value in unpack at /usr/sbin/needrestart line 79.
```

This PR will instead use the current process' ppid to detect environ, so
we're sure we have read access to it.

This is not a breaking change, it still works on rootful podman
containers, and in namespaced pids.

Signed-off-by: Luca Di Maio <luca.dimaio1@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant