diff --git a/macro.h b/macro.h index a3b1d535..4afdc31a 100644 --- a/macro.h +++ b/macro.h @@ -14,6 +14,7 @@ #ifndef SICSMACRO #define SICSMACRO #include +#include "sics.h" #include "SCinter.h" Tcl_Interp *MacroInit(SicsInterp *pInter); diff --git a/sicscron.c b/sicscron.c index ce49d5d2..2621d945 100644 --- a/sicscron.c +++ b/sicscron.c @@ -11,7 +11,7 @@ #include #include #include -#include +#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,