Name

local-seqpacket-socket-accept — accept incoming local socket connections and spawn a program per connection

Synopsis

local-seqpacket-socket-accept [--verbose] [--connection-limit number] [--localname hostname] {next-prog}

Description

local-seqpacket-socket-accept expects file descriptor 3 to be a socket that has been set up with local-seqpacket-socket-listen(1) to listen for incoming local socket connections. It loops forever, accepting local socket connections and (for each such connection) spawning next-prog, closing the listening socket in the child process and setting the connected socket as the child process' standard input and standard output.

next-prog may contain its own command line options, which local-seqpacket-socket-accept will ignore.

Following the UCSPI conventions, local-seqpacket-socket-accept sets up several environment variables containing information about the local socket connection.

PROTO

This always has the value UNIX.

UNIXLOCALPATH

The local (server) pathname of the socket.

UNIXREMOTEPATH

The remote (client) pathname of the socket.

UNIXREMOTEPID

The PID of the remote (client) process that connected.

UNIXREMOTEUID

The effective UID of the remote (client) process that connected.

UNIXREMOTEGID

The effective GID of the remote (client) process that connected.

If the --verbose option is used, local-seqpacket-socket-accept logs information about processes spawned and the current and maximum number of connections. The latter is set with the --connection-limit option, which defaults to 40. If it is reached, local-seqpacket-socket-accept stops accepting new connections until one or more child processes exit. local-seqpacket-socket-accept always limits the number of connections, and has no notion of an "unlimited" number of connections.

USAGE

local-seqpacket-socket-accept can be used

  • as a "socket-activated" daemon monitored by systemd(1) (with the systemd-recommended Accept=false),
  • as a daemon started by inetd(1) (with wait and as long as it is chained via fdmove 0 3 ), and
  • as a simple daemon chained from local-seqpacket-socket-listen(1) and monitored by service-manager(1).

Together, local-seqpacket-socket-accept and local-seqpacket-socket-listen(1) replace unixserver(1) from ucspi-unix.

To change the process' UID and GID after a successful call to accept(2), simply chain to setuidgid(1) or setuidgid-fromenv(1). This is, however, not usually necessary because unprivileged processes can accept any connections. It is preferable to chain local-seqpacket-socket-accept from setuidgid(1) or setuidgid-fromenv(1).

Author

Jonathan de Boyne Pollard