From 3057f683f3fe1c3490d68db2a8fc936b4652ba91 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 17 Apr 2007 17:59:39 +0200 Subject: Add timestamps to debug output. (This used to be ctdb commit 197a02384bd2ca42dfff4c0357175424d2321e9c) --- ctdb/lib/util/debug.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 ctdb/lib/util/debug.c (limited to 'ctdb/lib/util/debug.c') diff --git a/ctdb/lib/util/debug.c b/ctdb/lib/util/debug.c new file mode 100644 index 0000000000..a3229015ca --- /dev/null +++ b/ctdb/lib/util/debug.c @@ -0,0 +1,40 @@ +/* + Unix SMB/CIFS implementation. + ctdb debug functions + Copyright (C) Volker Lendecke 2007 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "system/time.h" +#include + +void do_debug(const char *format, ...) +{ + struct timeval tm; + va_list ap; + char *s = NULL; + + va_start(ap, format); + vasprintf(&s, format, ap); + va_end(ap); + + gettimeofday(&tm, NULL); + printf("%-8.8d.%-6.6d [%d]: %s", (int)tm.tv_sec, (int)tm.tv_usec, + (int)getpid(), s); + fflush(stdout); + free(s); +} -- cgit From e5f2e5e5eb56c390c68c1ac79a32fb068510fc41 Mon Sep 17 00:00:00 2001 From: Peter Somogyi Date: Fri, 20 Apr 2007 14:26:19 +0200 Subject: - ctdb/ib minor bugfixes (error case) - make ctdb capable of alternative connection (like ib) again, solved the fork problem - do_debug memory overwrite bugfix (occured using ibwrapper_test with wrong address given) (This used to be ctdb commit da0b84cda26d544f63841dfd770ed7ebad401944) --- ctdb/lib/util/debug.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'ctdb/lib/util/debug.c') diff --git a/ctdb/lib/util/debug.c b/ctdb/lib/util/debug.c index a3229015ca..ffe1dcc382 100644 --- a/ctdb/lib/util/debug.c +++ b/ctdb/lib/util/debug.c @@ -22,6 +22,22 @@ #include "system/time.h" #include +static int vasprintf2(char **ptr, const char *format, va_list ap) +{ + int ret; + va_list tmp_ap; + + va_copy(tmp_ap, ap); + ret = vsnprintf(NULL, 0, format, tmp_ap); + if (ret <= 0) return ret; + + (*ptr) = (char *)malloc(ret+1); + if (!*ptr) return -1; + ret = vsnprintf(*ptr, ret+1, format, ap); + + return ret; +} + void do_debug(const char *format, ...) { struct timeval tm; @@ -29,7 +45,7 @@ void do_debug(const char *format, ...) char *s = NULL; va_start(ap, format); - vasprintf(&s, format, ap); + vasprintf2(&s, format, ap); va_end(ap); gettimeofday(&tm, NULL); -- cgit From eb20281bb423eb32e870dd78f8984e784b8aff67 Mon Sep 17 00:00:00 2001 From: Peter Somogyi Date: Fri, 20 Apr 2007 17:04:00 +0200 Subject: use talloc_vasprintf (This used to be ctdb commit e259620d416497fba5ac43a87f3be7b280c21409) --- ctdb/lib/util/debug.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) (limited to 'ctdb/lib/util/debug.c') diff --git a/ctdb/lib/util/debug.c b/ctdb/lib/util/debug.c index ffe1dcc382..c9c6974964 100644 --- a/ctdb/lib/util/debug.c +++ b/ctdb/lib/util/debug.c @@ -22,21 +22,6 @@ #include "system/time.h" #include -static int vasprintf2(char **ptr, const char *format, va_list ap) -{ - int ret; - va_list tmp_ap; - - va_copy(tmp_ap, ap); - ret = vsnprintf(NULL, 0, format, tmp_ap); - if (ret <= 0) return ret; - - (*ptr) = (char *)malloc(ret+1); - if (!*ptr) return -1; - ret = vsnprintf(*ptr, ret+1, format, ap); - - return ret; -} void do_debug(const char *format, ...) { @@ -45,12 +30,12 @@ void do_debug(const char *format, ...) char *s = NULL; va_start(ap, format); - vasprintf2(&s, format, ap); + s = talloc_vasprintf(NULL, format, ap); va_end(ap); gettimeofday(&tm, NULL); printf("%-8.8d.%-6.6d [%d]: %s", (int)tm.tv_sec, (int)tm.tv_usec, (int)getpid(), s); fflush(stdout); - free(s); + talloc_free(s); } -- cgit From d244415d1e4428aa39cc25082b7f691b461afb22 Mon Sep 17 00:00:00 2001 From: Peter Somogyi Date: Mon, 23 Apr 2007 12:45:14 +0200 Subject: fixed ctdb/ib bug at reject event reverted my suggestion in debug.c (based on my false error detection) (This used to be ctdb commit 5c52c9f37639c65b551c10d1706c49653cd99742) --- ctdb/lib/util/debug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ctdb/lib/util/debug.c') diff --git a/ctdb/lib/util/debug.c b/ctdb/lib/util/debug.c index c9c6974964..a048ed807e 100644 --- a/ctdb/lib/util/debug.c +++ b/ctdb/lib/util/debug.c @@ -30,12 +30,12 @@ void do_debug(const char *format, ...) char *s = NULL; va_start(ap, format); - s = talloc_vasprintf(NULL, format, ap); + vasprintf(&s, format, ap); va_end(ap); gettimeofday(&tm, NULL); printf("%-8.8d.%-6.6d [%d]: %s", (int)tm.tv_sec, (int)tm.tv_usec, (int)getpid(), s); fflush(stdout); - talloc_free(s); + free(s); } -- cgit From 13392414b113e9ac21d7abb008f62f3338ff41a0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 19 May 2007 14:01:02 +1000 Subject: nicer date formatting (This used to be ctdb commit 78c256caa738593e335de65df752ff015f3a38e1) --- ctdb/lib/util/debug.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'ctdb/lib/util/debug.c') diff --git a/ctdb/lib/util/debug.c b/ctdb/lib/util/debug.c index a048ed807e..7d1395480d 100644 --- a/ctdb/lib/util/debug.c +++ b/ctdb/lib/util/debug.c @@ -25,17 +25,22 @@ void do_debug(const char *format, ...) { - struct timeval tm; + struct timeval t; va_list ap; char *s = NULL; + struct tm *tm; + char tbuf[100]; va_start(ap, format); vasprintf(&s, format, ap); va_end(ap); - gettimeofday(&tm, NULL); - printf("%-8.8d.%-6.6d [%d]: %s", (int)tm.tv_sec, (int)tm.tv_usec, - (int)getpid(), s); + t = timeval_current(); + tm = localtime(&t.tv_sec); + + strftime(tbuf,sizeof(tbuf)-1,"%Y/%m/%d %H:%M:%S", tm); + + printf("%s.%06u [%5u]: %s", tbuf, (unsigned)t.tv_usec, (unsigned)getpid(), s); fflush(stdout); free(s); } -- cgit From 32de198fd3d59033418ac0e05baaf16b17f5ce46 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 15:29:31 +1000 Subject: update lib/replace from samba4 (This used to be ctdb commit f0555484105668c01c21f56322992e752e831109) --- ctdb/lib/util/debug.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'ctdb/lib/util/debug.c') diff --git a/ctdb/lib/util/debug.c b/ctdb/lib/util/debug.c index 7d1395480d..1d709248be 100644 --- a/ctdb/lib/util/debug.c +++ b/ctdb/lib/util/debug.c @@ -5,7 +5,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program; if not, see . */ #include "includes.h" -- cgit From 4322a86645f67c469797c6a896342641e2626423 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 6 Jan 2008 12:35:49 +1100 Subject: ensure tdb log messages appear in ctdbd logs (This used to be ctdb commit b2439487832230e7b738c0f89eeaa2c0c4ba0951) --- ctdb/lib/util/debug.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'ctdb/lib/util/debug.c') diff --git a/ctdb/lib/util/debug.c b/ctdb/lib/util/debug.c index 78d465d52b..c1f1c91410 100644 --- a/ctdb/lib/util/debug.c +++ b/ctdb/lib/util/debug.c @@ -22,17 +22,14 @@ #include -void do_debug(const char *format, ...) +void do_debug_v(const char *format, va_list ap) { struct timeval t; - va_list ap; char *s = NULL; struct tm *tm; char tbuf[100]; - va_start(ap, format); vasprintf(&s, format, ap); - va_end(ap); t = timeval_current(); tm = localtime(&t.tv_sec); @@ -43,3 +40,12 @@ void do_debug(const char *format, ...) fflush(stderr); free(s); } + +void do_debug(const char *format, ...) +{ + va_list ap; + + va_start(ap, format); + do_debug_v(format, ap); + va_end(ap); +} -- cgit From b62b7fcde84c503e78e65bd4ecf3abc4781af2ec Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 16 Jan 2008 22:03:01 +1100 Subject: added syslog support, and use a pipe to catch logging from child processes to the ctdbd logging functions (This used to be ctdb commit 1306b04cd01e996fd1aa1159a9521f2ff7b06165) --- ctdb/lib/util/debug.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'ctdb/lib/util/debug.c') diff --git a/ctdb/lib/util/debug.c b/ctdb/lib/util/debug.c index c1f1c91410..341a4a1586 100644 --- a/ctdb/lib/util/debug.c +++ b/ctdb/lib/util/debug.c @@ -22,7 +22,7 @@ #include -void do_debug_v(const char *format, va_list ap) +static void _do_debug_v(const char *format, va_list ap) { struct timeval t; char *s = NULL; @@ -41,6 +41,9 @@ void do_debug_v(const char *format, va_list ap) free(s); } +/* default logging function */ +void (*do_debug_v)(const char *, va_list ap) = _do_debug_v; + void do_debug(const char *format, ...) { va_list ap; @@ -49,3 +52,4 @@ void do_debug(const char *format, ...) do_debug_v(format, ap); va_end(ap); } + -- cgit From 2fcedf6dac9dd275adbb0017e53547614df29d93 Mon Sep 17 00:00:00 2001 From: Sumit Bose Date: Wed, 20 May 2009 12:08:13 +0200 Subject: add missing checks on so far ignored return values Most of these were found during a review by Jim Meyering (This used to be ctdb commit 3aee5ee1deb4a19be3bd3a4ce3abbe09de763344) --- ctdb/lib/util/debug.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'ctdb/lib/util/debug.c') diff --git a/ctdb/lib/util/debug.c b/ctdb/lib/util/debug.c index 341a4a1586..9e81929220 100644 --- a/ctdb/lib/util/debug.c +++ b/ctdb/lib/util/debug.c @@ -28,8 +28,14 @@ static void _do_debug_v(const char *format, va_list ap) char *s = NULL; struct tm *tm; char tbuf[100]; - - vasprintf(&s, format, ap); + int ret; + + ret = vasprintf(&s, format, ap); + if (ret == -1) { + fprintf(stderr, "vasprintf failed in _do_debug_v, cannot print debug message.\n"); + fflush(stderr); + return; + } t = timeval_current(); tm = localtime(&t.tv_sec); -- cgit From 26e1486db7cafa86d9deceb225820631dfeb2a92 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Thu, 21 May 2009 11:49:16 +1000 Subject: Whitespace changes and using the CTDB_NO_MEMORY() macro changes to the previous patch. (This used to be ctdb commit d623ea7c04daa6349b42d50862843c9f86115488) --- ctdb/lib/util/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ctdb/lib/util/debug.c') diff --git a/ctdb/lib/util/debug.c b/ctdb/lib/util/debug.c index 9e81929220..2390f4cb9e 100644 --- a/ctdb/lib/util/debug.c +++ b/ctdb/lib/util/debug.c @@ -28,7 +28,7 @@ static void _do_debug_v(const char *format, va_list ap) char *s = NULL; struct tm *tm; char tbuf[100]; - int ret; + int ret; ret = vasprintf(&s, format, ap); if (ret == -1) { -- cgit From ace21b84b7c27870b67806db1d8c5516d595376d Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 21 Jul 2009 09:47:07 +0200 Subject: debug: add debug_add and dump_data functions Michael (This used to be ctdb commit 64405bdbebb2ddf0ae980e958ede77df79139000) --- ctdb/lib/util/debug.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) (limited to 'ctdb/lib/util/debug.c') diff --git a/ctdb/lib/util/debug.c b/ctdb/lib/util/debug.c index 2390f4cb9e..63ca03b5a7 100644 --- a/ctdb/lib/util/debug.c +++ b/ctdb/lib/util/debug.c @@ -20,7 +20,7 @@ #include "includes.h" #include "system/time.h" #include - +#include static void _do_debug_v(const char *format, va_list ap) { @@ -59,3 +59,80 @@ void do_debug(const char *format, ...) va_end(ap); } + +static void _do_debug_add_v(const char *format, va_list ap) +{ + char *s = NULL; + int ret; + + ret = vasprintf(&s, format, ap); + if (ret == -1) { + fprintf(stderr, "vasprintf failed in _do_debug_add_v, cannot print debug message.\n"); + fflush(stderr); + return; + } + + fprintf(stderr, "%s", s); + fflush(stderr); + free(s); +} + +/* default logging function */ +void (*do_debug_add_v)(const char *, va_list ap) = _do_debug_add_v; + +void do_debug_add(const char *format, ...) +{ + va_list ap; + + va_start(ap, format); + do_debug_add_v(format, ap); + va_end(ap); +} + +#define DEBUGLVL(lvl) ((lvl) <= LogLevel) +#define DEBUG(lvl, x) do { if ((lvl) <= LogLevel) { this_log_level = (lvl); do_debug x; }} while (0) +#define DEBUGADD(lvl, x) do { if ((lvl) <= LogLevel) { this_log_level = (lvl); do_debug_add x; }} while (0) + +static void print_asc(int level, const uint8_t *buf, size_t len) +{ + int i; + for (i=0;i8) DEBUGADD(level,(" ")); + while (n--) DEBUGADD(level,(" ")); + n = MIN(8,i%16); + print_asc(level,&buf[i-(i%16)],n); DEBUGADD(level,( " " )); + n = (i%16) - n; + if (n>0) print_asc(level,&buf[i-n],n); + DEBUGADD(level,("\n")); + } + DEBUG(level, (__location__ " dump data of size %i finished\n", (int)len)); +} + -- cgit From bc2675119df5c2fe0943bcfea0178a1926be6fc7 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Wed, 18 Nov 2009 12:44:18 +1100 Subject: add an in memory ringbuffer where we store the last 500000 log entries regardless of log level. add commandt to extract this in memory buffer and to clear it (This used to be ctdb commit 29d2ee8d9c6c6f36b2334480f646d6db209f370e) --- ctdb/lib/util/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ctdb/lib/util/debug.c') diff --git a/ctdb/lib/util/debug.c b/ctdb/lib/util/debug.c index 63ca03b5a7..6597570348 100644 --- a/ctdb/lib/util/debug.c +++ b/ctdb/lib/util/debug.c @@ -90,7 +90,7 @@ void do_debug_add(const char *format, ...) } #define DEBUGLVL(lvl) ((lvl) <= LogLevel) -#define DEBUG(lvl, x) do { if ((lvl) <= LogLevel) { this_log_level = (lvl); do_debug x; }} while (0) +#define DEBUG(lvl, x) do { this_log_level = (lvl); log_ringbuffer x; if ((lvl) <= LogLevel) { do_debug x; }} while (0) #define DEBUGADD(lvl, x) do { if ((lvl) <= LogLevel) { this_log_level = (lvl); do_debug_add x; }} while (0) static void print_asc(int level, const uint8_t *buf, size_t len) -- cgit From e28c652ccabad2a3df6f60d95bcd4f32a3feaba8 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Fri, 4 Dec 2009 11:45:37 +1100 Subject: Dont store debug level DEBUG_DEBUG in the in-memory ringbuffer. It is unlikely we will need something this verbose for normal troubleshooting. This allows us to keep a significantly longer time interval of log messages in the 500k slots available in the ringbuffer. (This used to be ctdb commit cc99c05c0c6484ad574039a454e6133852cb41fa) --- ctdb/lib/util/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ctdb/lib/util/debug.c') diff --git a/ctdb/lib/util/debug.c b/ctdb/lib/util/debug.c index 6597570348..d4d3bd643e 100644 --- a/ctdb/lib/util/debug.c +++ b/ctdb/lib/util/debug.c @@ -90,7 +90,7 @@ void do_debug_add(const char *format, ...) } #define DEBUGLVL(lvl) ((lvl) <= LogLevel) -#define DEBUG(lvl, x) do { this_log_level = (lvl); log_ringbuffer x; if ((lvl) <= LogLevel) { do_debug x; }} while (0) +#define DEBUG(lvl, x) do { this_log_level = (lvl); if ((lvl) < DEBUG_DEBUG) { log_ringbuffer x; } if ((lvl) <= LogLevel) { do_debug x; }} while (0) #define DEBUGADD(lvl, x) do { if ((lvl) <= LogLevel) { this_log_level = (lvl); do_debug_add x; }} while (0) static void print_asc(int level, const uint8_t *buf, size_t len) -- cgit From a309287947f49dc06beeaea0300e1a41ab3d4ba7 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 19 Dec 2009 11:40:06 +0100 Subject: move DEBUG* macros to one place metze (This used to be ctdb commit 4b4dd5d7f81bf226e05c7f3d40087043da1517a2) --- ctdb/lib/util/debug.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'ctdb/lib/util/debug.c') diff --git a/ctdb/lib/util/debug.c b/ctdb/lib/util/debug.c index d4d3bd643e..1cbaa230f1 100644 --- a/ctdb/lib/util/debug.c +++ b/ctdb/lib/util/debug.c @@ -89,10 +89,6 @@ void do_debug_add(const char *format, ...) va_end(ap); } -#define DEBUGLVL(lvl) ((lvl) <= LogLevel) -#define DEBUG(lvl, x) do { this_log_level = (lvl); if ((lvl) < DEBUG_DEBUG) { log_ringbuffer x; } if ((lvl) <= LogLevel) { do_debug x; }} while (0) -#define DEBUGADD(lvl, x) do { if ((lvl) <= LogLevel) { this_log_level = (lvl); do_debug_add x; }} while (0) - static void print_asc(int level, const uint8_t *buf, size_t len) { int i; -- cgit From 9fbb191b78a0cef008166fbc2bdad454735b8e1c Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 19 Jul 2010 19:29:09 +0930 Subject: logging: give a unique logging name to each forked child. This means we can distinguish which child is logging, esp. via syslog where we have no pid. Signed-off-by: Rusty Russell (This used to be ctdb commit 68b3761a0874429b90731741f0531f76dcfbb081) --- ctdb/lib/util/debug.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ctdb/lib/util/debug.c') diff --git a/ctdb/lib/util/debug.c b/ctdb/lib/util/debug.c index 1cbaa230f1..e9365d88f6 100644 --- a/ctdb/lib/util/debug.c +++ b/ctdb/lib/util/debug.c @@ -42,13 +42,15 @@ static void _do_debug_v(const char *format, va_list ap) strftime(tbuf,sizeof(tbuf)-1,"%Y/%m/%d %H:%M:%S", tm); - fprintf(stderr, "%s.%06u [%5u]: %s", tbuf, (unsigned)t.tv_usec, (unsigned)getpid(), s); + fprintf(stderr, "%s.%06u [%s%5u]: %s", tbuf, (unsigned)t.tv_usec, + debug_extra, (unsigned)getpid(), s); fflush(stderr); free(s); } /* default logging function */ void (*do_debug_v)(const char *, va_list ap) = _do_debug_v; +const char *debug_extra = ""; void do_debug(const char *format, ...) { -- cgit