diff --git a/ofac.c b/ofac.c index 6e7ba8d6..80d12407 100644 --- a/ofac.c +++ b/ofac.c @@ -246,6 +246,7 @@ AddCommand(pInter,"udpquieck",QuieckAction,KillQuieck,NULL); AddCommand(pInter,"alias",MakeAlias,NULL,NULL); AddCommand(pInter,"sicscron",MakeCron,NULL,NULL); + AddCommand(pInter,"dolater",MakeCron,NULL,NULL); AddCommand(pInter,"sicsdatafactory",SICSDataFactory,NULL,NULL); AddCommand(pInter,"scriptcallback",CallbackScript,NULL,NULL); AddCommand(pInter,"help",SicsHelp,KillHelp,NULL); diff --git a/sicscron.c b/sicscron.c index 2621d945..76536b5c 100644 --- a/sicscron.c +++ b/sicscron.c @@ -2,7 +2,7 @@ S I C S C R O N A cron like command facility for SICS which allows to repeat a command - at given time intervalls. + at given time intervals. copyright: see copyright.h @@ -19,7 +19,7 @@ typedef struct { - int iIntervall; + int iInterval; time_t tNext; char *pCommand; SConnection *pCon; @@ -57,13 +57,15 @@ pCron self = (pCron)pData; int iRet; Tcl_Interp *pTcl = pServ->pSics->pTcl; - + time_t now; + if(!self) { return 0; } - if(time(NULL) > self->tNext) + now = time(NULL); + if(now >= self->tNext) { MacroPush(self->pCon); old=StatisticsBegin(self->stat); @@ -76,9 +78,14 @@ self->iEnd = 0; return 0; } - self->tNext = time(NULL) + self->iIntervall; + if (self->iEnd == 2) { /* dolater command */ + self->iEnd = 0; + return 0; + } + self->tNext += self->iInterval; + if (now > self->tNext) self->tNext = now + 1; } - return self->iEnd; + return self->iEnd > 0; } /*-----------------------------------------------------------------------*/ static void CronSignal(void *pData, int iID, void *pSigData) @@ -112,15 +119,15 @@ /* enough arguments? */ if(argc < 3) { - SCWrite(pCon,"ERROR: not enough arguments to sicscron",eError); + SCPrintf(pCon,eError,"ERROR: not enough arguments to %s", argv[0]); return 0; } - /* interpret first argument as intervall in seconds */ + /* interpret first argument as interval in seconds */ iRet = Tcl_GetInt(pSics->pTcl,argv[1],&iVal); if(iRet != TCL_OK) { - SCWrite(pCon,"ERROR: failed to convert intervall argument to int", + SCWrite(pCon,"ERROR: failed to convert interval argument to int", eError); return 0; } @@ -146,10 +153,14 @@ /* transfer the rights to the dummy connection */ SCSetRights(pNew->pCon, rights); } - pNew->iIntervall = iVal; + pNew->iInterval = iVal; pNew->pCommand = cmd; - pNew->tNext = 0; - pNew->iEnd = 1; + pNew->tNext = time(NULL) + iVal; + if (strcasecmp(argv[0], "dolater") == 0) { + pNew->iEnd = 2; + } else { + pNew->iEnd = 1; + } pNew->stat = StatisticsNew(cmd); TaskRegister(pServ->pTasker,