Is it possible to make seek() operations on a named pipe return successful

pipesyslog

Is there any way to make it so that when programs try to perform seek() operations on a named pipe it will come back successful (but act as if the pipe was an empty file) instead of 'Illegal seek'?

I have every last little bit of logging on my system stored in an SQLite database, I don't have files anywhere. However there are a few programs that have trouble with this. There are 2 specific cases;

  • A program wants to write to a log file which syslog-ng has created as a named pipe and is reading from. The program wants to perform a seek() for some reason and then fails.
  • A program (such as denyhosts or fail2ban) wants to read from a log file which syslog-ng has created as a named pipe and is writing to. The program wants to performs a seek() on it and fails.

Ideally I'd just like these seeks to behave as if the named pipe were just an empty file. I can't see any reason why a program writing a log would need to perform a seek anyway, it should just open the file for append and start writing. I can see why a program reading would want to seek, so that it could resume from its last position, and so I would like it to behave as if the file were empty (like it had been truncated).

So is there some option that can be set on named pipes to get them to behave this way? If not is there a mode that can be set when syslog-ng opens the pipe to have it behave this way (I'm open to making code changes)? Or am I up a creek?

Best Answer

Seekable pipes have been proposed for the Linux kernel, but I'm not aware of a working patch to implement them.

You could use an LD_PRELOAD'ed library that overrides the lseek call on specific files. I don't know of any off-the-shelf wrapper for this purpose. Shadowfs might help in writing one.