structering the core some more

This commit is contained in:
Axel Kittenberger 2018-03-27 09:14:53 +02:00
parent fc8c02a749
commit 2cb4c957da

View File

@ -12,26 +12,12 @@
#include "lsyncd.h" #include "lsyncd.h"
// FIXME check if all that headers are really required...
#include <sys/stat.h>
#include <sys/times.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/inotify.h> #include <sys/inotify.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <signal.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <syslog.h>
#include <math.h>
#include <time.h>
#include <unistd.h> #include <unistd.h>
#include <string.h>
#include <errno.h>
#define LUA_USE_APICHECK 1
#include <lua.h> #include <lua.h>
#include <lualib.h> #include <lualib.h>
#include <lauxlib.h> #include <lauxlib.h>
@ -84,8 +70,8 @@ static const uint32_t standard_event_mask =
static int static int
l_addwatch( lua_State *L ) l_addwatch( lua_State *L )
{ {
const char *path = luaL_checkstring( L, 1 ); char const * path = luaL_checkstring( L, 1 );
const char *imode = luaL_checkstring( L, 2 ); char const * imode = luaL_checkstring( L, 2 );
uint32_t mask = standard_event_mask; uint32_t mask = standard_event_mask;
// checks the desired inotify reaction mode // checks the desired inotify reaction mode
@ -164,9 +150,11 @@ l_addwatch( lua_State *L )
static int static int
l_rmwatch( lua_State *L ) l_rmwatch( lua_State *L )
{ {
int wd = luaL_checkinteger( L, 1 ); const int wd = luaL_checkinteger( L, 1 );
inotify_rm_watch( inotify_fd, wd ); inotify_rm_watch( inotify_fd, wd );
printlogf( L, "Inotify", "rmwatch()<-%d", wd ); printlogf( L, "Inotify", "rmwatch()<-%d", wd );
return 0; return 0;
} }
@ -233,10 +221,7 @@ handle_event(
} }
// cancel on ignored or resetting // cancel on ignored or resetting
if( event && ( IN_IGNORED & event->mask ) ) if( event && ( IN_IGNORED & event->mask ) ) return;
{
return;
}
if( event && event->len == 0 ) if( event && event->len == 0 )
{ {
@ -392,7 +377,7 @@ handle_event(
/* /*
| buffer to read inotify events into | buffer to read inotify events into
*/ */
static size_t readbuf_size = 2048; static size_t readbuf_size = 4196;
static char * readbuf = NULL; static char * readbuf = NULL;
@ -412,6 +397,7 @@ inotify_ready(
if( obs->fd != inotify_fd ) if( obs->fd != inotify_fd )
{ {
logstring( "Error", "internal failure, inotify_fd != obs->fd" ); logstring( "Error", "internal failure, inotify_fd != obs->fd" );
exit( -1 ); exit( -1 );
} }
@ -436,11 +422,8 @@ inotify_ready(
} }
} while( len < 0 && err == EINVAL ); } while( len < 0 && err == EINVAL );
if( len == 0 ) // no more inotify events
{ if( len == 0 ) break;
// no more inotify events
break;
}
if (len < 0) if (len < 0)
{ {
@ -458,9 +441,7 @@ inotify_ready(
int i = 0; int i = 0;
while( i < len && !hup && !term ) while( i < len && !hup && !term )
{ {
struct inotify_event *event = struct inotify_event *event = ( struct inotify_event * ) ( readbuf + i );
( struct inotify_event * )
(readbuf + i);
handle_event( L, event ); handle_event( L, event );
@ -478,10 +459,8 @@ inotify_ready(
// checks if there is an unary MOVE_FROM left in the buffer // checks if there is an unary MOVE_FROM left in the buffer
if( move_event ) if( move_event )
{ {
logstring( logstring( "Inotify", "handling unary move from." );
"Inotify",
"handling unary move from."
);
handle_event( L, NULL ); handle_event( L, NULL );
} }
} }
@ -514,6 +493,7 @@ inotify_tidy( struct observance *obs )
close( inotify_fd ); close( inotify_fd );
free( readbuf ); free( readbuf );
readbuf = NULL; readbuf = NULL;
} }
@ -546,6 +526,7 @@ open_inotify( lua_State *L )
close_exec_fd( inotify_fd ); close_exec_fd( inotify_fd );
non_block_fd( inotify_fd ); non_block_fd( inotify_fd );
observe_fd( inotify_fd, inotify_ready, NULL, inotify_tidy, NULL ); observe_fd( inotify_fd, inotify_ready, NULL, inotify_tidy, NULL );
} }