- Fixed a bug in conman.c which could cause a core dump when terminating
a connection during an active run. - Added an additional output mode for the connection in order to support the batch run editor. - Made clientput send everything with eWarning mode in order to support the batch run editor. - Added a better NetReadTillTerm - Fixed a problem in synchronize.c - Fixed an issue with reading empty line on normal connection sockets. - Added a psi scan mode to mesure.c for TRICS - Made motor print warnings when trying to reposition. - Fixed abug in hkl.c which cause wrong signs. SKIPPED: psi/el734driv.c psi/el734hp.c psi/el737driv.c psi/el737hpdriv.c psi/nextrics.c psi/nxamor.c psi/psi.c psi/slsmagnet.c psi/swmotor2.c psi/tasscan.c psi/tasutil.c
This commit is contained in:
351
conman.c
351
conman.c
@ -25,6 +25,11 @@
|
||||
Added simulation mode
|
||||
Mark Koennecke, March 2003
|
||||
|
||||
Refactored a bit, removed SCWriteBinary (never used anywhere), added
|
||||
appending outcode to text,
|
||||
Mark Koennecke, July 2004
|
||||
|
||||
|
||||
Copyright: see copyright.h
|
||||
-----------------------------------------------------------------------------*/
|
||||
#include "fortify.h"
|
||||
@ -55,6 +60,9 @@
|
||||
|
||||
extern pServer pServ;
|
||||
|
||||
#include "outcode.c" /* text for OutCode */
|
||||
|
||||
|
||||
/*------ Max Size of Command Stack */
|
||||
#define MAXSTACK 100
|
||||
/*---------- Magic ID Header */
|
||||
@ -374,7 +382,7 @@ extern pServer pServ;
|
||||
return;
|
||||
}
|
||||
|
||||
if(pVictim->inUse > 0)
|
||||
if(SCActive(pVictim))
|
||||
{
|
||||
SCnoSock(pVictim);
|
||||
if(pVictim->pSock)
|
||||
@ -573,6 +581,54 @@ void SCSetWriteFunc(SConnection *self, writeFunc x)
|
||||
}
|
||||
self->write = x;
|
||||
}
|
||||
/*------------------------------------------------------------------------*/
|
||||
static int doSockWrite(SConnection *self, char *buffer)
|
||||
{
|
||||
int iRet = 1;
|
||||
|
||||
if(self->pSock)
|
||||
{
|
||||
if(self->iTelnet)
|
||||
{
|
||||
iRet = TelnetWrite(self->pSock,buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
iRet = NETWrite(self->pSock,buffer,strlen(buffer));
|
||||
if(!HasNL(buffer))
|
||||
{
|
||||
iRet = NETWrite(self->pSock,"\n",sizeof("\n"));
|
||||
}
|
||||
}
|
||||
if(!iRet)
|
||||
{
|
||||
SCnoSock(self);
|
||||
WriteToCommandLog("SYS> ","Connection broken on send");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
puts(buffer);
|
||||
}
|
||||
return iRet;
|
||||
}
|
||||
/*-------------------------------------------------------------------------*/
|
||||
static void writeToLogFiles(SConnection *self, char *buffer)
|
||||
{
|
||||
int i;
|
||||
for(i = 0; i < self->iFiles; i++)
|
||||
{
|
||||
if(self->pFiles[i])
|
||||
{
|
||||
fputs(buffer,self->pFiles[i]);
|
||||
if(! HasNL(buffer))
|
||||
{
|
||||
fputs("\n",self->pFiles[i]);
|
||||
fflush(self->pFiles[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static int SCNormalWrite(SConnection *self, char *buffer, int iOut)
|
||||
{
|
||||
@ -611,30 +667,7 @@ void SCSetWriteFunc(SConnection *self, writeFunc x)
|
||||
/* print it to client if error message */
|
||||
if((iOut== eError) || (iOut == eWarning) )
|
||||
{
|
||||
if(self->pSock)
|
||||
{
|
||||
if(self->iTelnet)
|
||||
{
|
||||
iRet = TelnetWrite(self->pSock,buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
iRet = NETWrite(self->pSock,buffer,strlen(buffer));
|
||||
if(!HasNL(buffer))
|
||||
{
|
||||
iRet = NETWrite(self->pSock,"\n",sizeof("\n"));
|
||||
}
|
||||
}
|
||||
if(!iRet)
|
||||
{
|
||||
SCnoSock(self);
|
||||
WriteToCommandLog("SYS> ","Connection broken on send");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
puts(buffer);
|
||||
}
|
||||
iRet = doSockWrite(self,buffer);
|
||||
}
|
||||
}
|
||||
else /* not in interpreter, normal logic */
|
||||
@ -644,45 +677,94 @@ void SCSetWriteFunc(SConnection *self, writeFunc x)
|
||||
return 0;
|
||||
|
||||
/* first the socket */
|
||||
iRet = doSockWrite(self,buffer);
|
||||
|
||||
writeToLogFiles(self,buffer);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static int SCWriteWithOutcode(SConnection *self, char *buffer, int iOut)
|
||||
{
|
||||
int i, iPtr, iRet, length;
|
||||
char pBueffel[80];
|
||||
char *bufPtr = NULL;
|
||||
|
||||
if(!VerifyConnection(self))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* log it for any case */
|
||||
if(self->pSock)
|
||||
{
|
||||
if(self->iTelnet)
|
||||
{
|
||||
iRet = TelnetWrite(self->pSock,buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
iRet = NETWrite(self->pSock,buffer,strlen(buffer));
|
||||
if(!HasNL(buffer))
|
||||
{
|
||||
iRet = NETWrite(self->pSock,"\n",strlen("\n"));
|
||||
}
|
||||
}
|
||||
if(!iRet)
|
||||
{
|
||||
SCnoSock(self);
|
||||
WriteToCommandLog("SYS> ","Send broken to connection");
|
||||
}
|
||||
{
|
||||
iRet = self->pSock->sockid;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s \n",buffer);
|
||||
}
|
||||
iRet = 0;
|
||||
}
|
||||
sprintf(pBueffel,"Next line intended for socket: %d",iRet);
|
||||
SICSLogWrite(pBueffel,eInternal);
|
||||
SICSLogWrite(buffer,iOut);
|
||||
|
||||
/* write to commandlog if user or manager privilege */
|
||||
if(SCGetRights(self) <= usUser)
|
||||
{
|
||||
sprintf(pBueffel,"To sock %d :",iRet);
|
||||
WriteToCommandLog(pBueffel,buffer);
|
||||
}
|
||||
|
||||
/* now all the possible logfiles */
|
||||
for(i = 0; i < self->iFiles; i++)
|
||||
/*
|
||||
prepare the message with the outcode appended.
|
||||
*/
|
||||
length = strlen(buffer) + strlen(pCode[iOut]) + 10;
|
||||
bufPtr = (char *)malloc(length * sizeof(char));
|
||||
if(!bufPtr)
|
||||
{
|
||||
SICSLogWrite("SYS>>ERROR: out of memory in SCWriteWithOutcode",eError);
|
||||
return 0;
|
||||
}
|
||||
memset(bufPtr,0,length*sizeof(char));
|
||||
strcpy(bufPtr,buffer);
|
||||
i = strlen(bufPtr);
|
||||
while(i-- > 0)
|
||||
{
|
||||
if(!isspace(bufPtr[i]))
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
bufPtr[i] = '\0';
|
||||
strcat(bufPtr,"@@");
|
||||
strcat(bufPtr,pCode[iOut]);
|
||||
strcat(bufPtr,"\r\n");
|
||||
|
||||
|
||||
/* put it into the interpreter if present */
|
||||
if(SCinMacro(self))
|
||||
{
|
||||
InterpWrite(self->pSics,buffer);
|
||||
/* print it to client if error message */
|
||||
if((iOut== eError) || (iOut == eWarning) )
|
||||
{
|
||||
if(self->pFiles[i])
|
||||
{
|
||||
fputs(buffer,self->pFiles[i]);
|
||||
if(! HasNL(buffer))
|
||||
{
|
||||
fputs("\n",self->pFiles[i]);
|
||||
fflush(self->pFiles[i]);
|
||||
}
|
||||
}
|
||||
iRet = doSockWrite(self,bufPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
else /* not in interpreter, normal logic */
|
||||
{
|
||||
/* is this really to be printed ? */
|
||||
if(iOut < self->iOutput)
|
||||
{
|
||||
free(bufPtr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* first the socket */
|
||||
iRet = doSockWrite(self,bufPtr);
|
||||
|
||||
writeToLogFiles(self,buffer);
|
||||
}
|
||||
free(bufPtr);
|
||||
return 1;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
@ -721,31 +803,8 @@ void SCSetWriteFunc(SConnection *self, writeFunc x)
|
||||
return 0;
|
||||
|
||||
/* the socket */
|
||||
if(self->pSock)
|
||||
{
|
||||
if(self->iTelnet)
|
||||
{
|
||||
iRet = TelnetWrite(self->pSock,buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
iRet = NETWrite(self->pSock,buffer,strlen(buffer));
|
||||
if(!HasNL(buffer))
|
||||
{
|
||||
iRet = NETWrite(self->pSock,"\n",sizeof("\n"));
|
||||
}
|
||||
}
|
||||
if(!iRet)
|
||||
{
|
||||
SCnoSock(self);
|
||||
WriteToCommandLog("SYS> ","Send broken to connection");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s \n",buffer);
|
||||
}
|
||||
}
|
||||
iRet = doSockWrite(self,buffer);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
@ -810,20 +869,8 @@ void SCSetWriteFunc(SConnection *self, writeFunc x)
|
||||
/* is this really to be printed ? */
|
||||
if(iOut < self->iOutput)
|
||||
return 0;
|
||||
|
||||
/* now all the possible logfiles */
|
||||
for(i = 0; i < self->iFiles; i++)
|
||||
{
|
||||
if(self->pFiles[i])
|
||||
{
|
||||
fputs(buffer,self->pFiles[i]);
|
||||
if(! HasNL(buffer))
|
||||
{
|
||||
fputs("\n",self->pFiles[i]);
|
||||
fflush(self->pFiles[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
writeToLogFiles(self,buffer);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@ -836,67 +883,6 @@ void SCSetWriteFunc(SConnection *self, writeFunc x)
|
||||
}
|
||||
self->write = SCFileWrite;
|
||||
}
|
||||
/*-------------------------------------------------------------------------*/
|
||||
int SCWriteBinary(SConnection *pCon, char *pComputer, int iPort,
|
||||
void *pData, int iDataLen)
|
||||
{
|
||||
int iRet;
|
||||
char pBueffel[1024];
|
||||
mkChannel *pChan = NULL;
|
||||
|
||||
assert(pCon);
|
||||
|
||||
/* do we have an identical connection already */
|
||||
if(pCon->pDataSock)
|
||||
{
|
||||
if(strcmp(pComputer,pCon->pDataComp) == 0 && (pCon->iDataPort == iPort))
|
||||
{
|
||||
pChan = pCon->pDataSock;
|
||||
}
|
||||
else /* rubbish, kill it */
|
||||
{
|
||||
NETClosePort(pCon->pDataSock);
|
||||
free(pCon->pDataSock);
|
||||
free(pCon->pDataComp);
|
||||
pCon->pDataSock = NULL;
|
||||
pCon->pDataComp = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* we have none, open it! */
|
||||
if(!pChan)
|
||||
{
|
||||
pChan = NETConnect(pComputer, iPort);
|
||||
if(!pChan)
|
||||
{
|
||||
sprintf(pBueffel,"ERROR: cannot connect to %s %d",pComputer, iPort);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
SCWrite(pCon,"EOFBINARYERROR",eValue);
|
||||
return 0;
|
||||
}
|
||||
pCon->pDataSock = pChan;
|
||||
pCon->pDataComp = strdup(pComputer);
|
||||
pCon->iDataPort = iPort;
|
||||
}
|
||||
|
||||
/* do the writing */
|
||||
iRet = NETWrite(pChan,pData,iDataLen);
|
||||
if(iRet != 1)
|
||||
{
|
||||
sprintf(pBueffel,"ERROR: failed to write data to %s %d",pComputer, iPort);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
SCWrite(pCon,"EOFBINARYERROR",eValue);
|
||||
NETClosePort(pChan);
|
||||
free(pCon->pDataSock);
|
||||
free(pCon->pDataComp);
|
||||
pCon->pDataSock = NULL;
|
||||
pCon->pDataComp = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
SCWrite(pCon,"EOFBINARYOK",eValue);
|
||||
return 1;
|
||||
}
|
||||
/*------------------------------------------------------------------------*/
|
||||
int SCWriteUUencoded(SConnection *pCon, char *pName, void *pData,
|
||||
int iDataLen)
|
||||
@ -1205,6 +1191,7 @@ void SCSetWriteFunc(SConnection *self, writeFunc x)
|
||||
char *pPtr = NULL;
|
||||
char pFrom[50];
|
||||
Status eOld;
|
||||
int oldMode;
|
||||
|
||||
if(!VerifyConnection(pCon))
|
||||
{
|
||||
@ -1217,8 +1204,16 @@ void SCSetWriteFunc(SConnection *self, writeFunc x)
|
||||
CostaUnlock(pCon->pStack);
|
||||
while(1)
|
||||
{
|
||||
/* wait a second */
|
||||
/*
|
||||
wait a second. We want to wait even in a simulation, otherwise
|
||||
we go into an endless loop. This is why there is the hack with
|
||||
oldMode and pServ->simMode.
|
||||
*/
|
||||
oldMode = pServ->simMode;
|
||||
pServ->simMode = 0;
|
||||
SicsWait(1);
|
||||
pServ->simMode = oldMode;
|
||||
|
||||
/* is there an interrupt pending ? */
|
||||
if(SCGetInterrupt(pCon) != eContinue)
|
||||
{
|
||||
@ -1366,8 +1361,8 @@ void SCSetWriteFunc(SConnection *self, writeFunc x)
|
||||
config OutCode val sets an new output code
|
||||
config Rights User Password sets and verifies new user rights
|
||||
config File Filename Logs to another file
|
||||
*/
|
||||
#include "outcode.c" /* text for OutCode */
|
||||
config output normal | withcode Sets output mode
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
int ConfigCon(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
int argc, char *argv[])
|
||||
@ -1472,6 +1467,25 @@ void SCSetWriteFunc(SConnection *self, writeFunc x)
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
}
|
||||
else if(strcmp(argv[1],"output") == 0)
|
||||
{
|
||||
strtolower(argv[2]);
|
||||
if(strcmp(argv[2],"normal") == 0)
|
||||
{
|
||||
SCSetWriteFunc(pCon,SCNormalWrite);
|
||||
}
|
||||
else if(strcmp(argv[2],"withcode") == 0)
|
||||
{
|
||||
SCSetWriteFunc(pCon,SCWriteWithOutcode);
|
||||
}
|
||||
else
|
||||
{
|
||||
SCWrite(pCon,"ERROT: output mode not recognised",eError);
|
||||
return 0;
|
||||
}
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
}
|
||||
else if(strcmp(argv[1],"rights") == 0)
|
||||
{
|
||||
if(argc < 4)
|
||||
@ -1697,7 +1711,7 @@ void SCSetWriteFunc(SConnection *self, writeFunc x)
|
||||
|
||||
if(self->iEnd)
|
||||
{
|
||||
if(self->inUse != 0)
|
||||
if(SCActive(self))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
@ -1768,7 +1782,7 @@ void SCSetWriteFunc(SConnection *self, writeFunc x)
|
||||
|
||||
if(self->iEnd)
|
||||
{
|
||||
if(self->inUse != 0)
|
||||
if(SCActive(self))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
@ -1828,3 +1842,16 @@ void SCparChange(SConnection *self)
|
||||
}
|
||||
self->parameterChange = 1;
|
||||
}
|
||||
/*------------------------------------------------------------------------*/
|
||||
int SCActive(SConnection *self)
|
||||
{
|
||||
if(self->inUse != 0 )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if(GetExeOwner(pServ->pExecutor) == self)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user