- added 'sicscron list' and 'dolater list' command
This commit is contained in:
43
sicscron.c
43
sicscron.c
@ -27,6 +27,11 @@
|
||||
Statistics *stat;
|
||||
} Cron, *pCron;
|
||||
|
||||
typedef struct {
|
||||
SConnection *pCon;
|
||||
int dolater;
|
||||
} CronListData;
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
static void KillCron(void *pData)
|
||||
{
|
||||
@ -92,15 +97,32 @@
|
||||
{
|
||||
pCron self = (pCron)pData;
|
||||
int *iInt;
|
||||
|
||||
struct tm tm;
|
||||
char datim[24];
|
||||
CronListData *data;
|
||||
|
||||
if(iID == SICSINT)
|
||||
{
|
||||
iInt = (int *)pSigData;
|
||||
if(*iInt >= eEndServer)
|
||||
{
|
||||
{
|
||||
self->iEnd = 0;
|
||||
}
|
||||
}
|
||||
if(iID == CRONLIST) {
|
||||
data = pSigData;
|
||||
if (self->iEnd == 2 && data->dolater) {
|
||||
tm = *localtime(&self->tNext);
|
||||
strftime(datim, sizeof datim, "%Y-%m-%d %T", &tm);
|
||||
SCPrintf(data->pCon, eStatus, "%s %s", datim,
|
||||
self->pCommand);
|
||||
} else if (self->iEnd == 1 && !data->dolater) {
|
||||
tm = *localtime(&self->tNext);
|
||||
strftime(datim, sizeof datim, "%Y-%m-%d %T", &tm);
|
||||
SCPrintf(data->pCon, eStatus, "%s %8d %s", datim,
|
||||
self->iInterval, self->pCommand);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------------------*/
|
||||
int MakeCron(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
@ -109,6 +131,7 @@
|
||||
pCron pNew = NULL;
|
||||
int iVal, iRet, rights;
|
||||
char *cmd;
|
||||
CronListData data;
|
||||
|
||||
/* need user priv. */
|
||||
if(!SCMatchRights(pCon,usUser))
|
||||
@ -116,6 +139,19 @@
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (argc == 2 && strcasecmp(argv[1], "list") == 0) {
|
||||
if (strcasecmp(argv[0], "dolater") == 0) {
|
||||
data.dolater = 1;
|
||||
SCPrintf(pCon, eError, "Date Time Command");
|
||||
} else {
|
||||
data.dolater = 0;
|
||||
SCPrintf(pCon, eError, "Date Time Interval Command");
|
||||
}
|
||||
data.pCon = pCon;
|
||||
TaskSignal(pServ->pTasker, CRONLIST, &data);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* enough arguments? */
|
||||
if(argc < 3)
|
||||
{
|
||||
@ -153,12 +189,13 @@
|
||||
/* transfer the rights to the dummy connection */
|
||||
SCSetRights(pNew->pCon, rights);
|
||||
}
|
||||
pNew->iInterval = iVal;
|
||||
pNew->pCommand = cmd;
|
||||
pNew->tNext = time(NULL) + iVal;
|
||||
if (strcasecmp(argv[0], "dolater") == 0) {
|
||||
pNew->iInterval = -1;
|
||||
pNew->iEnd = 2;
|
||||
} else {
|
||||
pNew->iInterval = iVal;
|
||||
pNew->iEnd = 1;
|
||||
}
|
||||
pNew->stat = StatisticsNew(cmd);
|
||||
|
Reference in New Issue
Block a user