lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Mon, Aug 3, 2009 at 8:55 PM, Rob Hoelz<rob@hoelzro.net> wrote:
> I wrote a binding to Linux's inotify facility for Lua, and I'm
> announcing it here with the hope that someone other than myself will
> find it useful.

Compiled fine after a few Debian-specific issues about sys/inotify,
but there is a most curious bug. Here is my version of your test
script:

local inotify = require 'inotify'
local handle = inotify.init()
local wd = handle:addwatch('/home/sdonovan/aggregator/lasync',
inotify.IN_CREATE, inotify.IN_MOVE)

 local events = handle:read()

 for _, ev in ipairs(events) do
     print(ev.name .. ' was created or renamed')
 end

 handle:rmwatch(wd)
 handle:close()

And yes it worked, but only the ev.name was printed, the concat did not work.

This fixed it. On line 100, there was a

           lua_pushlstring(L, name, iev->len - 1);

which I needed to replace by

            char name[512];  // yes I know, arbitrary constant
            strncpy(name,iev->name,iev->len);
            name[iev->len] = '\0';
            lua_pushstring(L,name);

So it was a problem with not properly terminating the buffer with NUL ?

steve d.

(Linux debian 2.6.18-4-486 #1 Mon Mar 26 16:39:10 UTC 2007 i686 GNU/Linux)