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