From b3212c07865739d4e9e484bbc1d4ddca8b1e8437 Mon Sep 17 00:00:00 2001 From: Axel Kittenberger Date: Tue, 27 Mar 2018 09:09:07 +0200 Subject: [PATCH] structering the core some more --- CMakeLists.txt | 3 +- core/core.c | 79 ++---------------------------------------- core/inotify.c | 2 +- core/log.c | 2 +- core/{smem.c => mem.c} | 4 +-- core/{smem.h => mem.h} | 6 ++-- core/pipe.c | 2 +- 7 files changed, 12 insertions(+), 86 deletions(-) rename core/{smem.c => mem.c} (95%) rename core/{smem.h => mem.h} (78%) diff --git a/CMakeLists.txt b/CMakeLists.txt index b048169..16ecbe2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,8 @@ set( LSYNCD_SRC core/core.c core/log.c core/pipe.c - core/smem.c + core/mem.c + core/util.c mantle.c default.c ) diff --git a/core/core.c b/core/core.c index f2cb4be..8366b13 100644 --- a/core/core.c +++ b/core/core.c @@ -38,7 +38,8 @@ #include #include "log.h" -#include "smem.h" +#include "mem.h" +#include "util.h" #include "pipe.h" #ifdef WITH_INOTIFY @@ -164,30 +165,6 @@ sig_handler( int sig ) #endif -/* -| Returns the absolute path of a path. -| -| This is a wrapper to various C-Library differences. -*/ -char * -get_realpath( const char * rpath ) -{ - // uses c-library to get the absolute path -#ifdef __GLIBC__ - // in case of GLIBC the task is easy. - return realpath( rpath, NULL ); -#else -# warning having to use old style realpath() - // otherwise less so and requires PATH_MAX limit - char buf[ PATH_MAX] ; - char *asw = realpath( rpath, buf ); - if( !asw ) return NULL; - - return s_strdup( asw ); -#endif -} - - /*:::::::::::::::::::. :: Helper Routines '::::::::::::::::::::*/ @@ -212,58 +189,6 @@ static int mci = 0; static int callError; -/* -| Sets the close-on-exit flag of a file descriptor. -*/ -extern void -close_exec_fd( int fd ) -{ - int flags; - - flags = fcntl( fd, F_GETFD ); - - if( flags == -1 ) - { - logstring( "Error", "cannot get descriptor flags!" ); - exit( -1 ); - } - - flags |= FD_CLOEXEC; - - if( fcntl( fd, F_SETFD, flags ) == -1 ) - { - logstring( "Error", "cannot set descripptor flags!" ); - exit( -1 ); - } -} - - -/* -| Sets the non-blocking flag of a file descriptor. -*/ -extern void -non_block_fd( int fd ) -{ - int flags; - - flags = fcntl( fd, F_GETFL ); - - if( flags == -1 ) - { - logstring( "Error", "cannot get status flags!" ); - exit( -1 ); - } - - flags |= O_NONBLOCK; - - if( fcntl( fd, F_SETFL, flags ) == -1 ) - { - logstring( "Error", "cannot set status flags!" ); - exit( -1 ); - } -} - - /*::::::::::::::::. :: Observances ':::::::::::::::::*/ diff --git a/core/inotify.c b/core/inotify.c index 6e4c721..7ea11cf 100644 --- a/core/inotify.c +++ b/core/inotify.c @@ -36,7 +36,7 @@ #include #include -#include "smem.h" +#include "mem.h" #include "log.h" #include "inotify.h" diff --git a/core/log.c b/core/log.c index fc2dd06..44055fc 100644 --- a/core/log.c +++ b/core/log.c @@ -27,7 +27,7 @@ #include #include "log.h" -#include "smem.h" +#include "mem.h" #include "lsyncd.h" diff --git a/core/smem.c b/core/mem.c similarity index 95% rename from core/smem.c rename to core/mem.c index 873323c..03ba9ae 100644 --- a/core/smem.c +++ b/core/mem.c @@ -1,5 +1,5 @@ /* -| smem.c from Lsyncd - Live (Mirror) Syncing Demon +| mem.c from Lsyncd - Live (Mirror) Syncing Demon | | | Simple "secured" memory management. @@ -19,7 +19,7 @@ #include #include "lsyncd.h" -#include "smem.h" +#include "mem.h" #include "log.h" /* diff --git a/core/smem.h b/core/mem.h similarity index 78% rename from core/smem.h rename to core/mem.h index 8872f48..dd6effc 100644 --- a/core/smem.h +++ b/core/mem.h @@ -1,5 +1,5 @@ /* -| smem.h from Lsyncd - Live (Mirror) Syncing Demon +| mem.h from Lsyncd - Live (Mirror) Syncing Demon | | | Simple "secured" memory management. @@ -9,8 +9,8 @@ | Authors: Axel Kittenberger */ -#ifndef LSYNCD_SMEM_H -#define LSYNCD_SMEM_H +#ifndef LSYNCD_MEM_H +#define LSYNCD_MEM_H extern void * s_calloc( size_t nmemb, size_t size ); extern void * s_malloc( size_t size ); diff --git a/core/pipe.c b/core/pipe.c index 903f6e8..89c070f 100644 --- a/core/pipe.c +++ b/core/pipe.c @@ -20,7 +20,7 @@ //#include #include "log.h" -#include "smem.h" +#include "mem.h" #include "pipe.h"