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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
Method 2
If the application is calling seek, then it is either broken, or is not meant to work on pipes. If the former, then it needs fixed. If the latter, then it expects the seek to actually work, so lieing and claiming it worked when it did not will almost certainly cause incorrect operation.
Also if the log file is replaced with a named pipe, then only one process could read from it at a time. It should be a socket instead.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0