Added handling of timeout cmd arg for valgrind test. fixed memory leaks.
This commit is contained in:
@@ -157,3 +157,12 @@ void AqHomed_SetDbFile(AQHOMED *aqh, const char *s)
|
||||
|
||||
|
||||
|
||||
int AqHomed_GetTimeout(const AQHOMED *aqh)
|
||||
{
|
||||
return aqh?aqh->timeout:0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -39,6 +39,8 @@ void AqHomed_SetPidFile(AQHOMED *aqh, const char *s);
|
||||
const char *AqHomed_GetDbFile(const AQHOMED *aqh);
|
||||
void AqHomed_SetDbFile(AQHOMED *aqh, const char *s);
|
||||
|
||||
int AqHomed_GetTimeout(const AQHOMED *aqh);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -41,6 +41,8 @@ struct AQHOMED {
|
||||
char *logFile;
|
||||
char *pidFile;
|
||||
|
||||
int timeout; /* timeout for run e.g. inside valgrind */
|
||||
|
||||
int nodeAddress;
|
||||
};
|
||||
|
||||
|
||||
@@ -101,6 +101,8 @@ int AqHomed_Init(AQHOMED *aqh, int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
aqh->timeout=GWEN_DB_GetIntValue(dbArgs, "timeout", 0, 0);
|
||||
|
||||
aqh->nodeAddress=GWEN_DB_GetIntValue(dbArgs, "nodeAddress", 0, AQHOMED_DEFAULT_NODEADDR);
|
||||
|
||||
_setupDb(aqh, dbArgs);
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static void _runService(AQHOMED *aqh);
|
||||
#ifdef HAVE_SIGNAL_H
|
||||
static int _setSignalHandlers(void);
|
||||
static int _setupSigAction(struct sigaction *sa, int sig);
|
||||
@@ -108,10 +109,7 @@ int main(int argc, char **argv)
|
||||
return 2;
|
||||
}
|
||||
|
||||
while(!stopService) {
|
||||
DBG_DEBUG(NULL, "Next loop");
|
||||
AqHomed_Loop(aqh, 2000);
|
||||
}
|
||||
_runService(aqh);
|
||||
|
||||
AqHomed_Fini(aqh);
|
||||
AqHomed_free(aqh);
|
||||
@@ -124,6 +122,30 @@ int main(int argc, char **argv)
|
||||
|
||||
|
||||
|
||||
void _runService(AQHOMED *aqh)
|
||||
{
|
||||
time_t timeStart;
|
||||
int timeout;
|
||||
|
||||
timeout=AqHomed_GetTimeout(aqh);
|
||||
timeStart=time(NULL);
|
||||
|
||||
while(!stopService) {
|
||||
AqHomed_Loop(aqh, 2000);
|
||||
if (timeout) {
|
||||
time_t now;
|
||||
|
||||
now=time(NULL);
|
||||
if (timeout && ((int)difftime(now, timeStart))>timeout) {
|
||||
DBG_INFO(NULL, "Timeout");
|
||||
break;
|
||||
}
|
||||
}
|
||||
} /* while */
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _setSignalHandlers(void)
|
||||
{
|
||||
#ifdef HAVE_SIGNAL_H
|
||||
|
||||
@@ -190,10 +190,14 @@ int _doWatch(GWEN_DB_NODE *dbArgs)
|
||||
|
||||
void _awaitAndPrintChanges(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds, const char *tmpl)
|
||||
{
|
||||
time_t tStart;
|
||||
|
||||
tStart=time(NULL);
|
||||
|
||||
for (;;) {
|
||||
GWEN_MSG *msg;
|
||||
|
||||
msg=Utils_WaitForSpecificIpcMessage(epTcp, AQH_MSGTYPE_IPC_DATA_DATACHANGED, timeoutInSeconds);
|
||||
msg=Utils_WaitForSpecificIpcMessage(epTcp, AQH_MSGTYPE_IPC_DATA_DATACHANGED, 2);
|
||||
if (msg) {
|
||||
uint16_t code;
|
||||
|
||||
@@ -207,6 +211,15 @@ void _awaitAndPrintChanges(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds, const
|
||||
GWEN_Msg_free(msg);
|
||||
}
|
||||
}
|
||||
if (timeoutInSeconds) {
|
||||
time_t now;
|
||||
|
||||
now=time(NULL);
|
||||
if ((int)(difftime(now, tStart))>=timeoutInSeconds) {
|
||||
DBG_INFO(NULL, "Timeout");
|
||||
break;
|
||||
}
|
||||
}
|
||||
} /* for */
|
||||
}
|
||||
|
||||
|
||||
@@ -163,9 +163,15 @@ int main(int argc, char **argv)
|
||||
rv=1;
|
||||
}
|
||||
|
||||
GWEN_Fini();
|
||||
GWEN_DB_Group_free(dbArgs);
|
||||
|
||||
AQH_Fini();
|
||||
|
||||
GWEN_Gui_SetGui(NULL);
|
||||
GWEN_Gui_free(gui);
|
||||
|
||||
GWEN_Fini();
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user