From 714f63a8395ad8ed491ad2c64fc73172af7b6733 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Thu, 4 Jul 2013 16:55:28 -0400 Subject: [PATCH] make STP_OOB_DATA treatment more stringent Since all STP_OOB_DATA originally comes from _stp_vlog() in runtime/linux/io.c, we can be sure that all warnings will be prefixed by "WARNING: " and all errors by "ERROR: ", as defined by WARN_STRING ERR_STRING in io.c. Therefore, we can be more stringent in control.c and mainloop.c in the way we identify warnings and errors. Additionally, warnings can instead use the warn() macro and errors the err() macro so that they benefit from coloring. The main effect of this patch is that all calls to _stp_warn() and _stp_error() will be colored upon reception by stapio. --- runtime/transport/control.c | 8 ++++---- staprun/mainloop.c | 16 ++++++++++------ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/runtime/transport/control.c b/runtime/transport/control.c index cbc8e6d55..0ddfbb3cd 100644 --- a/runtime/transport/control.c +++ b/runtime/transport/control.c @@ -337,14 +337,14 @@ static struct _stp_buffer *_stp_ctl_get_buffer(int type, void *data, /* Note that "WARNING:" should not be * translated, since it is part of the module * cmd protocol. */ - if (data && len >= 7 - && strncmp(data, "WARNING:", 7) == 0) + if (data && len >= 9 + && strncmp(data, "WARNING: ", 9) == 0) bptr = _stp_ctl_oob_warn; /* Note that "ERROR:" should not be * translated, since it is part of the module * cmd protocol. */ - else if (data && len >= 5 - && strncmp(data, "ERROR:", 5) == 0) + else if (data && len >= 7 + && strncmp(data, "ERROR: ", 7) == 0) bptr = _stp_ctl_oob_err; else printk(KERN_WARNING "_stp_ctl_get_buffer unexpected STP_OOB_DATA\n"); diff --git a/staprun/mainloop.c b/staprun/mainloop.c index 9035c8cd6..d5c61b18a 100644 --- a/staprun/mainloop.c +++ b/staprun/mainloop.c @@ -658,10 +658,11 @@ int stp_main_loop(void) case STP_OOB_DATA: /* Note that "WARNING:" should not be translated, since it is * part of the module cmd protocol. */ - if (strncmp(recvbuf.payload.data, "WARNING:", 7) == 0) { + if (strncmp(recvbuf.payload.data, "WARNING: ", 9) == 0) { if (suppress_warnings) break; if (verbose) { /* don't eliminate duplicates */ - eprintf("%.*s", (int) nb, recvbuf.payload.data); + /* trim "WARNING: " */ + warn("%.*s", (int) nb-9, recvbuf.payload.data+9); break; } else { /* eliminate duplicates */ static void *seen = 0; @@ -671,13 +672,15 @@ int stp_main_loop(void) if (! dupstr) { /* OOM, should not happen. */ - eprintf("%.*s", (int) nb, recvbuf.payload.data); + /* trim "WARNING: " */ + warn("%.*s", (int) nb-9, recvbuf.payload.data+9); break; } retval = tfind (dupstr, & seen, (int (*)(const void*, const void*))strcmp); if (! retval) { /* new message */ - eprintf("%s", dupstr); + /* trim "WARNING: " */ + warn("%.*s", strlen(dupstr)-9, dupstr+9); /* We set a maximum for stored warning messages, to prevent a misbehaving script/environment @@ -711,8 +714,9 @@ int stp_main_loop(void) } /* duplicate elimination */ /* Note that "ERROR:" should not be translated, since it is * part of the module cmd protocol. */ - } else if (strncmp(recvbuf.payload.data, "ERROR:", 5) == 0) { - eprintf("%.*s", (int) nb, recvbuf.payload.data); + } else if (strncmp(recvbuf.payload.data, "ERROR: ", 7) == 0) { + /* trim "ERROR: " */ + err("%.*s", (int) nb-7, recvbuf.payload.data+7); error_detected = 1; } else { /* neither warning nor error */ eprintf("%.*s", (int) nb, recvbuf.payload.data); -- 2.43.5