From 2af18872b7aec25d0ab4bc9342e0287bdace2151 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Mon, 10 Nov 2008 18:07:20 +0000 Subject: [PATCH] ebl Update after fatal signal debugging git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@8031 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/cats/protos.h | 1 + bacula/src/cats/sql.c | 24 ++++++++++++++++++++++++ bacula/src/dird/dird.c | 3 ++- bacula/src/jcr.h | 4 ++++ bacula/src/lib/jcr.c | 16 ++++++++++++++++ bacula/technotes-2.5 | 2 ++ 6 files changed, 49 insertions(+), 1 deletion(-) diff --git a/bacula/src/cats/protos.h b/bacula/src/cats/protos.h index f0ef589ef3..eba966bf73 100644 --- a/bacula/src/cats/protos.h +++ b/bacula/src/cats/protos.h @@ -58,6 +58,7 @@ void db_start_transaction(JCR *jcr, B_DB *mdb); void db_end_transaction(JCR *jcr, B_DB *mdb); int db_int64_handler(void *ctx, int num_fields, char **row); void db_thread_cleanup(); +void _db_print_dbg(JCR *jcr, FILE *fp); /* sql_create.c */ bool db_create_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar); diff --git a/bacula/src/cats/sql.c b/bacula/src/cats/sql.c index 052d37af49..a100f2cd77 100644 --- a/bacula/src/cats/sql.c +++ b/bacula/src/cats/sql.c @@ -740,4 +740,28 @@ bool db_open_batch_connexion(JCR *jcr, B_DB *mdb) return true; } +/* + * !!! WARNING !!! Use this function only when bacula is stopped. + * ie, after a fatal signal and before exiting the program + * Print information about a B_DB object. + */ +void _db_print_dbg(JCR *jcr, FILE *fp) +{ + B_DB *mdb = jcr->db; + + if (!mdb) { + return; + } + + fprintf(fp, "B_DB %p db_name=%s db_user=%s connected=%i\n", + mdb, NPRTB(mdb->db_name), NPRTB(mdb->db_user), mdb->connected); + fprintf(fp, "\tcmd=\"%s\" changes=%i\n", NPRTB(mdb->cmd), mdb->changes); + if (mdb->lock.valid == RWLOCK_VALID) { + fprintf(fp, "\tRWLOCK %p w_active=%i w_wait=%i\n", &mdb->lock, mdb->lock.w_active, mdb->lock.w_wait); +#ifndef HAVE_WIN32 + fprintf(fp, "\t\tthreadid=0x%x mutex=%p\n", (int)mdb->lock.writer_id, &mdb->lock.mutex); +#endif + } +} + #endif /* HAVE_SQLITE3 || HAVE_MYSQL || HAVE_SQLITE || HAVE_POSTGRESQL*/ diff --git a/bacula/src/dird/dird.c b/bacula/src/dird/dird.c index 633cb91264..2f2092df40 100644 --- a/bacula/src/dird/dird.c +++ b/bacula/src/dird/dird.c @@ -282,7 +282,6 @@ int main (int argc, char *argv[]) FDConnectTimeout = (int)director->FDConnectTimeout; SDConnectTimeout = (int)director->SDConnectTimeout; - #if !defined(HAVE_WIN32) signal(SIGHUP, reload_config); #endif @@ -313,6 +312,8 @@ int main (int argc, char *argv[]) init_job_server(director->MaxConcurrentJobs); + dbg_add_hook(_db_print_dbg); /* used to debug B_DB connexion after fatal signal */ + // init_device_resources(); Dmsg0(200, "wait for next job\n"); diff --git a/bacula/src/jcr.h b/bacula/src/jcr.h index 386335eba0..b228073cae 100644 --- a/bacula/src/jcr.h +++ b/bacula/src/jcr.h @@ -466,4 +466,8 @@ extern void b_free_jcr(const char *file, int line, JCR *jcr); extern void free_jcr(JCR *jcr); #endif +/* Used to display job information after a fatal signal */ +typedef void (dbg_jcr_hook)(JCR *jcr, FILE *fp); +void dbg_add_hook(dbg_jcr_hook *fct); + #endif /* __JCR_H_ */ diff --git a/bacula/src/lib/jcr.c b/bacula/src/lib/jcr.c index 48d366ed49..58a155b08b 100644 --- a/bacula/src/lib/jcr.c +++ b/bacula/src/lib/jcr.c @@ -1008,6 +1008,17 @@ extern "C" void timeout_handler(int sig) return; /* thus interrupting the function */ } +/* Used to display mdb information after a fatal signal */ +#define MAX_DBG_HOOK 10 +static dbg_jcr_hook *dbg_hooks[MAX_DBG_HOOK]; +static int dbg_jcr_handler_count; + +void dbg_add_hook(dbg_jcr_hook *fct) +{ + ASSERT(dbg_jcr_handler_count < MAX_DBG_HOOK); + dbg_hooks[dbg_jcr_handler_count++] = fct; +} + /* * !!! WARNING !!! * @@ -1048,6 +1059,11 @@ void _print_jcr_dbg(FILE *fp) fprintf(fp, "\tdequeing=%i\n", jcr->dequeuing); fprintf(fp, "\tdb=%p db_batch=%p batch_started=%i\n", jcr->db, jcr->db_batch, jcr->batch_started); + + for(int i=0; i < dbg_jcr_handler_count; i++) { + dbg_jcr_hook *fct = dbg_hooks[i]; + fct(jcr, fp); + } } } diff --git a/bacula/technotes-2.5 b/bacula/technotes-2.5 index d8af59b567..a774fd5028 100644 --- a/bacula/technotes-2.5 +++ b/bacula/technotes-2.5 @@ -10,6 +10,8 @@ filepattern (restore with regex in bsr) mixed priorities General: +11Nov08 +ebl Add db and rwlock debug after a fatal signal. 10Nov08 ebl Fix maxwaittime to fit documentation, this time is now counted from the job start and group all wait periods. -- 2.39.5