fixed memory leaks, added cleanup code, added valgrind scripts to test binaries
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include "./init.h"
|
||||
#include "./fini.h"
|
||||
#include "./loop.h"
|
||||
#include "./cleanup.h"
|
||||
|
||||
#include <gwenhywfar/gwenhywfar.h>
|
||||
#include <gwenhywfar/logger.h>
|
||||
@@ -29,6 +30,14 @@
|
||||
|
||||
|
||||
|
||||
//#define CLEANUP_INTERVAL_IN_SECS (5*60)
|
||||
//#define WRITE_INTERVAL_IN_SECS (5*60)
|
||||
|
||||
#define CLEANUP_INTERVAL_IN_SECS (60)
|
||||
#define WRITE_INTERVAL_IN_SECS (60)
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* defines
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
@@ -48,6 +57,9 @@ static int _setupSigAction(struct sigaction *sa, int sig);
|
||||
static void _signalHandler(int s);
|
||||
#endif
|
||||
|
||||
static void _runService(AQHOME_STORAGE *aqh);
|
||||
static void _writeCurrentState(AQHOME_STORAGE *aqh);
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
@@ -106,10 +118,7 @@ int main(int argc, char **argv)
|
||||
return 2;
|
||||
}
|
||||
|
||||
while(!stopService) {
|
||||
DBG_DEBUG(NULL, "Next loop");
|
||||
AqHomeStorage_Loop(aqh, 2000);
|
||||
}
|
||||
_runService(aqh);
|
||||
|
||||
AqHomeStorage_Fini(aqh);
|
||||
AqHomeStorage_free(aqh);
|
||||
@@ -122,6 +131,67 @@ int main(int argc, char **argv)
|
||||
|
||||
|
||||
|
||||
void _runService(AQHOME_STORAGE *aqh)
|
||||
{
|
||||
time_t timeStart;
|
||||
time_t timeLastCleanup;
|
||||
time_t timeLastWrite;
|
||||
int timeout;
|
||||
|
||||
timeout=AqHomeStorage_GetTimeout(aqh);
|
||||
timeStart=time(NULL);
|
||||
timeLastCleanup=time(NULL);
|
||||
timeLastWrite=time(NULL);
|
||||
|
||||
while(!stopService) {
|
||||
time_t now;
|
||||
|
||||
DBG_DEBUG(NULL, "Next loop");
|
||||
AqHomeStorage_Loop(aqh, 2000);
|
||||
|
||||
now=time(NULL);
|
||||
|
||||
if (((int)difftime(now, timeLastCleanup))>CLEANUP_INTERVAL_IN_SECS) {
|
||||
DBG_INFO(NULL, "Cleanup time");
|
||||
AqHomeStorage_Cleanup(aqh);
|
||||
timeLastCleanup=now;
|
||||
}
|
||||
|
||||
if (((int)difftime(now, timeLastWrite))>WRITE_INTERVAL_IN_SECS) {
|
||||
DBG_INFO(NULL, "Write time");
|
||||
_writeCurrentState(aqh);
|
||||
timeLastWrite=now;
|
||||
}
|
||||
|
||||
|
||||
if (timeout && ((int)difftime(now, timeStart))>timeout) {
|
||||
DBG_INFO(NULL, "Timeout");
|
||||
_writeCurrentState(aqh);
|
||||
break;
|
||||
}
|
||||
} /* while */
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _writeCurrentState(AQHOME_STORAGE *aqh)
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv=AqHomeStorage_WriteStorageIfChanged(aqh);
|
||||
if (rv<0) {
|
||||
DBG_ERROR(NULL, "ATTENTION: Could not write storage statefile (%d)", rv);
|
||||
}
|
||||
|
||||
rv=AqHomeStorage_WriteServiceIfChanged(aqh);
|
||||
if (rv<0) {
|
||||
DBG_ERROR(NULL, "ATTENTION: Could not write current config (%d)", rv);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int _setSignalHandlers(void)
|
||||
{
|
||||
#ifdef HAVE_SIGNAL_H
|
||||
|
||||
Reference in New Issue
Block a user