Skip to main content

exec_reload

Function exec_reload 

Source
pub fn exec_reload(
    raw_fd: RawFd,
    nick: &str,
    server: &str,
    channels: &[String],
    keepalive_interval_ms: u64,
    keepalive_timeout_ms: u64,
) -> BoxError
Expand description

Hot-reload support: replace the running bot binary without dropping the IRC connection.

ยงHow it works

On Unix, a TCP socket is just an open file descriptor. When a process calls exec() the new process image inherits all file descriptors that do not have the FD_CLOEXEC flag set.

exec_reload exploits this:

  1. Clears FD_CLOEXEC on the live TCP socket fd so the new binary inherits it.
  2. Serialises the connection metadata (fd number, nick, server, channels, keepalive settings) into environment variables.
  3. Calls exec() to replace the current process image with the new binary. The PID does not change; the TCP connection is never closed.

The new binary calls crate::connection::State::try_inherit_from_env at startup. If the env vars are present it reconstructs a live State from the inherited fd instead of opening a new TCP connection.

This is the Unix-only implementation. On non-Unix targets the function is a no-op that returns Err.