From 8228f2cad4df296d6f1903bb69765aaa4dacd3cb Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Wed, 26 Apr 2023 02:06:39 +0200 Subject: [PATCH] aqhomed: added option to let aqhomed stop after a given time period. used for valgrind tests. --- apps/aqhomed/main.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/apps/aqhomed/main.c b/apps/aqhomed/main.c index 783686e..61b594c 100644 --- a/apps/aqhomed/main.c +++ b/apps/aqhomed/main.c @@ -43,6 +43,7 @@ #include #include #include +#include #define I18N(msg) msg @@ -121,6 +122,10 @@ int main(int argc, char **argv) return 2; } + GWEN_DB_Group_free(dbArgs); + GWEN_Gui_SetGui(NULL); + GWEN_Gui_free(gui); + return 0; } @@ -131,6 +136,10 @@ int _serve(GWEN_DB_NODE *dbArgs) const char *pidFile; GWEN_MSG_ENDPOINT_MGR *emgr; int rv; + int timeout; + time_t startTime; + + startTime=time(NULL); rv=_setSignalHandlers(); if (rv<0) { @@ -138,6 +147,7 @@ int _serve(GWEN_DB_NODE *dbArgs) return rv; } + timeout=GWEN_DB_GetIntValue(dbArgs, "timeout", 0, 0); pidFile=GWEN_DB_GetCharValue(dbArgs, "pidfile", 0, "aqhomed.pid"); if (pidFile && *pidFile) { rv=_createPidFile(pidFile); @@ -156,11 +166,23 @@ int _serve(GWEN_DB_NODE *dbArgs) while(!stopService) { DBG_DEBUG(NULL, "Next loop"); AQH_MsgManager_LoopOnce(emgr); + + if (timeout) { + time_t now; + + now=time(NULL); + if ((now-startTime)>timeout) { + DBG_INFO(NULL, "Timeout, stopping service"); + break; + } + } } if (pidFile && *pidFile) remove(pidFile); + GWEN_MsgEndpointMgr_free(emgr); + return 0; } @@ -480,6 +502,17 @@ int _readArgs(int argc, char **argv, GWEN_DB_NODE *dbArgs) I18S("Specify the PID file"), I18S("Specify the PID file") }, + { + GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ + GWEN_ArgsType_Int, /* type */ + "timeout", /* name */ + 0, /* minnum */ + 1, /* maxnum */ + "T", /* short option */ + "timeout", /* long option */ + I18S("Specify timeout in second (default: no timeout)"), + I18S("Specify timeout in second (default: no timeout)") + }, { GWEN_ARGS_FLAGS_HELP | GWEN_ARGS_FLAGS_LAST, /* flags */ GWEN_ArgsType_Int, /* type */