diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2012-04-12 10:05:31 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2012-04-12 10:05:31 +0200 |
commit | aac862e2797e9a05c64a872850bb2e9f304d6e13 (patch) | |
tree | 119060f12d5fbe1b92e40cf56694467799f75a0e /server | |
parent | 4c39b3361c7f873174a5c091943aa1e47861fb9f (diff) |
New mutex wrapped debug system.
Diffstat (limited to 'server')
-rw-r--r-- | server/src/daemon.cc | 4 | ||||
-rw-r--r-- | server/src/debug.cc | 27 | ||||
-rw-r--r-- | server/src/debug.h | 1 | ||||
-rw-r--r-- | server/src/mutex.cc | 14 | ||||
-rw-r--r-- | server/src/mutex.h | 4 | ||||
-rw-r--r-- | server/src/pracrod.cc | 13 | ||||
-rw-r--r-- | server/src/server.cc | 9 |
7 files changed, 61 insertions, 11 deletions
diff --git a/server/src/daemon.cc b/server/src/daemon.cc index 938170c..e8e08ee 100644 --- a/server/src/daemon.cc +++ b/server/src/daemon.cc @@ -134,6 +134,10 @@ int Daemon::run(const char *user, const char* group, bool detach, } else { fprintf(fp, "%lu", (unsigned long int)pid); fclose(fp); + /* + fprintf(stderr, "Wrote pid %lu to file \"%s\"", + (unsigned long int)pid, pidfile.c_str()); + */ } } diff --git a/server/src/debug.cc b/server/src/debug.cc index d3e74e8..e42baae 100644 --- a/server/src/debug.cc +++ b/server/src/debug.cc @@ -36,6 +36,10 @@ #include <pthread.h> +#include "mutex.h" + +static Mutex mutex; + static unsigned int gettid() { return (unsigned int)pthread_self(); @@ -76,6 +80,7 @@ int __debug(const char *func, const int line, const enum __debug_class cl, const char *ch, const char *fmt, ...) { + MutexAutolock m(mutex); int ret = 0; if(__debug_enabled(cl, ch)) { if((unsigned)cl < NELEM(debug_class_str)) @@ -98,6 +103,7 @@ int __debug_va(const char *func, const int line, const enum __debug_class cl, const char *ch, const char *fmt, va_list va) { + MutexAutolock m(mutex); int ret = 0; if(__debug_enabled(cl, ch)) { if((unsigned)cl < NELEM(debug_class_str)) @@ -117,6 +123,8 @@ int __debug_va(const char *func, const int line, int __log(const char *func, const int line, const enum __debug_class cl, const char *ch, const char *fmt, ...) { + MutexAutolock m(mutex); + std::string logmsg; char str[8]; @@ -157,6 +165,8 @@ int __log(const char *func, const int line, const enum __debug_class cl, int __log_va(const char *func, const int line, const enum __debug_class cl, const char *ch, const char *fmt, va_list va) { + MutexAutolock m(mutex); + std::string logmsg; char str[8]; #ifdef WITH_DEBUG @@ -190,9 +200,25 @@ int __log_va(const char *func, const int line, const enum __debug_class cl, void debug_init(FILE *fp) { + mutex.name = "debug"; + MutexAutolock m(mutex); logfp = fp; } +void debug_reinit(const char *logfile) +{ + MutexAutolock m(mutex); + + if(logfp != stderr) { + fclose(logfp); + logfp = fopen(logfile, "a"); + if(!logfp) { + fprintf(stderr, "Could not write to logfile: '%s'\n", logfile); + logfp = stderr; + } + } +} + /* * fmt := [set[,set]*]* @@ -202,6 +228,7 @@ void debug_init(FILE *fp) */ void debug_parse(const char *fmt) { + MutexAutolock m(mutex); char *s; char *next; char *opt; diff --git a/server/src/debug.h b/server/src/debug.h index a5f199d..838d83f 100644 --- a/server/src/debug.h +++ b/server/src/debug.h @@ -53,6 +53,7 @@ #endif/*HAVE_CONFIG*/ void debug_init(FILE *fp); +void debug_reinit(const char *file); void debug_parse(const char *fmt); enum __debug_class diff --git a/server/src/mutex.cc b/server/src/mutex.cc index ec0d0e8..9805591 100644 --- a/server/src/mutex.cc +++ b/server/src/mutex.cc @@ -27,6 +27,11 @@ */ #include "mutex.h" +#include "debug.h" + +#define MUTEX_DBG(x) +//#define MUTEX_DBG(x) x + Mutex::Mutex() { pthread_mutex_init (&mutex, NULL); @@ -39,16 +44,23 @@ Mutex::~Mutex() bool Mutex::trylock() { - return pthread_mutex_trylock(&mutex) == 0; + bool ret = pthread_mutex_trylock(&mutex) == 0; + + if(ret) MUTEX_DBG(printf("trylock succeeded on %s\n", name.c_str())); + else MUTEX_DBG(printf("trylock failed on %s\n", name.c_str())); + + return ret; } void Mutex::lock() { pthread_mutex_lock(&mutex); + MUTEX_DBG(printf("lock on %s\n", name.c_str())); } void Mutex::unlock() { + MUTEX_DBG(printf("unlock on %s\n", name.c_str())); pthread_mutex_unlock(&mutex); } diff --git a/server/src/mutex.h b/server/src/mutex.h index cf052ad..87f18e1 100644 --- a/server/src/mutex.h +++ b/server/src/mutex.h @@ -30,6 +30,8 @@ #include <pthread.h> +#include <string> + class Mutex { public: Mutex(); @@ -39,6 +41,8 @@ public: void lock(); void unlock(); + std::string name; + private: pthread_mutex_t mutex; }; diff --git a/server/src/pracrod.cc b/server/src/pracrod.cc index dbedeca..b68cf07 100644 --- a/server/src/pracrod.cc +++ b/server/src/pracrod.cc @@ -116,19 +116,12 @@ void childwait(int) } static FILE *logfp = stderr; -static std::string logfile; +std::string logfile; +bool logfile_reload = false; void reload(int) { - if(logfp != stderr) { - fclose(logfp); - logfp = fopen(logfile.c_str(), "a"); - if(!logfp) { - fprintf(stderr, "Could not write to logfile: '%s'\n", optarg); - logfp = stderr; - } - debug_init(logfp); - } + logfile_reload = true; } class PracroDaemon : public Daemon { diff --git a/server/src/server.cc b/server/src/server.cc index 2d2d4c9..838da32 100644 --- a/server/src/server.cc +++ b/server/src/server.cc @@ -37,6 +37,9 @@ #include "client_connection.h" #include "admin_connection.h" +extern std::string logfile; +extern volatile bool logfile_reload; + class PracroHttpd : public Httpd { public: PracroHttpd() {} @@ -57,6 +60,12 @@ public: headers_t &getargs, headers_t &headers) { + if(logfile_reload) { + DEBUG(pracrod, "Reopen log file %s\n", logfile.c_str()); + debug_reinit(logfile.c_str()); + logfile_reload = false; + } + Connection *connection = NULL; if(headers.find("User-Agent") != headers.end() && |