aqhomed: added option to let aqhomed stop after a given time period.
used for valgrind tests.
This commit is contained in:
@@ -43,6 +43,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
|
||||
#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 */
|
||||
|
||||
Reference in New Issue
Block a user