Does not delete unix sockets on shutdown

#20 · closed · 3 comments

View on GitHub ↗

Nemo157

```console > systemfd -s unix::$XDG_RUNTIME_DIR/ssh-agent.socket -- cargo run -- daemon -s ~> socket /run/user/1000/ssh-agent.socket (unix listener) Compiling sshagmux v0.1.0 (/home/nemo157/sources/sshagmux) Finished dev [unoptimized + debuginfo] target(s) in 3.02s Running `target/debug/sshagmux daemon -s` 2023-10-10T13:56:43.652739Z INFO sshagmux::app: getting systemd socket 2023-10-10T13:56:43.652898Z INFO sshagmux::app: bound to /run/user/1000/ssh-agent.socket ... ^C2023-10-10T14:12:13.742422Z INFO sshagmux: initial SIGINT, shutdown requested > systemfd -s unix::$XDG_RUNTIME_DIR/ssh-agent.socket -- cargo run -- daemon -s error: EADDRINUSE: Address already in use ``` From `man systemd.socket`: > A daemon listening on an `AF_UNIX` socket may, but does not need to, call `close(2)` on the received socket before exiting. However, it must not unlink the socket from a file system. When you `systemctl stop foobar.socket` it then unlinks the socket from the file system, so it similarly should be `systemfd`'s responsibility to delete the socket during shutdown so the service can be started again.

Comments

mitsuhiko

I wonder if it should unlink on startup. Since we `exec` there is not really a good way to shut down unless I keep a separate process around.

Nemo157

Hmmm, I would like if it errored if something else was using the socket (like in the above example I was replacing a `systemd` managed socket for testing, so if I forgot to `systemctl stop` it); but if there's not a nice way to do that I guess force overwriting it would be fine. Maybe with a `--force` flag to make it explicit?

mitsuhiko

I think the most common way to do this would be to delete before bind. Maybe it should only be done if nobody uses it.