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

Support binding to file descriptors passed to the process #14

Open
drewwells opened this issue Nov 27, 2024 · 1 comment
Open

Support binding to file descriptors passed to the process #14

drewwells opened this issue Nov 27, 2024 · 1 comment

Comments

@drewwells
Copy link

drewwells commented Nov 27, 2024

Systemd can open root level ports and pass a socket to another process. This is helpful because the program can run in user-level permission but appear to be listening to port 80.

See golang port for an example of the idea: https://github.com/librespeed/speedtest-go/pull/35/files#diff-17bd1293d66c18344655b66a75ac56c5798e7407a1670834166b12ee3585ad2b

Rust similar code to activate this

use listenfd::ListenFd;
use std::net::TcpListener;

fn main() {
    let mut listenfd = ListenFd::from_env();
    
    // Try to get socket from systemd first
    let listener = match listenfd.take_tcp_listener(0).unwrap() {
        // Got socket from systemd
        Some(l) => l,
        // No systemd socket, create our own
        None => TcpListener::bind("0.0.0.0:80").unwrap()
    };
}
@SudoDios
Copy link
Collaborator

Yes, good idea 👍

SudoDios added a commit that referenced this issue Dec 1, 2024
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

2 participants