From fe903864590701f8e37c65b118bb0a907e797e56 Mon Sep 17 00:00:00 2001 From: Jonas Suhr Christensen Date: Wed, 12 Dec 2012 15:16:54 +0100 Subject: Fixed compiling with -Wall and -Werror. Removed debug_filter. --- Makefile | 2 +- Makefile.files | 1 - debug.c | 34 ++++++++++++++++++++++++---------- debug_syslog.c | 12 ++++-------- main.c | 4 ++-- 5 files changed, 31 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index d28a183..89cf611 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ include Makefile.files all: - gcc ${DEBUG_SOURCES} main.c -o debug -DWITH_DBG_SYSLOG -DWITH_DBG_FILTER + g++ -Werror -Wall -D_FORTIFY_SOURCE=2 -g -O2 ${DEBUG_SOURCES} main.c -o debug -DWITH_DBG_SYSLOG -DWITH_DEBUG diff --git a/Makefile.files b/Makefile.files index 3aaf203..a75fb39 100644 --- a/Makefile.files +++ b/Makefile.files @@ -5,7 +5,6 @@ DEBUG_SOURCES = \ debug.c \ - debug_filter.c \ debug_syslog.c DEBUG_EXTRA_DIST = \ diff --git a/debug.c b/debug.c index e91ff31..b3e3c4e 100644 --- a/debug.c +++ b/debug.c @@ -45,7 +45,11 @@ #include "debug_filter.h" #endif -struct { +#ifdef WITH_DBG_SYSLOG +#include "debug_syslog.h" +#endif + +struct dbg_config_t { unsigned int flags; #ifdef WITH_DBG_MUTEX pthread_mutex_t mutex; @@ -56,7 +60,8 @@ struct { const char* syslog_host; int syslog_port; #endif -} dbg_config = { .flags = DBG_FLAG_DEFAULT, .fd = -1, .file_fd = -1 }; +};// dbg_config;// = { .flags = DBG_FLAG_DEFAULT, .fd = -1, .file_fd = -1 }; +static struct dbg_config_t dbg_config; static void dbg_mutex_init() { @@ -103,6 +108,10 @@ dbg_status_t dbg_init(unsigned int flags, ...) dbg_config.flags = flags; + dbg_config.flags = DBG_FLAG_DEFAULT; + dbg_config.fd = -1; + dbg_config.file_fd = -1; + int end = 0; va_list vl; @@ -201,10 +210,14 @@ static int dbg_output_fd(int fd, const char *msg) char hdr[32]; dbg_create_header(hdr, sizeof(hdr)); - write(fd, hdr, strlen(hdr)); - write(fd, " ", 1); - write(fd, msg, strlen(msg)); - if(msg[strlen(msg) - 1] != '\n') write(fd, "\n", 1); + + int s = -1; + s = write(fd, hdr, strlen(hdr)); + s = write(fd, " ", 1); + s = write(fd, msg, strlen(msg)); + if(msg[strlen(msg) - 1] != '\n') { + s = write(fd, "\n", 1); + } return 0; } @@ -213,6 +226,7 @@ int __debug(const char *func, const int line, const char *ch, const char *fmt, ...) { int result = 0; + int sz; dbg_mutex_lock(); @@ -226,9 +240,9 @@ int __debug(const char *func, const int line, char buf[1024]; - int sz = snprintf(buf, sizeof(buf), - "%s:%s:%s:%d ", - debug_class_str[(unsigned)cl], ch, func, line); + sz = snprintf(buf, sizeof(buf), + "%s:%s:%s:%d ", + debug_class_str[(unsigned)cl], ch, func, line); va_list va; va_start(va, fmt); sz += vsnprintf(buf + sz, sizeof(buf) - sz, fmt, va); @@ -258,7 +272,7 @@ int __debug(const char *func, const int line, dbg_syslog_output(buf); } - done: +// done: dbg_mutex_unlock(); return result; diff --git a/debug_syslog.c b/debug_syslog.c index c5d9dbc..c3f8062 100644 --- a/debug_syslog.c +++ b/debug_syslog.c @@ -27,8 +27,6 @@ */ #include "debug_syslog.h" -#define _GNU_SOURCE - #include #include #include @@ -74,7 +72,8 @@ void dbg_syslog_init(const char* host, int port) char buf[SYSLOG_LENOFEXECNAME]; FILE* f = fopen("/proc/self/cmdline", "r"); if(f) { - fgets(buf, SYSLOG_LENOFEXECNAME, f); + char* s = NULL; + s = fgets(buf, SYSLOG_LENOFEXECNAME, f); fclose(f); } @@ -175,10 +174,6 @@ void dbg_syslog_createheader() { * * */ -static void _calculate_pri() { - -} - void dbg_syslog_output(char* msg) { if(dbg_syslog_sock < 0) return; @@ -190,7 +185,8 @@ void dbg_syslog_output(char* msg) strftime(buftime, SYSLOG_TIMELEN, "%b %e %H:%M:%S ", &time); // Currently everything is mapped to local facility 4 as debug - char bufpri[SYSLOG_PRILEN] = "<167>"; + char bufpri[SYSLOG_PRILEN]; + strncpy(bufpri, "<167>", SYSLOG_PRILEN); char buftag[SYSLOG_TAGLEN]; snprintf(buftag, SYSLOG_TAGLEN, "%s[%d]: ", execname, pid); diff --git a/main.c b/main.c index f5baa8a..54778fa 100644 --- a/main.c +++ b/main.c @@ -47,7 +47,7 @@ int main(int argc, char *argv[]) // DBG_FLAG_OUTPUT_TO_STDOUT | DBG_FLAG_OUTPUT_TO_SYSLOG | //DBG_FLAG_OUTPUT_TO_STDERR | - DBG_FLAG_USE_FILTER | +// DBG_FLAG_USE_FILTER | 0, //DBG_OPTION_FD, fd, // DBG_OPTION_FILENAME, "", @@ -55,7 +55,7 @@ int main(int argc, char *argv[]) "127.0.0.1", DBG_OPTION_SYSLOG_PORT, 514, - DBG_OPTION_FILTER, "+all", +// DBG_OPTION_FILTER, "+all", DBG_OPTION_END); if(status != DBG_STATUS_OK) { -- cgit v1.2.3