[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Tail -f in lua, truncate aware?
- From: Justin Cormack <justin@...>
- Date: Fri, 28 Jun 2013 21:39:58 +0100
On Fri, Jun 28, 2013 at 9:34 PM, Coda Highland <chighland@gmail.com> wrote:
> On Fri, Jun 28, 2013 at 1:27 PM, Egil Hjelmeland
> <privat@egil-hjelmeland.no> wrote:
>> On 28. juni 2013 21:01, William Ahern wrote:
>>>
>>> On Fri, Jun 28, 2013 at 02:42:19PM +0200, Bernd Eggink wrote:
>>>>
>>>> On 28.06.2013 13:47, ms2008vip wrote:
>>>>
>>>>> I'd like to make the output of tail -F or something similar
>>>>> available to me in Lua without blocking or blocking.
>>>>> If the file gets truncated or log rotated, the program will
>>>>> detect
>>>>> it and will return to the start. This seems to be
>>>>> a level 1 question but looks strange to me. I just can't figure
>>>>> it
>>>>> out. Does anyone could share some code? TKS
>>>>>
>>>>
>>>> In Linux you can use poll() or rpoll() from the luaposix library
>>>> (https://github.com/luaposix/luaposix)
>>>
>>> poll doesn't work on regular files. Or rather, it's defined to immediately
>>> signal readiness, which makes it useless for this case.
>>>
>>> "Regular files shall always poll TRUE for reading and writing."
>>>
>>> -- http://www.opengroup.org/susv3xsh/poll.html
>>>
>>>
>>>
>> yes, by Bernd mentions output of process 'tail -F'. If he want output from
>> an other program into Lua, it will most likely involve a pipe or a fifo, and
>> pipes and fifos can be poll()'ed or select()'ed. Use a pipe if you want to
>> fork and exec the 'tail -F' directly from Lua, or just make a named
>> /path/to/fifo and do 'tail -F > /path/to/fifo'
>>
>>
>>
>> Egil
>>
>>
>
> For the record:
>
> tail -F works by polling the file. Every 1.0 seconds (configurable),
> it stat()s the file to see if the size has changed. If it's gotten
> larger, it reads from the end and outputs; if it's gotten smaller, it
> outputs the entire file.
>
> If it's been updated to use something like inotify, the docs on
> gnu.org haven't been updated to match (don't want to go dig out the
> source code at the moment), but I've got my suspicions it still just
> polls.
>
> /s/ Adam
>
It has...
strace tail -f /var/log/dmesg
....
inotify_init() = 4
inotify_add_watch(4, "/var/log/dmesg",
IN_MODIFY|IN_ATTRIB|IN_DELETE_SELF|IN_MOVE_SELF) = 1
fstat(3, {st_mode=S_IFREG|0640, st_size=56599, ...}) = 0
read(4,
- References:
- Tail -f in lua, truncate aware?, ms2008vip
- Re: Tail -f in lua, truncate aware?, Bernd Eggink
- Re: Tail -f in lua, truncate aware?, William Ahern
- Re: Tail -f in lua, truncate aware?, Egil Hjelmeland
- Re: Tail -f in lua, truncate aware?, Coda Highland