Yesterday I was asked a question as to whether it would be possible to automate a task such that when a file is saved locally, an action is triggered by the system to automatically transfer the file to a remote machine.

My answer to this is that is should be possible as every time a file is saved, an event is raised to update other applications and systems so it should be fairly trivial to implement.

Whilst digging around for a viable solution I came across a small C application called fslogger for mac which prints out a whole bunch of information whenever a file is updated.

Now on the face of it, this looks quite clean and despite having the first few characters of FSE_ARG_STRING missing each time, the information provided could potentially be quite useful.

The problem however, is fslogger needs to be run with root privileges which could cause other issues elsewhere when trying to use the data.

To get around this I’ve been playing around with named pipes in a short script but am now encountering some weirdness which I can’t work out the root cause.

The script itself is as follows:

When called without any arguments, it first sets up a named pipe in /tmp called ‘sysstate’ and attach a reader to it as a detached process.

The script then launches a new process to attach the writer to the pipe with root privileges. The 3 second sleep before the launch of ‘writer’ is to ensure that the reader has time to set itself up properly otherwise nothing seems to happen.

Now at face value this should be all that is needed, however the output from this script is nothing like the expected example we have above.

I would be grateful if anyone can explain why this is happening, I’ve been chasing my tail on it all morning without any result.

To get fslogger working on Mountain Lion run the following set of commands:

2 thoughts on “Bash pipe weirdness using fslogger

  1. Gremoz

    Hi Martin,

    thanks for a very useful post. Unfortunately I’m unable to compile fslogger on Mac OS Maverick. I’m getting following errors:

    Do you have any guesses what can be the problem? Could you also post you binary?

    1. Hi. Sorry for the delay in responding.

      It looks like your compiler is not POSIX compliant. I’ve not tried building on Maverick yet so don’t know what the compiler is configured with but the source for stdio.h carries this block:

      Try passing in a CC flag for _POSIX_C_SOURCE to gcc and re-compiling.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.