diff options
author | Lennart Poettering <lennart@poettering.net> | 2023-04-27 15:33:01 +0200 |
---|---|---|
committer | Luca Boccassi <luca.boccassi@gmail.com> | 2023-04-27 17:56:24 +0100 |
commit | dbecd3d6eeafb099bf946511d6885f74a0b80c9d (patch) | |
tree | 2ec5207174023d22c005283b55cc9846b47e00b1 /src/shutdown | |
parent | fd34e27fb9903c2e6de85d4cd5e0ca88ffc8f72f (diff) | |
download | systemd-dbecd3d6eeafb099bf946511d6885f74a0b80c9d.tar.gz |
shutdown: paranoia – close all fds we might get passed in
We don't expect any fds (beyond 0…2) to be passed from the service
manager into systemd-shutdown, but let's better be safe then sorry.
Diffstat (limited to 'src/shutdown')
-rw-r--r-- | src/shutdown/shutdown.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/shutdown/shutdown.c b/src/shutdown/shutdown.c index b1dac20c69..802be44a79 100644 --- a/src/shutdown/shutdown.c +++ b/src/shutdown/shutdown.c @@ -338,6 +338,12 @@ int main(int argc, char *argv[]) { char *arguments[3]; int cmd, r; + /* Close random fds we might have get passed, just for paranoia, before we open any new fds, for + * example for logging. After all this tool's purpose is about detaching any pinned resources, and + * open file descriptors are the primary way to pin resources. Note that we don't really expect any + * fds to be passed here. */ + (void) close_all_fds(NULL, 0); + /* The log target defaults to console, but the original systemd process will pass its log target in through a * command line argument, which will override this default. Also, ensure we'll never log to the journal or * syslog, as these logging daemons are either already dead or will die very soon. */ |