s6: the s6-ftrigrd program
Keywords: s6 command s6-ftrigrd program internal libexec fifodir regexp subscribe notification listener

libs6
s6
Software
skarnet.org

# The s6-ftrigrd internal program

s6-ftrigrd is a helper program that manages a set of subscriptions to fifodirs as well as regular expressions on events. It takes orders from its client program that controls it via the ftrigr library, and notifies it when desired events happen.

## Interface

s6-ftrigrd is not meant to be called directly. When the client calls `ftrigr_start()` or `ftrigr_startf()`, it spawns an instance of s6-ftrigrd as a child. s6-ftrigrd's stdin is a pipe reading from the client; its stdout is a pipe writing to the client; its stderr is the same as the client's; and there's an additional pipe from s6-ftrigrd to the client, used for asynchronous notifications.

When the client uses `ftrigr_end()`, or closes s6-ftrigrd's stdin in any way, s6-ftrigrd exits 0.

s6-ftrigrd handles the grunt work of creating fifos in a fifodir for a subscriber. It also wakes up on every event, and compares the chain of events it received on a given fifodir with the client-provided regexp. If the chain of events matches the regexp, it notifies the client.

## Notes

The connection management between the client and s6-ftrigrd is entirely done by the sassclient library from skalibs.

s6-ftrigrd is entirely asynchronous. It stores unread notifications into heap memory; it can grow in size if there are a lot of events and the client fails to read them. To avoid uncontrolled growth, make sure your client calls `ftrigr_update()` as soon as `ftrigr_fd()` becomes readable.

The number of concurrent subscriptions that an s6-ftrigrd instance can handle is only limited by RAM and open file descriptors. It is likely that the latter is the bottleneck: s6-ftrigrd uses two file descriptors per fifodir. With a default limit of 1024 open file descriptors per process, it means that s6-ftrigrd can handle around 500 concurrent fifodirs, which is reasonable for most systems, but make sure to increase the open files resource limit before starting an ftrigr session if you need more.