From e829b175730fb93081612392c9da8332c8d66586 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Wed, 5 Mar 2014 11:28:19 +0100 Subject: Use hugin module instead of old debug code. --- server/src/pracrod.cc | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) (limited to 'server/src/pracrod.cc') diff --git a/server/src/pracrod.cc b/server/src/pracrod.cc index b68cf07..a67ce7d 100644 --- a/server/src/pracrod.cc +++ b/server/src/pracrod.cc @@ -62,7 +62,7 @@ #include "tcpsocket.h" -#include "debug.h" +#include static const char version_str[] = "Pracro server v" VERSION "\n" @@ -115,13 +115,14 @@ void childwait(int) } } -static FILE *logfp = stderr; -std::string logfile; -bool logfile_reload = false; - void reload(int) { - logfile_reload = true; + printf("Reopening logfile...\n"); + if(hugin_reopen_log() != HUG_STATUS_OK) { + fprintf(stderr, "Could not reopen logfile!\n"); + return; + } + DEBUG(pracro, "Reopened log\n"); } class PracroDaemon : public Daemon { @@ -172,13 +173,16 @@ E0OPPYamkDI/+6Hx2KECQHF9xV1XatyXuFmfRAInK2BtfGY5UIvJaLxVD3Z1+i6q\n\ int main(int argc, char *argv[]) { + const char *hugin_filter = "+all"; + const char *logfile = NULL; + unsigned int hugin_flags = 0; + int c; char *configfile = NULL; char *user = NULL; char *group = NULL; bool foreground = false; char *xml_basedir = NULL; - char *debugstr = NULL; std::string database; std::string pidfile; std::string sessionpath; @@ -239,7 +243,8 @@ int main(int argc, char *argv[]) break; case 'L': - logfile = optarg; + hugin_flags |= HUG_FLAG_OUTPUT_TO_FILE; + logfile = strdup(optarg); break; case 'S': @@ -247,7 +252,8 @@ int main(int argc, char *argv[]) break; case 'D': - debugstr = strdup(optarg); + hugin_flags |= HUG_FLAG_USE_FILTER; + hugin_filter = optarg; break; case 's': @@ -277,17 +283,15 @@ int main(int argc, char *argv[]) } } - if(logfile != "") { - logfp = fopen(logfile.c_str(), "a"); - if(!logfp) { - fprintf(stderr, "Could not write to logfile: '%s'\n", optarg); - logfp = stderr; - } - debug_init(logfp); - } + if(logfile == NULL) hugin_flags |= HUG_FLAG_OUTPUT_TO_STDOUT; - if(debugstr) { - debug_parse(debugstr); + hug_status_t status = hug_init(hugin_flags, + HUG_OPTION_FILTER, hugin_filter, + HUG_OPTION_FILENAME, logfile, + HUG_OPTION_END); + if(status != HUG_STATUS_OK) { + printf("Error: %d\n", status); + return 1; } // Load config @@ -295,10 +299,10 @@ int main(int argc, char *argv[]) if(configfile) configparser = new ConfigurationParser(configfile); else configparser = new ConfigurationParser(ETC"/pracrod.conf"); } catch(ConfigurationParser::ParseException &e) { - ERR_LOG(pracrod, "Config file parse error: %s.\n", e.what()); + ERR(pracrod, "Config file parse error: %s.\n", e.what()); return 1; } catch(ConfigurationParser::ReadException &e) { - ERR_LOG(pracrod, "Config file read error: %s.\n", e.what()); + ERR(pracrod, "Config file read error: %s.\n", e.what()); return 1; } @@ -340,7 +344,5 @@ int main(int argc, char *argv[]) if(user) free(user); if(group) free(group); - if(logfp != stderr) fclose(logfp); - return 0; } -- cgit v1.2.3