7

Systemd offers unit files whom control monitoring of a certain path trough inotify: systemd.path(5). If a file or directory is modified in the watched path the corresponding systemd.service(5) is called.

According to the inotify(7) man page:

To determine what events have occurred, an application read(2)s from the inotify file descriptor. If no events have so far occurred, then, assuming a blocking file descriptor, read(2) will block until at least one event occurs (unless interrupted by a signal, in which case the call fails with the error EINTR; see signal(7)).

Each successful read(2) returns a buffer containing one or more of the following structures:

      struct inotify_event {
          int      wd;       /* Watch descriptor */
          uint32_t mask;     /* Mask of events */
          uint32_t cookie;   /* Unique cookie associating related
                                events (for rename(2)) */
          uint32_t len;      /* Size of name field */
          char     name[];   /* Optional null-terminated name */
      };

So if systemd see a change in the watched path, is there a way of getting any data from the read(2) command? Notably I need the name[] to be used as an argument to the command for the ExecStart= in the systemd.service(5) unit statement.

[Service]
ExecStart=/usr/bin/command --file=$inotifyName
  • Sure there is: can you program C? – MariusMatutiae Jan 25 '14 at 12:58
  • Nope. Just pointing out, that if a program is using inotify, it can include read(2), to work with the event. So how does systemd use it and can I use data from read(2) in a systemd unit file as a variable or specifier? – Tim Jan 25 '14 at 17:03
  • It does so from within a C program: read(2) is a system all, you can check it from man man. – MariusMatutiae Jan 25 '14 at 17:20
  • I know read(2) is a system call. I do not want to do anything with read(2). I want to run a command from a systemd.service file, triggered by a systemd.path file, which in turn uses inotify and I assume it uses something like read(2). I need the a string containing the filename that triggered the event appended to the ExecStart statement in the unit file. – Tim Jan 25 '14 at 19:09
  • 2
    Did you find out? I'm looking at running a script as well. – CMCDragonkai Jan 17 '16 at 5:45

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.