Skip to main content

systemd

Function systemd 

Source
pub fn systemd() -> Result<Vec<InheritedListener>, InheritError>
Expand description

The listeners systemd passed to this process (socket activation). Reads LISTEN_PID (it must name this process, otherwise the variables were meant for another and the list is empty), LISTEN_PIDFDID where present (Linux: must match this process’s pidfd), LISTEN_FDS (at most 64), and LISTEN_FDNAMES. Every descriptor from 3 is verified (a socket, listening, TCP or Unix stream) before any is taken. Not started by systemd: an empty list. A second call returns what earlier calls (including systemd_named) left.

§Errors

BadCount, TooMany, NamesMismatch, PidFdMismatch, NotASocket, NotListening, WrongKind, Os; nothing is taken on an error.

use net_io::{AllowAll, ListenerSpec, ServerBuilder};
let mut builder = ServerBuilder::new();
for inherited in net_io::systemd()? {
    builder = builder.listener(ListenerSpec::adopt(inherited.handle));
}
let server = builder.handler(|conn| { conn.send_all(b"hi\n")?; Ok(()) }).gate(AllowAll).build()?;
server.open_door()?;
server.wait_for_stop();