Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
unix-socket-server.cc File Reference
#include "nix/cmd/unix-socket-server.hh"
#include "nix/util/environment-variables.hh"
#include "nix/util/file-system.hh"
#include "nix/util/logging.hh"
#include "nix/util/signals.hh"
#include "nix/util/strings.hh"
#include "nix/util/unix-domain-socket.hh"
#include "nix/util/util.hh"
#include "nix/util/system-error.hh"
#include <ranges>
#include <sys/socket.h>
#include <sys/un.h>
#include <poll.h>
#include <sys/ucred.h>

Functions

PeerInfo nix::unix::getPeerInfo (Descriptor remote)
void nix::unix::serveUnixSocket (const ServeUnixSocketOptions &options, UnixSocketHandler handler)

Function Documentation

◆ getPeerInfo()

PeerInfo nix::unix::getPeerInfo ( Descriptor remote)

Get the identity of the caller, if possible.

◆ serveUnixSocket()

void nix::unix::serveUnixSocket ( const ServeUnixSocketOptions & options,
UnixSocketHandler handler )

Run a server loop that accepts connections and calls the handler for each.

This function handles:

  • systemd socket activation (via LISTEN_FDS environment variable)
  • Creating and binding a Unix domain socket if no activation is detected
  • Polling for incoming connections
  • Accepting connections

For each accepted connection, the handler is called with the connection file descriptor. The handler takes ownership of the file descriptor and is responsible for closing it when done.

This function never returns normally. It runs until interrupted (e.g., via SIGINT), at which point it throws Interrupted. Can be explicitly exited by throwing AbortServeSocket.

Parameters
optionsConfiguration for the server.
handlerCallback invoked for each accepted connection.