- added 'dolater' as single shot variant of the sicscron command

This commit is contained in:
zolliker
2007-02-23 12:13:45 +00:00
parent 4ddd6e8f3c
commit ebbde45f33
2 changed files with 24 additions and 12 deletions

1
ofac.c
View File

@ -246,6 +246,7 @@
AddCommand(pInter,"udpquieck",QuieckAction,KillQuieck,NULL); AddCommand(pInter,"udpquieck",QuieckAction,KillQuieck,NULL);
AddCommand(pInter,"alias",MakeAlias,NULL,NULL); AddCommand(pInter,"alias",MakeAlias,NULL,NULL);
AddCommand(pInter,"sicscron",MakeCron,NULL,NULL); AddCommand(pInter,"sicscron",MakeCron,NULL,NULL);
AddCommand(pInter,"dolater",MakeCron,NULL,NULL);
AddCommand(pInter,"sicsdatafactory",SICSDataFactory,NULL,NULL); AddCommand(pInter,"sicsdatafactory",SICSDataFactory,NULL,NULL);
AddCommand(pInter,"scriptcallback",CallbackScript,NULL,NULL); AddCommand(pInter,"scriptcallback",CallbackScript,NULL,NULL);
AddCommand(pInter,"help",SicsHelp,KillHelp,NULL); AddCommand(pInter,"help",SicsHelp,KillHelp,NULL);

View File

@ -2,7 +2,7 @@
S I C S C R O N S I C S C R O N
A cron like command facility for SICS which allows to repeat a command 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 copyright: see copyright.h
@ -19,7 +19,7 @@
typedef struct { typedef struct {
int iIntervall; int iInterval;
time_t tNext; time_t tNext;
char *pCommand; char *pCommand;
SConnection *pCon; SConnection *pCon;
@ -57,13 +57,15 @@
pCron self = (pCron)pData; pCron self = (pCron)pData;
int iRet; int iRet;
Tcl_Interp *pTcl = pServ->pSics->pTcl; Tcl_Interp *pTcl = pServ->pSics->pTcl;
time_t now;
if(!self) if(!self)
{ {
return 0; return 0;
} }
if(time(NULL) > self->tNext) now = time(NULL);
if(now >= self->tNext)
{ {
MacroPush(self->pCon); MacroPush(self->pCon);
old=StatisticsBegin(self->stat); old=StatisticsBegin(self->stat);
@ -76,9 +78,14 @@
self->iEnd = 0; self->iEnd = 0;
return 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) static void CronSignal(void *pData, int iID, void *pSigData)
@ -112,15 +119,15 @@
/* enough arguments? */ /* enough arguments? */
if(argc < 3) 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; return 0;
} }
/* interpret first argument as intervall in seconds */ /* interpret first argument as interval in seconds */
iRet = Tcl_GetInt(pSics->pTcl,argv[1],&iVal); iRet = Tcl_GetInt(pSics->pTcl,argv[1],&iVal);
if(iRet != TCL_OK) 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); eError);
return 0; return 0;
} }
@ -146,10 +153,14 @@
/* transfer the rights to the dummy connection */ /* transfer the rights to the dummy connection */
SCSetRights(pNew->pCon, rights); SCSetRights(pNew->pCon, rights);
} }
pNew->iIntervall = iVal; pNew->iInterval = iVal;
pNew->pCommand = cmd; pNew->pCommand = cmd;
pNew->tNext = 0; pNew->tNext = time(NULL) + iVal;
pNew->iEnd = 1; if (strcasecmp(argv[0], "dolater") == 0) {
pNew->iEnd = 2;
} else {
pNew->iEnd = 1;
}
pNew->stat = StatisticsNew(cmd); pNew->stat = StatisticsNew(cmd);
TaskRegister(pServ->pTasker, TaskRegister(pServ->pTasker,