- improved sicscron
This commit is contained in:
34
sicscron.c
34
sicscron.c
@ -11,7 +11,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <time.h>
|
||||
#include <tcl.h>
|
||||
#include "macro.h"
|
||||
#include "fortify.h"
|
||||
#include "sics.h"
|
||||
#include "splitter.h"
|
||||
@ -24,6 +24,7 @@
|
||||
char *pCommand;
|
||||
SConnection *pCon;
|
||||
int iEnd;
|
||||
Statistics *stat;
|
||||
} Cron, *pCron;
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
@ -43,12 +44,19 @@
|
||||
{
|
||||
SCDeleteConnection(self->pCon);
|
||||
}
|
||||
if (self->stat) {
|
||||
StatisticsKill(self->stat);
|
||||
}
|
||||
free(self);
|
||||
}
|
||||
/*-----------------------------------------------------------------------*/
|
||||
static int CronTask(void *pData)
|
||||
{
|
||||
Statistics *old;
|
||||
|
||||
pCron self = (pCron)pData;
|
||||
int iRet;
|
||||
Tcl_Interp *pTcl = pServ->pSics->pTcl;
|
||||
|
||||
if(!self)
|
||||
{
|
||||
@ -57,7 +65,17 @@
|
||||
|
||||
if(time(NULL) > self->tNext)
|
||||
{
|
||||
SCInvoke(self->pCon,pServ->pSics,self->pCommand);
|
||||
MacroPush(self->pCon);
|
||||
old=StatisticsBegin(self->stat);
|
||||
iRet = Tcl_Eval(pTcl,self->pCommand);
|
||||
StatisticsEnd(old);
|
||||
MacroPop();
|
||||
if (iRet != TCL_OK) {
|
||||
SCPrintf(self->pCon, eStatus,
|
||||
"ERROR in sicscron script: %s", pTcl->result);
|
||||
self->iEnd = 0;
|
||||
return 0;
|
||||
}
|
||||
self->tNext = time(NULL) + self->iIntervall;
|
||||
}
|
||||
return self->iEnd;
|
||||
@ -82,11 +100,11 @@
|
||||
int argc, char *argv[])
|
||||
{
|
||||
pCron pNew = NULL;
|
||||
int iVal, iRet;
|
||||
int iVal, iRet, rights;
|
||||
char *cmd;
|
||||
|
||||
/* only managers may do this */
|
||||
if(!SCMatchRights(pCon,usMugger))
|
||||
/* need user priv. */
|
||||
if(!SCMatchRights(pCon,usUser))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -123,10 +141,16 @@
|
||||
SCWrite(pCon,"ERROR: out of memory in sicscron",eError);
|
||||
return 0;
|
||||
}
|
||||
rights = SCGetRights(pCon);
|
||||
if (rights > usMugger) {
|
||||
/* transfer the rights to the dummy connection */
|
||||
SCSetRights(pNew->pCon, rights);
|
||||
}
|
||||
pNew->iIntervall = iVal;
|
||||
pNew->pCommand = cmd;
|
||||
pNew->tNext = 0;
|
||||
pNew->iEnd = 1;
|
||||
pNew->stat = StatisticsNew(cmd);
|
||||
|
||||
TaskRegister(pServ->pTasker,
|
||||
CronTask,
|
||||
|
Reference in New Issue
Block a user