From ccdaee099302c053e628e0953dba96d1d17f3ad9 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Tue, 11 Nov 2008 13:13:07 +0000 Subject: [PATCH] ebl Add Plugin debug after a fatal signal. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@8033 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/cats/protos.h | 2 +- bacula/src/cats/sql.c | 2 +- bacula/src/dird/dird.c | 2 +- bacula/src/filed/fd_plugins.c | 17 +++++++++++++++++ bacula/src/jcr.h | 6 +++--- bacula/src/lib/jcr.c | 16 +++++++++------- bacula/src/lib/plugins.c | 34 ++++++++++++++++++++++++++++++++++ bacula/src/lib/plugins.h | 5 +++++ bacula/src/lib/signal.c | 15 +++++++++++---- bacula/technotes-2.5 | 1 + 10 files changed, 83 insertions(+), 17 deletions(-) diff --git a/bacula/src/cats/protos.h b/bacula/src/cats/protos.h index eba966bf73..1e3996dca6 100644 --- a/bacula/src/cats/protos.h +++ b/bacula/src/cats/protos.h @@ -58,7 +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); +void _dbg_print_db(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 a100f2cd77..756c1e53d0 100644 --- a/bacula/src/cats/sql.c +++ b/bacula/src/cats/sql.c @@ -745,7 +745,7 @@ bool db_open_batch_connexion(JCR *jcr, B_DB *mdb) * 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) +void _dbg_print_db(JCR *jcr, FILE *fp) { B_DB *mdb = jcr->db; diff --git a/bacula/src/dird/dird.c b/bacula/src/dird/dird.c index 2f2092df40..df6f418fe8 100644 --- a/bacula/src/dird/dird.c +++ b/bacula/src/dird/dird.c @@ -312,7 +312,7 @@ 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 */ + dbg_jcr_add_hook(_dbg_print_db); /* used to debug B_DB connexion after fatal signal */ // init_device_resources(); diff --git a/bacula/src/filed/fd_plugins.c b/bacula/src/filed/fd_plugins.c index c0aa2eed02..a7a9fe88f7 100644 --- a/bacula/src/filed/fd_plugins.c +++ b/bacula/src/filed/fd_plugins.c @@ -481,6 +481,21 @@ bool plugin_set_attributes(JCR *jcr, ATTR *attr, BFILE *ofd) return true; } +void dump_fd_plugin(Plugin *plugin, FILE *fp) +{ + if (!plugin) { + return ; + } + pInfo *info = (pInfo *) plugin->pinfo; + fprintf(fp, "\tversion=%d\n", info->version); + fprintf(fp, "\tdate=%s\n", NPRTB(info->plugin_date)); + fprintf(fp, "\tmagic=%s\n", NPRTB(info->plugin_magic)); + fprintf(fp, "\tauthor=%s\n", NPRTB(info->plugin_author)); + fprintf(fp, "\tlicence=%s\n", NPRTB(info->plugin_license)); + fprintf(fp, "\tversion=%s\n", NPRTB(info->plugin_version)); + fprintf(fp, "\tdescription=%s\n", NPRTB(info->plugin_description)); +} + /* * This entry point is called internally by Bacula to ensure * that the plugin IO calls come into this code. @@ -516,6 +531,8 @@ void load_fd_plugins(const char *plugin_dir) Dmsg1(dbglvl, "Loaded plugin: %s\n", plugin->file); } + + dbg_plugin_add_hook(dump_fd_plugin); } /* diff --git a/bacula/src/jcr.h b/bacula/src/jcr.h index b228073cae..1339948812 100644 --- a/bacula/src/jcr.h +++ b/bacula/src/jcr.h @@ -466,8 +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); +/* Used to display specific job information after a fatal signal */ +typedef void (dbg_jcr_hook_t)(JCR *jcr, FILE *fp); +void dbg_jcr_add_hook(dbg_jcr_hook_t *fct); #endif /* __JCR_H_ */ diff --git a/bacula/src/lib/jcr.c b/bacula/src/lib/jcr.c index 58a155b08b..65e48d816a 100644 --- a/bacula/src/lib/jcr.c +++ b/bacula/src/lib/jcr.c @@ -1008,24 +1008,26 @@ extern "C" void timeout_handler(int sig) return; /* thus interrupting the function */ } -/* Used to display mdb information after a fatal signal */ +/* Used to display specific daemon information after a fatal signal + * (like B_DB in the director) + */ #define MAX_DBG_HOOK 10 -static dbg_jcr_hook *dbg_hooks[MAX_DBG_HOOK]; +static dbg_jcr_hook_t *dbg_jcr_hooks[MAX_DBG_HOOK]; static int dbg_jcr_handler_count; -void dbg_add_hook(dbg_jcr_hook *fct) +void dbg_jcr_add_hook(dbg_jcr_hook_t *fct) { ASSERT(dbg_jcr_handler_count < MAX_DBG_HOOK); - dbg_hooks[dbg_jcr_handler_count++] = fct; + dbg_jcr_hooks[dbg_jcr_handler_count++] = fct; } /* * !!! WARNING !!! * - * This function should be used ONLY after a violent signal. We walk through the + * This function should be used ONLY after a fatal signal. We walk through the * JCR chain without doing any lock, bacula should not be running. */ -void _print_jcr_dbg(FILE *fp) +void _dbg_print_jcr(FILE *fp) { char buf1[128], buf2[128], buf3[128], buf4[128]; if (!jcrs) { @@ -1061,7 +1063,7 @@ void _print_jcr_dbg(FILE *fp) 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]; + dbg_jcr_hook_t *fct = dbg_jcr_hooks[i]; fct(jcr, fp); } } diff --git a/bacula/src/lib/plugins.c b/bacula/src/lib/plugins.c index 6cc5e43286..d56b41ade2 100644 --- a/bacula/src/lib/plugins.c +++ b/bacula/src/lib/plugins.c @@ -207,3 +207,37 @@ void unload_plugins() delete plugin_list; plugin_list = NULL; } + +/* + * Dump plugin information + * Each daemon can register a hook that will be called + * after a fatal signal. + */ +#define DBG_MAX_HOOK 10 +static dbg_plugin_hook_t *dbg_plugin_hooks[DBG_MAX_HOOK]; +static int dbg_plugin_hook_count=0; + +void dbg_plugin_add_hook(dbg_plugin_hook_t *fct) +{ + ASSERT(dbg_plugin_hook_count < DBG_MAX_HOOK); + dbg_plugin_hooks[dbg_plugin_hook_count++] = fct; +} + +void _dbg_print_plugin(FILE *fp) +{ + Plugin *plugin; + fprintf(fp, "Attempt to dump plugins\n"); + + if (!plugin_list) { + return; + } + + foreach_alist(plugin, plugin_list) { + for(int i=0; i < dbg_plugin_hook_count; i++) { + dbg_plugin_hook_t *fct = dbg_plugin_hooks[i]; + fprintf(fp, "Plugin %p name=\"%s\" disabled=%d\n", + plugin, plugin->file, plugin->disabled); + fct(plugin, fp); + } + } +} diff --git a/bacula/src/lib/plugins.h b/bacula/src/lib/plugins.h index 60c1d280ab..9934a4eb10 100644 --- a/bacula/src/lib/plugins.h +++ b/bacula/src/lib/plugins.h @@ -79,5 +79,10 @@ extern Plugin *new_plugin(); extern bool load_plugins(void *binfo, void *bfuncs, const char *plugin_dir, const char *type); extern void unload_plugins(); +/* Each daemon can register a debug hook that will be called + * after a fatal signal + */ +typedef void (dbg_plugin_hook_t)(Plugin *plug, FILE *fp); +extern void dbg_plugin_add_hook(dbg_plugin_hook_t *fct); #endif /* __PLUGINS_H */ diff --git a/bacula/src/lib/signal.c b/bacula/src/lib/signal.c index 5e7de3aa31..941c6f7091 100644 --- a/bacula/src/lib/signal.c +++ b/bacula/src/lib/signal.c @@ -73,7 +73,9 @@ const char *get_signal_name(int sig) } /* defined in jcr.c */ -extern void _print_jcr_dbg(FILE *fp); +extern void _dbg_print_jcr(FILE *fp); +/* defined in plugin.c */ +extern void _dbg_print_plugin(FILE *fp); /* * !!! WARNING !!! @@ -81,7 +83,7 @@ extern void _print_jcr_dbg(FILE *fp); * This function should be used ONLY after a violent signal. We walk through the * JCR chain without doing any lock, bacula should not be running. */ -static void print_bacula_dbg() +static void dbg_print_bacula() { char buf[512]; @@ -92,7 +94,12 @@ static void print_bacula_dbg() fp = stderr; } - _print_jcr_dbg(fp); + /* Print also B_DB and RWLOCK structure + * Can add more info about JCR with dbg_jcr_add_hook() + */ + _dbg_print_jcr(fp); + + _dbg_print_plugin(fp); if (fp != stderr) { fclose(fp); @@ -197,7 +204,7 @@ extern "C" void signal_handler(int sig) Dmsg0(500, "Done waitpid\n"); fprintf(stderr, _("Traceback complete, attempting cleanup ...\n")); /* print information about the current state into working/.bactrace */ - print_bacula_dbg(); + dbg_print_bacula(); exit_handler(sig); /* clean up if possible */ Dmsg0(500, "Done exit_handler\n"); } else { diff --git a/bacula/technotes-2.5 b/bacula/technotes-2.5 index a774fd5028..78777a790a 100644 --- a/bacula/technotes-2.5 +++ b/bacula/technotes-2.5 @@ -11,6 +11,7 @@ mixed priorities General: 11Nov08 +ebl Add Plugin debug after a fatal signal. ebl Add db and rwlock debug after a fatal signal. 10Nov08 ebl Fix maxwaittime to fit documentation, this time is now counted -- 2.39.5