From 1ffa40b044fe6c66c9cfe1e996d09a704b4aa197 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sat, 28 Feb 2004 09:55:46 +0000 Subject: [PATCH] First cut SIGHUP while jobs running + apply Phil's Gnome 1.4 patch + major update to Win32 installer git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1096 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/kernstodo | 7 +++- bacula/src/dird/backup.c | 2 + bacula/src/dird/dird.c | 81 ++++++++++++++++++++++++++++++++----- bacula/src/jcr.h | 2 +- bacula/src/lib/parse_conf.c | 20 ++++++--- bacula/src/lib/parse_conf.h | 53 ++++++++++++------------ bacula/src/version.h | 4 +- 7 files changed, 123 insertions(+), 46 deletions(-) diff --git a/bacula/kernstodo b/bacula/kernstodo index 9480d9e151..481fcd8ae6 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -1,5 +1,5 @@ Kern's ToDo List - 27 January 2004 + 28 February 2004 Documentation to do: (any release a little bit at a time) - DB upgrade to version 5 in bacula-1.27b, DB upgrade to @@ -71,12 +71,13 @@ For 1.33 Testing/Documentation: http://howtos.linux.com/guides/nag2/x-087-2-nfs.mountd.shtml For 1.33 +- Look at installation file permissions with Scott so that make install + and the rpms agree. - Add a regression test for dbcheck. - Add disk seeking on restore. - Add atime preservation. - Allow for optional cancelling of SD and FD in case DIR gets a fatal error. Requested by Jesse Guardiani -- Remove h_errno from bnet.c by including proper header. - Do not err job if could not write bootstrap file. - Bizarre message: Error: Could not open WriteBootstrap file: - Build console in client only build. @@ -1392,3 +1393,5 @@ Block Position: 0 - Look at ASSERT() at 384 src/lib/bnet.c - Dates are wrong in restore list from Win32 FD. - Dates are wrong in catalog from Win32 FD. +- Remove h_errno from bnet.c by including proper header. + diff --git a/bacula/src/dird/backup.c b/bacula/src/dird/backup.c index d570e274ee..9e3d2354ea 100644 --- a/bacula/src/dird/backup.c +++ b/bacula/src/dird/backup.c @@ -456,6 +456,8 @@ static void backup_cleanup(JCR *jcr, int TermCode, char *since, FILESET_DBR *fsr jobstatus_to_ascii(jcr->FDJobStatus, fd_term_msg, sizeof(fd_term_msg)); jobstatus_to_ascii(jcr->SDJobStatus, sd_term_msg, sizeof(sd_term_msg)); +// bmicrosleep(40, 0); /* for debugging SIGHUP */ + Jmsg(jcr, msg_type, 0, _("Bacula " VERSION " (" LSMDATE "): %s\n\ JobId: %d\n\ Job: %s\n\ diff --git a/bacula/src/dird/dird.c b/bacula/src/dird/dird.c index 34aecc0e5a..479c9d1ebd 100644 --- a/bacula/src/dird/dird.c +++ b/bacula/src/dird/dird.c @@ -52,6 +52,7 @@ void store_replace(LEX *lc, RES_ITEM *item, int index, int pass); static char *configfile = NULL; static char *runjob = NULL; static int background = 1; +static void init_reload(void); /* Globals Exported */ DIRRES *director; /* Director resource */ @@ -105,6 +106,7 @@ int main (int argc, char *argv[]) my_name_is(argc, argv, "bacula-dir"); textdomain("bacula-dir"); init_msg(NULL, NULL); /* initialize message handler */ + init_reload(); daemon_start_time = time(NULL); while ((ch = getopt(argc, argv, "c:d:fg:r:stu:v?")) != -1) { @@ -272,12 +274,49 @@ static void terminate_dird(int sig) exit(sig); } +struct RELOAD_TABLE { + int job_count; + RES **res_table; +}; + +static const int max_reloads = 10; +static RELOAD_TABLE reload_table[max_reloads]; + +static void init_reload(void) +{ + for (int i=0; i < max_reloads; i++) { + reload_table[i].job_count = 0; + reload_table[i].res_table = NULL; + } +} + +/* + * Called here at the end of every job that was + * hooked decrementing the active job_count. When + * it goes to zero, no one is using the associated + * resource table, so free it. + */ +static void reload_job_end_cb(JCR *jcr) +{ + int i = jcr->reload_id - 1; + RES **res_tab; + Dmsg1(000, "reload job_end JobId=%d\n", jcr->JobId); + if (--reload_table[i].job_count <= 0) { + int num = r_last - r_first + 1; + res_tab = reload_table[i].res_table; + Dmsg0(000, "Freeing resources\n"); + for (int j=0; j die */ } - already_here = TRUE; + already_here = true; sigfillset(&set); sigprocmask(SIG_BLOCK, &set, NULL); lock_jcr_chain(); LockRes(); + for (int i=0; i < max_reloads; i++) { + if (reload_table[i].res_table == NULL) { + table = i; + break; + } + } + if (table < 0) { + Jmsg(NULL, M_ERROR, 0, _("Too many reload requests.\n")); + goto bail_out; + } + + /* + * Hook all active jobs that are not already hooked (i.e. + * reload_id == 0 + */ foreach_jcr(jcr) { - if (jcr->JobId != 0) { /* this is a console */ + /* JobId==0 => console */ + if (jcr->JobId != 0 && jcr->reload_id == 0) { + reload_table[table].job_count++; + jcr->reload_id = table + 1; + job_end_push(jcr, reload_job_end_cb); njobs++; } free_locked_jcr(jcr); } + Dmsg1(000, "Reload_config njobs=%d\n", njobs); if (njobs > 0) { - goto bail_out; + reload_table[table].res_table = save_config_resources(); + Dmsg1(000, "Saved old config in table %d\n", table); + } else { + free_config_resources(); } - free_config_resources(); - + Dmsg0(000, "Calling parse config\n"); parse_config(configfile); + Dmsg0(000, "Reloaded config file\n"); if (!check_resources()) { Jmsg(NULL, M_ERROR_TERM, 0, _("Please correct configuration file: %s\n"), configfile); } diff --git a/bacula/src/jcr.h b/bacula/src/jcr.h index 0a4ca14df3..185f461015 100644 --- a/bacula/src/jcr.h +++ b/bacula/src/jcr.h @@ -103,7 +103,7 @@ struct JCR { JCR_free_HANDLER *daemon_free_jcr; /* Local free routine */ dlist *msg_queue; /* Queued messages */ alist job_end_push; /* Job end pushed calls */ - int restart_count; /* SIGHUP restart count */ + int reload_id; /* SIGHUP reload table id */ bool dequeuing; /* dequeuing messages */ POOLMEM *errmsg; /* edited error message */ char Job[MAX_NAME_LENGTH]; /* Unique name of this Job */ diff --git a/bacula/src/lib/parse_conf.c b/bacula/src/lib/parse_conf.c index 02d2a5e183..a11f5d6ee1 100755 --- a/bacula/src/lib/parse_conf.c +++ b/bacula/src/lib/parse_conf.c @@ -801,13 +801,21 @@ parse_config(char *cf) * Free configuration resources * */ -void -free_config_resources() +void free_config_resources() { - RES *res; for (int i=r_first; i<=r_last; i++) { - res = resources[i-r_first].res_head; - free_resource(res, i); - res = NULL; + free_resource(resources[i-r_first].res_head, i); + resources[i-r_first].res_head = NULL; } } + +RES **save_config_resources() +{ + int num = r_last - r_first + 1; + RES **res = (RES **)malloc(num*sizeof(RES *)); + for (int i=0; i