From e9e7da9b7adcf33dece522514c323d392913041b Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Wed, 20 Apr 2016 09:38:06 +0200 Subject: [PATCH] Do proper logging rather than fprintf(stderr, ...) --- common/rdr/RandomStream.cxx | 9 ++++++--- common/rdr/ZlibOutStream.cxx | 19 +++++++++++-------- common/rfb/CMsgHandler.cxx | 3 +++ common/rfb/CMsgReader.cxx | 15 +++++++++------ common/rfb/Configuration.cxx | 2 +- common/rfb/Region.cxx | 9 ++++++--- common/rfb/SMsgReader.cxx | 4 ++-- 7 files changed, 38 insertions(+), 23 deletions(-) diff --git a/common/rdr/RandomStream.cxx b/common/rdr/RandomStream.cxx index 3fde18d1..e22da3d0 100644 --- a/common/rdr/RandomStream.cxx +++ b/common/rdr/RandomStream.cxx @@ -18,6 +18,7 @@ #include #include +#include #include #include #ifndef WIN32 @@ -30,6 +31,8 @@ #endif #endif +static rfb::LogWriter vlog("RandomStream"); + using namespace rdr; const int DEFAULT_BUF_LEN = 256; @@ -46,11 +49,11 @@ RandomStream::RandomStream() if (!CryptAcquireContext(&provider, 0, 0, PROV_RSA_FULL, 0)) { if (GetLastError() == (DWORD)NTE_BAD_KEYSET) { if (!CryptAcquireContext(&provider, 0, 0, PROV_RSA_FULL, CRYPT_NEWKEYSET)) { - fprintf(stderr, "RandomStream: unable to create keyset\n"); + vlog.error("unable to create keyset"); provider = 0; } } else { - fprintf(stderr, "RandomStream: unable to acquire context\n"); + vlog.error("unable to acquire context"); provider = 0; } } @@ -65,7 +68,7 @@ RandomStream::RandomStream() { #endif #endif - fprintf(stderr,"RandomStream: warning: no OS supplied random source - using rand()\n"); + vlog.error("no OS supplied random source - using rand()"); seed += (unsigned int) time(0) + getpid() + getpid() * 987654 + rand(); srand(seed); } diff --git a/common/rdr/ZlibOutStream.cxx b/common/rdr/ZlibOutStream.cxx index 9d9f8ba1..dd3c2367 100644 --- a/common/rdr/ZlibOutStream.cxx +++ b/common/rdr/ZlibOutStream.cxx @@ -21,11 +21,14 @@ #include #include +#include #include #undef ZLIBOUT_DEBUG +static rfb::LogWriter vlog("ZlibOutStream"); + using namespace rdr; enum { DEFAULT_BUF_SIZE = 16384 }; @@ -85,7 +88,7 @@ void ZlibOutStream::flush() zs->avail_in = ptr - start; #ifdef ZLIBOUT_DEBUG - fprintf(stderr,"zos flush: avail_in %d\n",zs->avail_in); + vlog.debug("flush: avail_in %d",zs->avail_in); #endif // Force out everything from the zlib encoder @@ -98,7 +101,7 @@ void ZlibOutStream::flush() int ZlibOutStream::overrun(int itemSize, int nItems) { #ifdef ZLIBOUT_DEBUG - fprintf(stderr,"zos overrun\n"); + vlog.debug("overrun"); #endif if (itemSize > bufSize) @@ -120,7 +123,7 @@ int ZlibOutStream::overrun(int itemSize, int nItems) } else { // but didn't consume all the data? try shifting what's left to the // start of the buffer. - fprintf(stderr,"z out buf not full, but in data not consumed\n"); + vlog.info("z out buf not full, but in data not consumed"); memmove(start, zs->next_in, ptr - zs->next_in); offset += zs->next_in - start; ptr -= zs->next_in - start; @@ -149,8 +152,8 @@ void ZlibOutStream::deflate(int flush) zs->avail_out = underlying->getend() - underlying->getptr(); #ifdef ZLIBOUT_DEBUG - fprintf(stderr,"zos: calling deflate, avail_in %d, avail_out %d\n", - zs->avail_in,zs->avail_out); + vlog.debug("calling deflate, avail_in %d, avail_out %d", + zs->avail_in,zs->avail_out); #endif rc = ::deflate(zs, flush); @@ -163,8 +166,8 @@ void ZlibOutStream::deflate(int flush) } #ifdef ZLIBOUT_DEBUG - fprintf(stderr,"zos: after deflate: %d bytes\n", - zs->next_out-underlying->getptr()); + vlog.debug("after deflate: %d bytes", + zs->next_out-underlying->getptr()); #endif underlying->setptr(zs->next_out); @@ -177,7 +180,7 @@ void ZlibOutStream::checkCompressionLevel() if (newLevel != compressionLevel) { #ifdef ZLIBOUT_DEBUG - fprintf(stderr,"zos change: avail_in %d\n",zs->avail_in); + vlog.debug("change: avail_in %d",zs->avail_in); #endif // zlib is just horribly stupid. It does an implicit flush on diff --git a/common/rfb/CMsgHandler.cxx b/common/rfb/CMsgHandler.cxx index 4fe50414..c009067a 100644 --- a/common/rfb/CMsgHandler.cxx +++ b/common/rfb/CMsgHandler.cxx @@ -19,9 +19,12 @@ #include #include +#include #include #include +static rfb::LogWriter vlog("CMsgHandler"); + using namespace rfb; CMsgHandler::CMsgHandler() diff --git a/common/rfb/CMsgReader.cxx b/common/rfb/CMsgReader.cxx index e8e7afb2..2b5b9fbf 100644 --- a/common/rfb/CMsgReader.cxx +++ b/common/rfb/CMsgReader.cxx @@ -23,10 +23,13 @@ #include #include #include +#include #include #include #include +static rfb::LogWriter vlog("CMsgReader"); + using namespace rfb; CMsgReader::CMsgReader(CMsgHandler* handler_, rdr::InStream* is_) @@ -74,7 +77,7 @@ void CMsgReader::readMsg() readEndOfContinuousUpdates(); break; default: - fprintf(stderr, "unknown message type %d\n", type); + vlog.error("unknown message type %d", type); throw Exception("unknown message type"); } } else { @@ -151,7 +154,7 @@ void CMsgReader::readServerCutText() rdr::U32 len = is->readU32(); if (len > 256*1024) { is->skip(len); - fprintf(stderr,"cut text too long (%d bytes) - ignoring\n",len); + vlog.error("cut text too long (%d bytes) - ignoring",len); return; } CharArray ca(len+1); @@ -172,7 +175,7 @@ void CMsgReader::readFence() len = is->readU8(); if (len > sizeof(data)) { - fprintf(stderr, "Ignoring fence with too large payload\n"); + vlog.error("Ignoring fence with too large payload"); is->skip(len); return; } @@ -198,14 +201,14 @@ void CMsgReader::readRect(const Rect& r, int encoding) { if ((r.br.x > handler->server.width()) || (r.br.y > handler->server.height())) { - fprintf(stderr, "Rect too big: %dx%d at %d,%d exceeds %dx%d\n", + vlog.error("Rect too big: %dx%d at %d,%d exceeds %dx%d", r.width(), r.height(), r.tl.x, r.tl.y, handler->server.width(), handler->server.height()); throw Exception("Rect too big"); } if (r.is_empty()) - fprintf(stderr, "Warning: zero size rect\n"); + vlog.error("zero size rect"); handler->dataRect(r, encoding); } @@ -449,7 +452,7 @@ void CMsgReader::readSetDesktopName(int x, int y, int w, int h) char* name = is->readString(); if (x || y || w || h) { - fprintf(stderr, "Ignoring DesktopName rect with non-zero position/size\n"); + vlog.error("Ignoring DesktopName rect with non-zero position/size"); } else { handler->setName(name); } diff --git a/common/rfb/Configuration.cxx b/common/rfb/Configuration.cxx index 619c4d5a..ea000600 100644 --- a/common/rfb/Configuration.cxx +++ b/common/rfb/Configuration.cxx @@ -379,7 +379,7 @@ StringParameter::StringParameter(const char* name_, const char* desc_, : VoidParameter(name_, desc_, co), value(strDup(v)), def_value(v) { if (!v) { - fprintf(stderr,"Default value for %s not allowed\n",name_); + vlog.error("Default value for %s not allowed",name_); throw rfb::Exception("Default value not allowed"); } } diff --git a/common/rfb/Region.cxx b/common/rfb/Region.cxx index c17c5d48..beca482d 100644 --- a/common/rfb/Region.cxx +++ b/common/rfb/Region.cxx @@ -24,6 +24,7 @@ // #include +#include #include #include @@ -33,6 +34,8 @@ extern "C" { #include } +static rfb::LogWriter vlog("Region"); + // A _RectRegion must never be passed as a return parameter to the Xlib region // operations. This is because for efficiency its "rects" member has not been // allocated with Xmalloc. It is however safe to pass it as an input @@ -123,7 +126,7 @@ void rfb::Region::setExtentsAndOrderedRects(const ShortRect* extents, BOX* prevRects = xrgn->rects; xrgn->rects = (BOX*)Xrealloc((char*)xrgn->rects, nRects * sizeof(BOX)); if (!xrgn->rects) { - fprintf(stderr,"Xrealloc failed\n"); + vlog.error("Xrealloc failed"); Xfree(prevRects); return; } @@ -234,13 +237,13 @@ rfb::Rect rfb::Region::get_bounding_rect() const { void rfb::Region::debug_print(const char* prefix) const { - fprintf(stderr,"%s num rects %3ld extents %3d,%3d %3dx%3d\n", + vlog.debug("%s num rects %3ld extents %3d,%3d %3dx%3d", prefix, xrgn->numRects, xrgn->extents.x1, xrgn->extents.y1, xrgn->extents.x2-xrgn->extents.x1, xrgn->extents.y2-xrgn->extents.y1); for (int i = 0; i < xrgn->numRects; i++) { - fprintf(stderr," rect %3d,%3d %3dx%3d\n", + vlog.debug(" rect %3d,%3d %3dx%3d", xrgn->rects[i].x1, xrgn->rects[i].y1, xrgn->rects[i].x2-xrgn->rects[i].x1, xrgn->rects[i].y2-xrgn->rects[i].y1); diff --git a/common/rfb/SMsgReader.cxx b/common/rfb/SMsgReader.cxx index cb71ac84..200350c1 100644 --- a/common/rfb/SMsgReader.cxx +++ b/common/rfb/SMsgReader.cxx @@ -83,7 +83,7 @@ void SMsgReader::readMsg() readQEMUMessage(); break; default: - fprintf(stderr, "unknown message type %d\n", msgType); + vlog.error("unknown message type %d", msgType); throw Exception("unknown message type"); } } @@ -173,7 +173,7 @@ void SMsgReader::readFence() len = is->readU8(); if (len > sizeof(data)) { - fprintf(stderr, "Ignoring fence with too large payload\n"); + vlog.error("Ignoring fence with too large payload"); is->skip(len); return; } -- 2.39.5