Skip to content

Commit

Permalink
Fix bareos-dir reload problems
Browse files Browse the repository at this point in the history
This commit fixes two problems:
- when trying to load an invalid configuration, resources are not
  unlocked properly in all cases.
- not all configuration errors have been detected as such by the reload
  command.

Fixes #750: Trying to reload the Director configuration after adding a
            second director resource leaves the Director in an invalid state
Fixes #780: Reload configuration error prevents bconsole connecting anymore
  • Loading branch information
joergsteffens committed Feb 16, 2017
1 parent cdea114 commit 14a0e1e
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/dird/dird.c
Expand Up @@ -1062,7 +1062,6 @@ static bool check_resources()
}
}

UnlockRes();
if (OK) {
close_msg(NULL); /* close temp message handler */
init_msg(NULL, me->messages); /* open daemon message handler */
Expand All @@ -1075,6 +1074,7 @@ static bool check_resources()
}

bail_out:
UnlockRes();
return OK;
}

Expand Down
2 changes: 1 addition & 1 deletion src/dird/ua_cmds.c
Expand Up @@ -357,7 +357,7 @@ static struct ua_cmdstruct commands[] = {
NT_("job=<job-name> client=<client-name> fileset=<fileset-name> level=<level>\n"
"\tstorage=<storage-name> where=<directory-prefix> when=<universal-time-specification>\n"
"\tpool=<pool-name> pluginoptions=<plugin-options-string> accurate=<yes|no> comment=<text>\n"
"\tspooldata=<yes|no> priority=<number> jobid=<jobid> catalog=<catalog> migrationjob=<>\n"
"\tspooldata=<yes|no> priority=<number> jobid=<jobid> catalog=<catalog> migrationjob=<job-name>\n"
"\tbackupclient=<client-name> backupformat=<format> nextpool=<pool-name>\n"
"\tsince=<universal-time-specification> verifyjob=<job-name> verifylist=<verify-list>\n"
"\tmigrationjob=<complete_name> yes"), false, true },
Expand Down
19 changes: 4 additions & 15 deletions src/dird/ua_configure.c
Expand Up @@ -43,23 +43,12 @@ static void configure_lex_error_handler(const char *file, int line, LEX *lc, con
/*
* This function is an error handler, used by lex.
*/
va_list ap;
int len, maxlen;
POOL_MEM buf(PM_NAME);
va_list ap;

while (1) {
maxlen = buf.size() - 1;
va_start(ap, msg);
len = bvsnprintf(buf.c_str(), maxlen, msg, ap);
va_end(ap);

if (len < 0 || len >= (maxlen - 5)) {
buf.realloc_pm(maxlen + maxlen / 2);
continue;
}

break;
}
va_start(ap, msg);
buf.bvsprintf(msg, ap);
va_end(ap);

configure_lex_error_handler(file, line, lc, buf);
}
Expand Down
29 changes: 3 additions & 26 deletions src/lib/lex.c
Expand Up @@ -110,6 +110,8 @@ static void s_err(const char *file, int line, LEX *lc, const char *msg, ...)
} else {
e_msg(file, line, lc->err_type, 0, _("Config error: %s\n"), buf.c_str());
}

lc->error_counter++;
}

/*
Expand Down Expand Up @@ -199,6 +201,7 @@ LEX *lex_close_file(LEX *lf)
lf->line = NULL;
if (of) {
of->options = lf->options; /* preserve options */
of->error_counter += lf->error_counter; /* summarize the errors */
memcpy(lf, of, sizeof(LEX));
Dmsg1(dbglvl, "Restart scan of cfg file %s\n", of->fname);
} else {
Expand All @@ -209,32 +212,6 @@ LEX *lex_close_file(LEX *lf)
return lf;
}

LEX *lex_close_buffer(LEX *lf)
{
LEX *of;

if (lf == NULL) {
Emsg0(M_ABORT, 0, _("Close of NULL file\n"));
}

of = lf->next;

free_memory(lf->line);
free_memory(lf->str);
lf->line = NULL;
if (of) {
of->options = lf->options; /* preserve options */
memcpy(lf, of, sizeof(LEX));
Dmsg1(dbglvl, "Restart scan of cfg file %s\n", of->fname);
} else {
of = lf;
lf = NULL;
}
free(of);

return lf;
}

/*
* Add lex structure for an included config file.
*/
Expand Down
1 change: 0 additions & 1 deletion src/lib/protos.h
Expand Up @@ -265,7 +265,6 @@ void initialize_json();

/* lex.c */
LEX *lex_close_file(LEX *lf);
LEX *lex_close_buffer(LEX *lf);
LEX *lex_open_file(LEX *lf,
const char *fname,
LEX_ERROR_HANDLER *scan_error,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/res.c
Expand Up @@ -49,7 +49,7 @@ union URES {

static int res_locked = 0; /* resource chain lock count -- for debug */

/* #define TRACE_RES */
// #define TRACE_RES

void b_LockRes(const char *file, int line)
{
Expand All @@ -60,7 +60,7 @@ void b_LockRes(const char *file, int line)
res_locked, my_config->m_res_lock.w_active, file, line);

if (res_locked) {
Pmsg2(000, "LockRes writerid=%d myid=%d\n",
Pmsg2(000, "LockRes writerid=%lu myid=%lu\n",
my_config->m_res_lock.writer_id, pthread_self());
}
#endif
Expand Down

0 comments on commit 14a0e1e

Please sign in to comment.