Skip to main content

Module socket_path

Module socket_path 

Source
Expand description

Unix socket paths that fit, checked where names and directories are chosen.

A Unix socket address has a fixed-size path field, and the OS reports an overflow only as an invalid argument, at bind or connect time, naming neither the length nor the limit. A service usually derives several sockets from one directory, so the one that overflows is often not the one anybody checked. Here a name is checked when it is written, as a const, and a directory once, against every socket it will hold.

use kunobi_daemon::socket_path::{SocketDir, SocketName};

const DAEMON: SocketName = SocketName::new("daemon.sock");
const CONTROL: SocketName = SocketName::new("daemon.ctl");

let dir = SocketDir::new("/tmp/kache-1f2e", &[DAEMON, CONTROL])?;
let control = dir.path(CONTROL)?;

Windows names a pipe after the path, which has no such limit, so every check passes there.

Structs§

SocketDir
A directory checked once against every socket it will hold.
SocketName
A socket file name, checked when it is constructed.

Constants§

MAX_NAME_BYTES
Longest socket name SocketName::new accepts. A name is a file name, not a place to spend the directory’s budget.
MAX_SOCKET_PATH_BYTES
Longest Unix socket path, in bytes, on this platform: sockaddr_un.sun_path less the NUL that terminates it. None where local endpoints are not Unix sockets.

Functions§

check_socket_path
Fails when socket is too long to bind or connect to as a Unix socket.
max_dir_bytes
Longest directory, in bytes, that still fits every socket in names, or None on a platform without the limit.