mirror of
https://github.com/octoleo/lsyncd.git
synced 2024-12-04 19:03:17 +00:00
fixing again setting with new delay objects, cleanups
This commit is contained in:
parent
544f6066b7
commit
785a7dd503
63
inotify.c
63
inotify.c
@ -124,9 +124,9 @@ l_addwatch( lua_State *L )
|
||||
// kernel call to create the inotify watch
|
||||
int wd = inotify_add_watch( inotify_fd, path, mask );
|
||||
|
||||
if (wd < 0)
|
||||
if( wd < 0 )
|
||||
{
|
||||
if (errno == ENOSPC)
|
||||
if( errno == ENOSPC )
|
||||
{
|
||||
printlogf(
|
||||
L, "Error",
|
||||
@ -154,18 +154,18 @@ l_addwatch( lua_State *L )
|
||||
|
||||
|
||||
/*
|
||||
* Removes an inotify watch.
|
||||
*
|
||||
* param dir (Lua stack) numeric watch descriptor
|
||||
*
|
||||
* return nil
|
||||
*/
|
||||
* Removes an inotify watch.
|
||||
*
|
||||
* param dir (Lua stack) numeric watch descriptor
|
||||
*
|
||||
* return nil
|
||||
*/
|
||||
static int
|
||||
l_rmwatch(lua_State *L)
|
||||
l_rmwatch( lua_State *L )
|
||||
{
|
||||
int wd = luaL_checkinteger(L, 1);
|
||||
inotify_rm_watch(inotify_fd, wd);
|
||||
printlogf(L, "Inotify", "rmwatch()<-%d", wd);
|
||||
int wd = luaL_checkinteger( L, 1 );
|
||||
inotify_rm_watch( inotify_fd, wd );
|
||||
printlogf( L, "Inotify", "rmwatch()<-%d", wd );
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -173,7 +173,8 @@ l_rmwatch(lua_State *L)
|
||||
/*
|
||||
| Lsyncd's core's inotify functions.
|
||||
*/
|
||||
static const luaL_Reg linotfylib[] = {
|
||||
static const luaL_Reg linotfylib[ ] =
|
||||
{
|
||||
{ "addwatch", l_addwatch },
|
||||
{ "rmwatch", l_rmwatch },
|
||||
{ NULL, NULL}
|
||||
@ -215,6 +216,7 @@ handle_event(
|
||||
|
||||
// used to execute two events in case of unmatched MOVE_FROM buffer
|
||||
struct inotify_event *after_buf = NULL;
|
||||
|
||||
if( event && ( IN_Q_OVERFLOW & event->mask ) )
|
||||
{
|
||||
// and overflow happened, tells the runner
|
||||
@ -224,8 +226,11 @@ handle_event(
|
||||
{
|
||||
exit( -1 );
|
||||
}
|
||||
|
||||
lua_pop( L, 1 );
|
||||
|
||||
hup = 1;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -251,10 +256,10 @@ handle_event(
|
||||
move_event = false;
|
||||
}
|
||||
else if(
|
||||
move_event &&
|
||||
(
|
||||
!( IN_MOVED_TO & event->mask ) ||
|
||||
event->cookie != move_event_buf->cookie
|
||||
move_event
|
||||
&& (
|
||||
!( IN_MOVED_TO & event->mask )
|
||||
|| event->cookie != move_event_buf->cookie
|
||||
)
|
||||
)
|
||||
{
|
||||
@ -263,18 +268,21 @@ handle_event(
|
||||
logstring(
|
||||
"Inotify",
|
||||
"icore, changing unary MOVE_FROM into DELETE"
|
||||
)
|
||||
);
|
||||
|
||||
after_buf = event;
|
||||
|
||||
event = move_event_buf;
|
||||
|
||||
event_type = "Delete";
|
||||
|
||||
move_event = false;
|
||||
}
|
||||
else if(
|
||||
move_event &&
|
||||
(
|
||||
IN_MOVED_TO & event->mask ) &&
|
||||
event->cookie == move_event_buf->cookie
|
||||
)
|
||||
move_event
|
||||
&& ( IN_MOVED_TO & event->mask )
|
||||
&& event->cookie == move_event_buf->cookie
|
||||
)
|
||||
{
|
||||
// this is indeed a matched move */
|
||||
event_type = "Move";
|
||||
@ -290,10 +298,14 @@ handle_event(
|
||||
if( move_event_buf_size < el )
|
||||
{
|
||||
move_event_buf_size = el;
|
||||
|
||||
move_event_buf = s_realloc( move_event_buf, el );
|
||||
}
|
||||
|
||||
memcpy( move_event_buf, event, el );
|
||||
|
||||
move_event = true;
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
@ -346,6 +358,7 @@ handle_event(
|
||||
}
|
||||
|
||||
lua_pushstring( L, event_type );
|
||||
|
||||
if( event_type != MOVE )
|
||||
{
|
||||
lua_pushnumber( L, event->wd );
|
||||
@ -390,6 +403,7 @@ handle_event(
|
||||
| buffer to read inotify events into
|
||||
*/
|
||||
static size_t readbuf_size = 2048;
|
||||
|
||||
static char * readbuf = NULL;
|
||||
|
||||
|
||||
@ -511,11 +525,14 @@ inotify_tidy( struct observance *obs )
|
||||
"Error",
|
||||
"internal failure: inotify_fd != ob->fd"
|
||||
);
|
||||
|
||||
exit( -1 );
|
||||
}
|
||||
|
||||
close( inotify_fd );
|
||||
|
||||
free( readbuf );
|
||||
|
||||
readbuf = NULL;
|
||||
}
|
||||
|
||||
|
1
lsyncd.c
1
lsyncd.c
@ -2081,7 +2081,6 @@ daemonize(
|
||||
write_pidfile( L, pidfile );
|
||||
}
|
||||
|
||||
|
||||
// detaches the new process from the parent process
|
||||
sid = setsid( );
|
||||
|
||||
|
45
lsyncd.lua
45
lsyncd.lua
@ -723,6 +723,19 @@ local Delay = ( function
|
||||
self[ k_nt ].status = 'active'
|
||||
end
|
||||
|
||||
--
|
||||
-- Sets the delay status to 'wait'
|
||||
--
|
||||
local function wait
|
||||
(
|
||||
self, -- this delay
|
||||
alarm -- alarm for the delay
|
||||
)
|
||||
self[ k_nt ].status = 'wait'
|
||||
|
||||
self[ k_nt ].alarm = alarm
|
||||
end
|
||||
|
||||
--
|
||||
-- Creates a new delay.
|
||||
--
|
||||
@ -741,6 +754,7 @@ local Delay = ( function
|
||||
{
|
||||
blockedBy = blockedBy,
|
||||
setActive = setActive,
|
||||
wait = wait,
|
||||
[ k_nt ] =
|
||||
{
|
||||
etype = etype,
|
||||
@ -2129,7 +2143,7 @@ local Sync = ( function
|
||||
|
||||
if delay.status ~= 'active'
|
||||
then
|
||||
error('collecting a non-active process')
|
||||
error( 'collecting a non-active process' )
|
||||
end
|
||||
|
||||
local rc = self.config.collect(
|
||||
@ -2142,12 +2156,11 @@ local Sync = ( function
|
||||
log( 'Error', 'Critical exitcode.' )
|
||||
|
||||
terminate( -1 )
|
||||
end
|
||||
|
||||
if rc ~= 'again'
|
||||
elseif rc ~= 'again'
|
||||
then
|
||||
-- if its active again the collecter restarted the event
|
||||
removeDelay( self, delay )
|
||||
|
||||
log(
|
||||
'Delay',
|
||||
'Finish of ',
|
||||
@ -2159,8 +2172,6 @@ local Sync = ( function
|
||||
)
|
||||
else
|
||||
-- sets the delay on wait again
|
||||
delay.status = 'wait'
|
||||
|
||||
local alarm = self.config.delay
|
||||
|
||||
-- delays at least 1 second
|
||||
@ -2169,7 +2180,7 @@ local Sync = ( function
|
||||
alarm = 1
|
||||
end
|
||||
|
||||
delay.alarm = now( ) + alarm
|
||||
delay:wait( now( ) + alarm )
|
||||
end
|
||||
else
|
||||
log(
|
||||
@ -2187,13 +2198,9 @@ local Sync = ( function
|
||||
log( 'Error', 'Critical exitcode.' );
|
||||
|
||||
terminate( -1 )
|
||||
end
|
||||
|
||||
if rc == 'again'
|
||||
elseif rc == 'again'
|
||||
then
|
||||
-- sets the delay on wait again
|
||||
delay.status = 'wait'
|
||||
|
||||
local alarm = self.config.delay
|
||||
|
||||
-- delays at least 1 second
|
||||
@ -2206,18 +2213,12 @@ local Sync = ( function
|
||||
|
||||
for _, d in ipairs( delay )
|
||||
do
|
||||
d.alarm = alarm
|
||||
d.status = 'wait'
|
||||
d:wait( alarm )
|
||||
end
|
||||
end
|
||||
|
||||
for _, d in ipairs( delay )
|
||||
do
|
||||
if rc ~= 'again'
|
||||
then
|
||||
else
|
||||
for _, d in ipairs( delay )
|
||||
do
|
||||
removeDelay( self, d )
|
||||
else
|
||||
d.status = 'wait'
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user