S6-FTRIG-LISTEN1(8)

πŸ“¦ version 2.15.1.0, in nixpkgs unstable

πŸ’– s6-ftrig-listen1(8) β€” System Manager's Manual vibes πŸ’–

okay so bestie, this is the s6-ftrig-listen1(8) page from the System Manager's Manual, and it's honestly kind of iconic: it subscribes first, then spawns the program, so the notification can't ghost you before you're listening. πŸŽ€


🌸 NAME 🌸

s6-ftrig-listen1 β€” subscribe to an s6-fifodir(7), then spawn a program, waiting for a pattern of events to occur on the fifodir.


✨ SYNOPSIS ✨

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

πŸ¦‹ DESCRIPTION πŸ¦‹

So <pink>s6-ftrig-listen1</pink> does the same thing as s6-ftrig-wait(8), with one major main-character upgrade: it can make sure the process that's sending the notifications is actually started after there's already a listener for those events. No missed-connection energy. πŸ’…

s6-ftrig-listen1 subscribes to fifodir.

Then it forks and execs prog... with all its arguments.

After that, it waits for the series of events received on fifodir to match regexp. And regexp must be an Extended Regular Expression[1] β€” that's the [1] link down in SEE ALSO, bestie. 🫢

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. Slay. ✨


πŸ’… 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.

πŸŽ€ EXAMPLES πŸŽ€

The following sequence of shell commands has a race condition. 😭 Not cute of the scheduler, honestly.

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(8) process starts sending β€œmessage” before the s6-ftrig-wait(8) 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

See? Listener first, notification second. Order matters, periodt. πŸ‘‘


🌈 SEE ALSO 🌈


πŸ‘‘ AUTHORS πŸ‘‘

  • Laurent Bercot
  • Alexis <flexibeast@gmail.com> (man page port)

signing off with the footer vibes: this is from Debian, dated September 29, 2021, for S6-FTRIG-LISTEN1(8) πŸ’…βœ¨

πŸ“¦ where this page comes from