Improvements to logParser and ResizeablePointer::append
This commit is contained in:
parent
5d0861d5ca
commit
94b6976dfa
1 changed files with 117 additions and 80 deletions
67
lib/util.cpp
67
lib/util.cpp
|
@ -214,8 +214,8 @@ namespace Util{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ResizeablePointer::append(const void *p, uint32_t l){
|
bool ResizeablePointer::append(const void *p, uint32_t l){
|
||||||
// We're writing to ourselves or from null pointer - assume outside write (e.g. fread or socket operation) and update the size
|
// We're writing from null pointer - assume outside write (e.g. fread or socket operation) and update the size
|
||||||
if (!p || p == ((char *)ptr) + currSize){
|
if (!p){
|
||||||
if (currSize + l > maxSize){
|
if (currSize + l > maxSize){
|
||||||
FAIL_MSG("Pointer write went beyond allocated size! Memory corruption likely.");
|
FAIL_MSG("Pointer write went beyond allocated size! Memory corruption likely.");
|
||||||
BACKTRACE;
|
BACKTRACE;
|
||||||
|
@ -306,8 +306,6 @@ namespace Util{
|
||||||
void callback(const std::string &, const std::string &, const std::string &, uint64_t, bool)){
|
void callback(const std::string &, const std::string &, const std::string &, uint64_t, bool)){
|
||||||
if (getenv("MIST_COLOR")){colored = true;}
|
if (getenv("MIST_COLOR")){colored = true;}
|
||||||
bool sysd_log = getenv("MIST_LOG_SYSTEMD");
|
bool sysd_log = getenv("MIST_LOG_SYSTEMD");
|
||||||
char buf[1024];
|
|
||||||
FILE *output = fdopen(in, "r");
|
|
||||||
char *color_time, *color_msg, *color_end, *color_strm, *CONF_msg, *FAIL_msg, *ERROR_msg,
|
char *color_time, *color_msg, *color_end, *color_strm, *CONF_msg, *FAIL_msg, *ERROR_msg,
|
||||||
*WARN_msg, *INFO_msg;
|
*WARN_msg, *INFO_msg;
|
||||||
if (colored){
|
if (colored){
|
||||||
|
@ -337,7 +335,16 @@ namespace Util{
|
||||||
WARN_msg = (char *)"";
|
WARN_msg = (char *)"";
|
||||||
INFO_msg = (char *)"";
|
INFO_msg = (char *)"";
|
||||||
}
|
}
|
||||||
while (fgets(buf, 1024, output)){
|
|
||||||
|
Socket::Connection O(-1, in);
|
||||||
|
O.setBlocking(true);
|
||||||
|
Util::ResizeablePointer buf;
|
||||||
|
while (O){
|
||||||
|
if (O.spool()){
|
||||||
|
while (O.Received().size()){
|
||||||
|
std::string & t = O.Received().get();
|
||||||
|
buf.append(t);
|
||||||
|
if (buf.size() && (buf.size() > 1024 || *t.rbegin() == '\n')){
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
char *kind = buf; // type of message, at begin of string
|
char *kind = buf; // type of message, at begin of string
|
||||||
char *progname = 0;
|
char *progname = 0;
|
||||||
|
@ -346,34 +353,57 @@ namespace Util{
|
||||||
char *strmNm = 0;
|
char *strmNm = 0;
|
||||||
char *message = 0;
|
char *message = 0;
|
||||||
while (i < 9 && buf[i] != '|' && buf[i] != 0 && buf[i] < 128){++i;}
|
while (i < 9 && buf[i] != '|' && buf[i] != 0 && buf[i] < 128){++i;}
|
||||||
if (buf[i] != '|'){continue;}// on parse error, skip to next message
|
if (buf[i] != '|'){
|
||||||
|
// on parse error, skip to next message
|
||||||
|
t.clear();
|
||||||
|
buf.truncate(0);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
buf[i] = 0; // insert null byte
|
buf[i] = 0; // insert null byte
|
||||||
++i;
|
++i;
|
||||||
progname = buf + i; // progname starts here
|
progname = buf + i; // progname starts here
|
||||||
while (i < 40 && buf[i] != '|' && buf[i] != 0){++i;}
|
while (i < 40 && buf[i] != '|' && buf[i] != 0){++i;}
|
||||||
if (buf[i] != '|'){continue;}// on parse error, skip to next message
|
if (buf[i] != '|'){
|
||||||
|
// on parse error, skip to next message
|
||||||
|
t.clear();
|
||||||
|
buf.truncate(0);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
buf[i] = 0; // insert null byte
|
buf[i] = 0; // insert null byte
|
||||||
++i;
|
++i;
|
||||||
progpid = buf + i; // progpid starts here
|
progpid = buf + i; // progpid starts here
|
||||||
while (i < 60 && buf[i] != '|' && buf[i] != 0){++i;}
|
while (i < 60 && buf[i] != '|' && buf[i] != 0){++i;}
|
||||||
if (buf[i] != '|'){continue;}// on parse error, skip to next message
|
if (buf[i] != '|'){
|
||||||
|
// on parse error, skip to next message
|
||||||
|
t.clear();
|
||||||
|
buf.truncate(0);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
buf[i] = 0; // insert null byte
|
buf[i] = 0; // insert null byte
|
||||||
++i;
|
++i;
|
||||||
lineno = buf + i; // lineno starts here
|
lineno = buf + i; // lineno starts here
|
||||||
while (i < 180 && buf[i] != '|' && buf[i] != 0){++i;}
|
while (i < 180 && buf[i] != '|' && buf[i] != 0){++i;}
|
||||||
if (buf[i] != '|'){continue;}// on parse error, skip to next message
|
if (buf[i] != '|'){
|
||||||
|
// on parse error, skip to next message
|
||||||
|
t.clear();
|
||||||
|
buf.truncate(0);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
buf[i] = 0; // insert null byte
|
buf[i] = 0; // insert null byte
|
||||||
++i;
|
++i;
|
||||||
strmNm = buf + i; // stream name starts here
|
strmNm = buf + i; // stream name starts here
|
||||||
while (i < 380 && buf[i] != '|' && buf[i] != 0){++i;}
|
while (i < 380 && buf[i] != '|' && buf[i] != 0){++i;}
|
||||||
if (buf[i] != '|'){continue;}// on parse error, skip to next message
|
if (buf[i] != '|'){
|
||||||
|
// on parse error, skip to next message
|
||||||
|
t.clear();
|
||||||
|
buf.truncate(0);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
buf[i] = 0; // insert null byte
|
buf[i] = 0; // insert null byte
|
||||||
++i;
|
++i;
|
||||||
message = buf + i; // message starts here
|
message = buf + i; // message starts here
|
||||||
// find end of line, insert null byte
|
// insert null byte for end of line
|
||||||
unsigned int j = i;
|
buf[buf.size()-1] = 0;
|
||||||
while (j < 1023 && buf[j] != '\n' && buf[j] != 0){++j;}
|
|
||||||
buf[j] = 0;
|
|
||||||
// print message
|
// print message
|
||||||
if (callback){callback(kind, message, strmNm, JSON::Value(progpid).asInt(), true);}
|
if (callback){callback(kind, message, strmNm, JSON::Value(progpid).asInt(), true);}
|
||||||
color_msg = color_end;
|
color_msg = color_end;
|
||||||
|
@ -415,8 +445,15 @@ namespace Util{
|
||||||
dprintf(out, "%s%s: %s%s", color_msg, kind, message, color_end);
|
dprintf(out, "%s%s: %s%s", color_msg, kind, message, color_end);
|
||||||
if (lineno && strlen(lineno)){dprintf(out, " (%s) ", lineno);}
|
if (lineno && strlen(lineno)){dprintf(out, " (%s) ", lineno);}
|
||||||
dprintf(out, "\n");
|
dprintf(out, "\n");
|
||||||
|
buf.truncate(0);
|
||||||
}
|
}
|
||||||
fclose(output);
|
t.clear();
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
Util::sleep(50);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close(out);
|
||||||
close(in);
|
close(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue