From d31c7dcd86b8a0dc5037ac5c67797dabf169bf38 Mon Sep 17 00:00:00 2001 From: psychon Date: Tue, 24 Mar 2009 18:45:03 +0000 Subject: [PATCH] Add znc --debug / znc -g This enables the debug output you get with --enable-debug on --disable-debug builds. The behaviour if znc was compiled with --disable-debug isn't changed. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1442 726aef4b-f618-498e-8847-2d620e286838 --- Utils.cpp | 9 +++++++-- Utils.h | 13 ++++++++----- main.cpp | 14 ++++++++++---- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/Utils.cpp b/Utils.cpp index 725767bf..fcf12272 100644 --- a/Utils.cpp +++ b/Utils.cpp @@ -24,7 +24,13 @@ using std::stringstream; -bool CUtils::stdoutIsTTY; +bool CUtils::stdoutIsTTY = true; +bool CUtils::debug = +#ifdef _DEBUG + true; +#else + false; +#endif CUtils::CUtils() {} CUtils::~CUtils() {} @@ -553,4 +559,3 @@ CString CBlowfish::Crypt(const CString & sData) { } #endif // HAVE_LIBSSL - diff --git a/Utils.h b/Utils.h index e0ac0098..986acbcf 100644 --- a/Utils.h +++ b/Utils.h @@ -21,11 +21,11 @@ using std::map; using std::vector; -#ifdef _DEBUG -#define DEBUG(f) (cout << f << endl) -#else -#define DEBUG(f) ((void)0) -#endif +#define DEBUG(f) do { \ + if (CUtils::Debug()) { \ + cout << f << endl; \ + } \ +} while (0); static inline void SetFdCloseOnExec(int fd) { @@ -46,6 +46,8 @@ public: static CString GetIP(unsigned long addr); static unsigned long GetLongIP(const CString& sIP); static void SetStdoutIsTTY(bool b) { stdoutIsTTY = b; } + static void SetDebug(bool b) { debug = b; } + static bool Debug() { return debug; } static void PrintError(const CString& sMessage); static void PrintMessage(const CString& sMessage, bool bStrong = false); @@ -77,6 +79,7 @@ public: private: protected: static bool stdoutIsTTY; + static bool debug; }; class CException { diff --git a/main.cpp b/main.cpp index 31966db0..215f4d22 100644 --- a/main.cpp +++ b/main.cpp @@ -12,6 +12,7 @@ static struct option g_LongOpts[] = { { "help", no_argument, 0, 'h' }, { "version", no_argument, 0, 'v' }, + { "debug", no_argument, 0, 'g' }, { "foreground", no_argument, 0, 'f' }, { "no-color", no_argument, 0, 'n' }, { "allow-root", no_argument, 0, 'r' }, @@ -31,6 +32,7 @@ static void GenerateHelp(const char *appname) { CUtils::PrintMessage("\t-h, --help List available command line options (this page)"); CUtils::PrintMessage("\t-v, --version Output version information and exit"); CUtils::PrintMessage("\t-f, --foreground Don't fork into the background"); + CUtils::PrintMessage("\t-g, --debug Output debugging information (Implies -f)"); CUtils::PrintMessage("\t-n, --no-color Don't use escape sequences in the output"); CUtils::PrintMessage("\t-r, --allow-root Don't complain if ZNC is run as root"); CUtils::PrintMessage("\t-c, --makeconf Interactively create a new config"); @@ -90,9 +92,9 @@ int main(int argc, char** argv) { bool bMakePem = false; bool bEncPem = false; - while ((iArg = getopt_long(argc, argv, "hvnrcsped:f", g_LongOpts, &iOptIndex)) != -1) { + while ((iArg = getopt_long(argc, argv, "hvnrcsped:gf", g_LongOpts, &iOptIndex)) != -1) { #else - while ((iArg = getopt_long(argc, argv, "hvnrcsd:f", g_LongOpts, &iOptIndex)) != -1) { + while ((iArg = getopt_long(argc, argv, "hvnrcsd:gf", g_LongOpts, &iOptIndex)) != -1) { #endif /* HAVE_LIBSSL */ switch (iArg) { case 'h': @@ -127,6 +129,10 @@ int main(int argc, char** argv) { case 'f': bForeground = true; break; + case 'g': + bForeground = true; + CUtils::SetDebug(true); + break; case '?': default: GenerateHelp(argv[0]); @@ -238,8 +244,8 @@ int main(int argc, char** argv) { // We are the child. There is no way we can be a process group // leader, thus setsid() must succeed. setsid(); - // Now we are in our own process group and session (no controlling - // terminal). We are independent! + // Now we are in our own process group and session (no + // controlling terminal). We are independent! } struct sigaction sa;