Added a loglsisten command for listening into the log
This commit is contained in:
95
loglisten.c
Normal file
95
loglisten.c
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
/**
|
||||||
|
* This is a means to listen into the stream of log messages from the logv2
|
||||||
|
* logging system.
|
||||||
|
*
|
||||||
|
* Mark Koennecke, May 2016
|
||||||
|
*/
|
||||||
|
#include <sics.h>
|
||||||
|
#include <logv2.h>
|
||||||
|
#include <lld.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
From logv2.c
|
||||||
|
*/
|
||||||
|
extern int subsystemFromText(const char *text);
|
||||||
|
/*=============================================================================*/
|
||||||
|
static int listenerList;
|
||||||
|
static int callbackRegistered = 0;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
SConnection *pCon;
|
||||||
|
char subsystem[64];
|
||||||
|
} ListenEntry;
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
static void LogListenCallback(unsigned int severity, const char *timeStamp,
|
||||||
|
const char *subsystem,
|
||||||
|
const char *message, void *userData)
|
||||||
|
{
|
||||||
|
ListenEntry current;
|
||||||
|
int status, cleanupNeeded = 0;
|
||||||
|
|
||||||
|
status = LLDnodePtr2First(listenerList);
|
||||||
|
while(status != 0){
|
||||||
|
LLDnodeDataTo(listenerList,¤t);
|
||||||
|
if(strcmp(current.subsystem,subsystem) == 0) {
|
||||||
|
if(SCisConnected(current.pCon)){
|
||||||
|
SCPureSockWrite(current.pCon,(char *)message,eValue);
|
||||||
|
} else {
|
||||||
|
cleanupNeeded = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
status = LLDnodePtr2Next(listenerList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
lld lists sometimes get confused when deleting nodes on the fly.
|
||||||
|
This is why this has been put into a separate loop
|
||||||
|
*/
|
||||||
|
if(cleanupNeeded){
|
||||||
|
status = LLDnodePtr2First(listenerList);
|
||||||
|
while(status != 0){
|
||||||
|
LLDnodeDataTo(listenerList,¤t);
|
||||||
|
if(!SCisConnected(current.pCon)){
|
||||||
|
SCDeleteConnection(current.pCon);
|
||||||
|
LLDnodeDelete(listenerList);
|
||||||
|
}
|
||||||
|
status = LLDnodePtr2Next(listenerList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
static int LogListenAction(SConnection * pCon, SicsInterp * pSics,
|
||||||
|
void *pData, int argc, char *argv[])
|
||||||
|
{
|
||||||
|
ListenEntry listLog;
|
||||||
|
|
||||||
|
if(argc < 2){
|
||||||
|
SCWrite(pCon,"ERROR: need subsystem argument for loglisten", eError);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(subsystemFromText(argv[1]) < 0){
|
||||||
|
SCPrintf(pCon,eError, "ERROR: invalid subsystem %s specified", argv[1]);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
listLog.pCon = SCCopyConnection(pCon);
|
||||||
|
strncpy(listLog.subsystem,argv[1],sizeof(listLog.subsystem));
|
||||||
|
LLDnodeAppendFrom(listenerList,&listLog);
|
||||||
|
|
||||||
|
if(!callbackRegistered){
|
||||||
|
RegisterLogCallback(LogListenCallback,NULL);
|
||||||
|
callbackRegistered = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SCSendOK(pCon);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
void LogListenInit(void)
|
||||||
|
{
|
||||||
|
listenerList = LLDcreate(sizeof(ListenEntry));
|
||||||
|
AddCmd("loglisten", LogListenAction);
|
||||||
|
}
|
2
logv2.c
2
logv2.c
@ -202,7 +202,7 @@ static unsigned int sevFromText(const char *txt)
|
|||||||
return sev;
|
return sev;
|
||||||
}
|
}
|
||||||
/*=============================================================================*/
|
/*=============================================================================*/
|
||||||
static unsigned int subsystemFromText(const char *text)
|
int subsystemFromText(const char *text)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
static const char *subText[] = {"sys",
|
static const char *subText[] = {"sys",
|
||||||
|
2
make_gen
2
make_gen
@ -14,7 +14,7 @@ SOBJ = network.o ifile.o conman.o SCinter.o splitter.o passwd.o \
|
|||||||
sicsexit.o costa.o task.o $(FORTIFYOBJ) testprot.o\
|
sicsexit.o costa.o task.o $(FORTIFYOBJ) testprot.o\
|
||||||
macro.o ofac.o obpar.o obdes.o drive.o status.o intserv.o \
|
macro.o ofac.o obpar.o obdes.o drive.o status.o intserv.o \
|
||||||
devexec.o mumo.o mumoconf.o selector.o selvar.o fupa.o lld.o \
|
devexec.o mumo.o mumoconf.o selector.o selvar.o fupa.o lld.o \
|
||||||
lld_blob.o strrepl.o lin2ang.o fomerge.o \
|
lld_blob.o strrepl.o lin2ang.o fomerge.o loglisten.o \
|
||||||
script.o o2t.o alias.o stringdict.o sdynar.o \
|
script.o o2t.o alias.o stringdict.o sdynar.o \
|
||||||
histmem.o histdriv.o histsim.o interface.o callback.o \
|
histmem.o histdriv.o histsim.o interface.o callback.o \
|
||||||
event.o emon.o evcontroller.o evdriver.o simev.o perfmon.o \
|
event.o emon.o evcontroller.o evdriver.o simev.o perfmon.o \
|
||||||
|
1
ofac.c
1
ofac.c
@ -55,6 +55,7 @@ static void InitGeneral(void)
|
|||||||
INIT(InitTaskOBJ);
|
INIT(InitTaskOBJ);
|
||||||
INIT(RemoteObjectInit);
|
INIT(RemoteObjectInit);
|
||||||
INIT(Logv2Init);
|
INIT(Logv2Init);
|
||||||
|
INIT(LogListenInit);
|
||||||
INIT(SiteInit); /* site specific initializations */
|
INIT(SiteInit); /* site specific initializations */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user