s6

Mirror/fork of https://skarnet.org/software/s6/
git clone https://ccx.te2000.cz/git/s6
Log | Files | Refs | README | LICENSE

s6-ftrig-listen1.html (2972B)


      1 <html>
      2   <head>
      3     <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      4     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
      5     <meta http-equiv="Content-Language" content="en" />
      6     <title>s6: the s6-ftrig-listen1 program</title>
      7     <meta name="Description" content="s6: the s6-ftrig-listen1 program" />
      8     <meta name="Keywords" content="s6 command s6-ftrig-listen1 fifodir notification event listener subscriber receive" />
      9     <!-- <link rel="stylesheet" type="text/css" href="//skarnet.org/default.css" /> -->
     10   </head>
     11 <body>
     12 
     13 <p>
     14 <a href="index.html">s6</a><br />
     15 <a href="//skarnet.org/software/">Software</a><br />
     16 <a href="//skarnet.org/">skarnet.org</a>
     17 </p>
     18 
     19 <h1> The s6-ftrig-listen1 program </h1>
     20 
     21 <p>
     22 s6-ftrig-listen1 subscribes to a <a href="fifodir.html">fifodir</a>, then
     23 spawns a program, then waits for a pattern of events to occur on the fifodir.
     24 </p>
     25 
     26 <p>
     27 s6-ftrig-listen1 acts just as <a href="s6-ftrig-wait.html">s6-ftrig-wait</a>,
     28 except it can make sure that the process sending the notifications is actually
     29 started <em>after</em> there is a listener for those events.
     30 </p>
     31 
     32 <h2> Interface </h2>
     33 
     34 <pre>
     35      s6-ftrig-listen1 [ -t <em>timeout</em> ] <em>fifodir</em> <em>regexp</em> <em>prog...</em>
     36 </pre>
     37 
     38 <ul>
     39  <li> s6-ftrig-listen1 subscribes to <em>fifodir</em> </li>
     40  <li> It then forks and exec <em>prog...</em> with all its arguments </li>
     41  <li> It waits for the series of events received on <em>fifodir</em>
     42 to match <em>regexp</em>. <em>regexp</em> must be an
     43 <a href="https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_04">Extended
     44 Regular Expression</a>. </li>
     45  <li> When the series of read events matches <em>regexp</em>,
     46 s6-ftrig-listen1 prints the last event it received to stdout (one byte followed by a newline),
     47 then exits 0. </li>
     48 </ul>
     49 
     50 <h2> Options </h2>
     51 
     52 <ul>
     53  <li> <tt>-t <em>timeout</em></tt>&nbsp;: if the events on <em>fifodir</em> have not
     54 matched <em>regexp</em> after <em>timeout</em> milliseconds, print an error message on
     55 stderr and exit 1. By default, s6-ftrig-listen1 waits indefinitely for a matching series
     56 of events. </li>
     57 </ul>
     58 
     59 <h2> Usage example </h2>
     60 
     61 <p>
     62  The following sequence of shell commands has a race condition:
     63 </p>
     64 
     65 <p> <em>In terminal 1:</em> </p>
     66 <pre>
     67 s6-mkfifodir /tmp/toto
     68 s6-ftrig-wait /tmp/toto "message"
     69 </pre>
     70 
     71 <p> <em>Then in terminal 2</em> </p>
     72 <pre>
     73 s6-ftrig-notify /tmp/toto message
     74 </pre>
     75 
     76 <p>
     77  Depending on the operating system's scheduler, there is the possibility that
     78 the s6-ftrig-notify process starts sending "message" <em>before</em> the
     79 s6-ftrig-wait process has actually subscribed to <tt>/tmp/toto</tt>, in which
     80 case the notification will be missed. The following sequence of shell commands
     81 accomplishes the same goal in a reliable way, without the race condition:
     82 </p>
     83 
     84 <pre>
     85 s6-mkfifodir /tmp/toto
     86 s6-ftrig-listen1 /tmp/toto "message" s6-ftrig-notify /tmp/toto message
     87 </pre>
     88 
     89 </body>
     90 </html>