s6: the s6-ftrig-listen1 program
Keywords: s6 command s6-ftrig-listen1 fifodir notification event listener subscriber receive

s6
Software
skarnet.org

# The s6-ftrig-listen1 program

s6-ftrig-listen1 subscribes to a fifodir, then spawns a program, then waits for a pattern of events to occur on the fifodir.

s6-ftrig-listen1 acts just as s6-ftrig-wait, except it can make sure that the process sending the notifications is actually started after there is a listener for those events.

## Interface

         s6-ftrig-listen1 [ -t timeout ] fifodir regexp prog...

- s6-ftrig-listen1 subscribes to fifodir
- It then forks and exec prog... with all its arguments
- It waits for the series of events received on fifodir to match regexp. regexp must be an Extended Regular Expression.
- When the series of read events matches regexp, s6-ftrig-listen1 prints the last event it received to stdout (one byte followed by a newline), then exits 0.

## Options

- `-t timeout` : if the events on fifodir have not matched regexp after timeout milliseconds, print an error message on stderr and exit 1. By default, s6-ftrig-listen1 waits indefinitely for a matching series of events.

## Usage example

The following sequence of shell commands has a race condition:

In terminal 1:

    s6-mkfifodir /tmp/toto
    s6-ftrig-wait /tmp/toto "message"

Then in terminal 2

    s6-ftrig-notify /tmp/toto message

Depending on the operating system's scheduler, there is the possibility that the s6-ftrig-notify process starts sending "message" before the s6-ftrig-wait process has actually subscribed to `/tmp/toto`, in which case the notification will be missed. The following sequence of shell commands accomplishes the same goal in a reliable way, without the race condition:

    s6-mkfifodir /tmp/toto
    s6-ftrig-listen1 /tmp/toto "message" s6-ftrig-notify /tmp/toto message