Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 40 additions & 27 deletions src/sse-pkg/util/sonataInfoDisplay/logfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,19 @@

int Logfile::m_maxFd = 0;
fd_set Logfile::m_rfds;
time_t Logfile::m_lastStatusTime = -1;

/*
* Constructor
* Opens specified logfile & gathers information.
*
* @param filename name of file
*/
Logfile::Logfile(string filename)
Logfile::Logfile(string filename, Components *details)
{
m_logfile = filename;
openLogfile(m_logfile);
}

/*
* Destructor
* Does nothing.
*/
Logfile::~Logfile()
{
m_details = details;
}

/*
Expand All @@ -69,7 +63,7 @@ void Logfile::openLogfile(string filename)
m_fp = fopen(filename.c_str(), "a+");
if(m_fp == NULL)
{
// Change to stderr?
// FIXME: actually exit, then send this to stderr.
fprintf(stdout," Could not open %s, EXITING.\n", filename.c_str());
}

Expand All @@ -78,12 +72,10 @@ void Logfile::openLogfile(string filename)
{
Logfile::m_maxFd = m_fd;
}

struct stat stbuf;

if(fstat(m_fd, &stbuf) == 0)
{
m_inode = stbuf.st_ino;
m_inode = stbuf.st_ino;
}
else
{
Expand All @@ -100,13 +92,12 @@ void Logfile::checkRefresh()

if (stat(m_logfile.c_str(), &stbuf) == 0)
{

// The most likely reason the inode would be changed is if a new
// logfile has been created.
// If so, switch to reading the new file.
if (m_inode != stbuf.st_ino)
{
//FIXME: Need exception handling.
// FIXME: Needs exception handling.
if(fclose(m_fp) == 0)
{
openLogfile(m_logfile);
Expand Down Expand Up @@ -152,8 +143,14 @@ void Logfile::getLine(char *buf, unsigned long bufsize)
* @return the number of file descriptors ready for reading
*/

int Logfile::readLogfiles(list<Logfile> logfiles)
int Logfile::readLogfiles(list<Logfile>& logfiles, Screen *screen)
{
int linesSinceLastStatus = 0;

if(Logfile::m_lastStatusTime == -1)
{
Logfile::m_lastStatusTime = time(NULL);
}
FD_ZERO(&m_rfds);
FD_SET(0, &m_rfds);

Expand All @@ -166,7 +163,7 @@ int Logfile::readLogfiles(list<Logfile> logfiles)
struct timeval tv;

tv.tv_sec = 0;
tv.tv_usec = 200000; //1/5 second
tv.tv_usec = 200000; // 1/5 second

int retVal = -1;

Expand All @@ -176,15 +173,31 @@ int Logfile::readLogfiles(list<Logfile> logfiles)
// Consider a delay by e.g. opting out of &m_rfds for n passes when at EOF?
retVal = select(Logfile::m_maxFd + 1, &m_rfds, NULL, NULL, &tv);

return retVal;
}
for(it=logfiles.begin(); it != logfiles.end(); it++)
{
if(it->m_details != NULL)
{
char line[2048];

if(FD_ISSET(it->getFd(), &m_rfds))
{
it->getLine(line, sizeof(line) - 1);
if(line[0] != 0 && it->m_details->addWithFilter(line))
screen->paint(it->m_details);
linesSinceLastStatus++;
memset(line, 0, sizeof(line));
}
//FIXME: Hack--move to filter in some way?
if(linesSinceLastStatus > 0 &&
(int)(time(NULL) - Logfile::m_lastStatusTime) > 1)
{
linesSinceLastStatus = 0;
Logfile::m_lastStatusTime = time(NULL);
it->m_details->addWithFilter("====================================");
screen->paint(it->m_details);
}
}
}

/*
* Returns file descriptor set for reads.
*
* @return the file descriptor set for reads
*/
fd_set *Logfile::getDescriptors()
{
return &Logfile::m_rfds;
return retVal;
}
24 changes: 10 additions & 14 deletions src/sse-pkg/util/sonataInfoDisplay/logfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#include <sys/select.h>
#include <sys/stat.h>
#include <list>
#include "components.h"
#include "screen.h"

