Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide listen() variant that accepts listener #73

Open
Natureshadow opened this issue Mar 30, 2023 · 5 comments
Open

Provide listen() variant that accepts listener #73

Natureshadow opened this issue Mar 30, 2023 · 5 comments

Comments

@Natureshadow
Copy link

In order to use systemd socket activation, it would be good to provide a variant of listen that, instead of an address string, accepts a Listener.

@Natureshadow Natureshadow changed the title Provide listen() variatn that accepts listener Provide listen() variant that accepts listener Mar 30, 2023
@Natureshadow
Copy link
Author

Hmm, reading the code, it seems that passed sockets are silently listened on.

@Gunni
Copy link

Gunni commented Jan 26, 2024

It works fine, just listen on unix:///proc/self/fd/3.

You can test it using something like: systemd-socket-activate -l /tmp/test.sock -- cargo run bonus points by using idle timeout to exit when not needed 😁

This issue can be closed.

@Natureshadow
Copy link
Author

Natureshadow commented Jan 26, 2024 via email

@Gunni
Copy link

Gunni commented Jan 26, 2024

And to find out that the fd is 3, I use a dice ;)?

It's part of systemd socket activation https://www.freedesktop.org/software/systemd/man/latest/systemd-socket-activate.html

Otherwise, standard input and output will be inherited, and sockets will be passed through file descriptors 3 and higher.

ppentchev added a commit to ppentchev/varlink-rust that referenced this issue Oct 27, 2024
Listener::new() already records the fact that this listener is actually
a connection that has already been established via socket activation.
Let Listener::accept() honor that flag.

Fixes varlink#73.
@ppentchev
Copy link

I think there is one single piece missing before this issue can be closed. The current varlink crate goes halfway towards the socket activation - it parses the LISTEN_FDS and LISTEN_FDNAMES environment variables; however, it then still attempts to invoke accept() on the varlink socket, which IMHO is incorrect: I think the socket is supposed to be an already-accepted connection, or at least that's what systemd's varlinkctl program does when invoking a program to communicate with.

I have submitted a pull request, #105, to not invoke accept() in that case.

Thanks for having implemented the parsing part already, though!

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

No branches or pull requests

3 participants