using namespace std;

Expand All @@ -58,13 +60,13 @@ using namespace std;
*
* @param filename name of file
*/
Logfile(string filename);
Logfile(string filename, Components *details);

/**
* Destructor
* Does nothing.
*/
~Logfile();
~Logfile() {};

/**
* Returns the logfile's file descriptor.
Expand All @@ -88,18 +90,7 @@ using namespace std;
*
* @return the number of file descriptors ready for reading
*/
static int readLogfiles(list<Logfile> logfiles);

/**
* Returns file descriptor set for reads.
*
* @return the file descriptor set for reads
*/
static fd_set *getDescriptors(); // FIXME: Will be
// private once all file
// handling is removed
// from main().

static int readLogfiles(list<Logfile>& logfiles, Screen *screen);

private:

Expand All @@ -116,6 +107,11 @@ using namespace std;
static int m_maxFd;
/** File-descriptor set used for select() reads */
static fd_set m_rfds;
/** Timestamp of most recently read status. */
static time_t m_lastStatusTime;

/** Input-line filter */
Components *m_details;

/**
* Open logfile.
Expand Down
56 changes: 6 additions & 50 deletions src/sse-pkg/util/sonataInfoDisplay/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@

#include "details.h"
#include "utils.h"
#include "screen.h"
#include "components.h"
#include "logfile.h"
#include <list>

Expand All @@ -70,7 +68,6 @@ int main(int argc, char **argv)
string systemLogFileName = "";
string systemErrorFileName = "";
Screen screen;
char line[2048];
list<Logfile> logfiles;

Components componentDetails;
Expand All @@ -90,64 +87,23 @@ int main(int argc, char **argv)
systemLogFileName = argv[2];
systemErrorFileName = argv[3];

Logfile systemStatusFile = Logfile(systemStatusFileName);
Logfile systemLogFile = Logfile(systemLogFileName);
Logfile systemErrorFile = Logfile(systemErrorFileName);
Logfile systemStatusFile = Logfile(systemStatusFileName, &componentDetails);
Logfile systemLogFile = Logfile(systemLogFileName, NULL);
Logfile systemErrorFile = Logfile(systemErrorFileName, NULL);

logfiles.push_back(systemStatusFile);
logfiles.push_back(systemLogFile);
logfiles.push_back(systemErrorFile);

//Initialize the curses screen.
// Initialize the curses screen.
screen.init();
screen.screenResize(0);

time_t lastStatusTime = time(NULL);;
int linesSinceLastStatus = 0;

//Loop foever
// Loop foever
while(1)
{

Logfile::readLogfiles(logfiles);

// FIXME: Move all the stuff below out of main!
// (Note the current clumsy use of Logfile::m_rfds.)

// Process any data read from the status file.
if(FD_ISSET(systemStatusFile.getFd(), Logfile::getDescriptors()))
{
systemStatusFile.getLine(line, sizeof(line) - 1);
if(line[0] != 0 && componentDetails.addWithFilter(line))
screen.paint(&componentDetails);
linesSinceLastStatus++;
memset(line, 0, sizeof(line));
}

//The trigger for the end of a status screen paint is "===..." but sometimes
//this does not arrive, so we have to force it.
if(linesSinceLastStatus > 0 && (int)(time(NULL) - lastStatusTime) > 1)
{
linesSinceLastStatus = 0;
lastStatusTime = time(NULL);
componentDetails.addWithFilter("====================================");
screen.paint(&componentDetails);
}

//Process the log file
if(FD_ISSET(systemLogFile.getFd(), Logfile::getDescriptors()))
{
}

//Process the error file
if(FD_ISSET(systemErrorFile.getFd(), Logfile::getDescriptors()))
{
}

Logfile::readLogfiles(logfiles, &screen);
screen.processKey(&componentDetails);
}


return 0;

}