Skip to content

Commit

Permalink
Rename global resource in director,
Browse files Browse the repository at this point in the history
Rename the global director variable to the same name used in the storage
daemon and filedaemon which is me. Also drop the two global variables
for the FD and SD timeout as those are part of the global resource
anyway so we can reference the me variable and don't need to polute the
global naming space of the binary with them.
  • Loading branch information
Marco van Wieringen committed Feb 17, 2015
1 parent 7c97135 commit 69ba056
Show file tree
Hide file tree
Showing 18 changed files with 93 additions and 105 deletions.
20 changes: 10 additions & 10 deletions src/dird/authenticate.c
Expand Up @@ -72,7 +72,7 @@ bool authenticate_storage_daemon(JCR *jcr, STORERES *store)
/*
* Send my name to the Storage daemon then do authentication
*/
bstrncpy(dirname, director->hdr.name, sizeof(dirname));
bstrncpy(dirname, me->hdr.name, sizeof(dirname));
bash_spaces(dirname);

/*
Expand Down Expand Up @@ -196,7 +196,7 @@ bool authenticate_file_daemon(JCR *jcr)
/*
* Send my name to the File daemon then do authentication
*/
bstrncpy(dirname, director->name(), sizeof(dirname));
bstrncpy(dirname, me->name(), sizeof(dirname));
bash_spaces(dirname);

/*
Expand Down Expand Up @@ -343,26 +343,26 @@ bool authenticate_user_agent(UAContext *uac)
/*
* TLS Requirement
*/
if (director->tls_enable) {
if (director->tls_require) {
if (me->tls_enable) {
if (me->tls_require) {
tls_local_need = BNET_TLS_REQUIRED;
} else {
tls_local_need = BNET_TLS_OK;
}
}

tls_authenticate = director->tls_authenticate;
tls_authenticate = me->tls_authenticate;

if (tls_authenticate) {
tls_local_need = BNET_TLS_REQUIRED;
}

if (director->tls_verify_peer) {
verify_list = director->tls_allowed_cns;
if (me->tls_verify_peer) {
verify_list = me->tls_allowed_cns;
}

auth_success = cram_md5_challenge(ua, director->password, tls_local_need, compatible) &&
cram_md5_respond(ua, director->password, &tls_remote_need, &compatible);
auth_success = cram_md5_challenge(ua, me->password, tls_local_need, compatible) &&
cram_md5_respond(ua, me->password, &tls_remote_need, &compatible);
} else {
unbash_spaces(name);
cons = (CONRES *)GetResWithName(R_CONSOLE, name);
Expand Down Expand Up @@ -425,7 +425,7 @@ bool authenticate_user_agent(UAContext *uac)
if (cons) {
tls_ctx = cons->tls_ctx;
} else {
tls_ctx = director->tls_ctx;
tls_ctx = me->tls_ctx;
}

/*
Expand Down
6 changes: 3 additions & 3 deletions src/dird/backup.c
Expand Up @@ -342,7 +342,7 @@ bool do_native_backup(JCR *jcr)
/*
* Start conversation with Storage daemon
*/
if (!connect_to_storage_daemon(jcr, 10, SDConnectTimeout, 1)) {
if (!connect_to_storage_daemon(jcr, 10, me->SDConnectTimeout, 1)) {
return false;
}

Expand Down Expand Up @@ -374,7 +374,7 @@ bool do_native_backup(JCR *jcr)
Dmsg0(150, "Storage daemon connection OK\n");

jcr->setJobStatus(JS_WaitFD);
if (!connect_to_file_daemon(jcr, 10, FDConnectTimeout, 1)) {
if (!connect_to_file_daemon(jcr, 10, me->FDConnectTimeout, 1)) {
goto bail_out;
}

Expand Down Expand Up @@ -483,7 +483,7 @@ bool do_native_backup(JCR *jcr)
jcr->setJobStatus(JS_ErrorTerminated);
Dmsg1(400, "wait for sd. use=%d\n", jcr->use_count());
/* Cancel SD */
wait_for_job_termination(jcr, FDConnectTimeout);
wait_for_job_termination(jcr, me->FDConnectTimeout);
Dmsg1(400, "after wait for sd. use=%d\n", jcr->use_count());
return false;
}
Expand Down
99 changes: 45 additions & 54 deletions src/dird/dird.c
Expand Up @@ -70,9 +70,7 @@ static void init_reload(void);
static CONFIG *config;

/* Globals Exported */
DIRRES *director; /* Director resource */
int FDConnectTimeout;
int SDConnectTimeout;
DIRRES *me; /* "Global" daemon resource */
char *configfile = NULL;
void *start_heap;

Expand Down Expand Up @@ -301,18 +299,18 @@ int main (int argc, char *argv[])
init_stack_dump(); /* grab new pid */
}
/* Create pid must come after we are a daemon -- so we have our final pid */
create_pid_file(director->pid_directory, "bareos-dir",
get_first_port_host_order(director->DIRaddrs));
read_state_file(director->working_directory, "bareos-dir",
get_first_port_host_order(director->DIRaddrs));
create_pid_file(me->pid_directory, "bareos-dir",
get_first_port_host_order(me->DIRaddrs));
read_state_file(me->working_directory, "bareos-dir",
get_first_port_host_order(me->DIRaddrs));
}

set_jcr_in_tsd(INVALID_JCR);
set_thread_concurrency(director->MaxConcurrentJobs * 2 +
set_thread_concurrency(me->MaxConcurrentJobs * 2 +
4 /* UA */ + 5 /* sched+watchdog+jobsvr+misc */);
lmgr_init_thread(); /* initialize the lockmanager stack */

load_dir_plugins(director->plugin_directory);
load_dir_plugins(me->plugin_directory);

/* If we are in testing mode, we don't try to fix the catalog */
cat_op mode=(test_config)?CHECK_CONNECTION:UPDATE_AND_FIX;
Expand All @@ -329,29 +327,26 @@ int main (int argc, char *argv[])
Jmsg((JCR *)NULL, M_ERROR_TERM, 0, _("Please correct configuration file: %s\n"), configfile);
}

my_name_is(0, NULL, director->name()); /* set user defined name */
my_name_is(0, NULL, me->name()); /* set user defined name */

cleanup_old_files();

p_db_log_insert = (db_log_insert_func)dir_db_log_insert;

FDConnectTimeout = (int)director->FDConnectTimeout;
SDConnectTimeout = (int)director->SDConnectTimeout;

#if !defined(HAVE_WIN32)
signal(SIGHUP, reload_config);
#endif

init_console_msg(working_directory);

Dmsg0(200, "Start UA server\n");
start_UA_server(director->DIRaddrs);
start_UA_server(me->DIRaddrs);

start_watchdog(); /* start network watchdog thread */

init_jcr_subsystem(); /* start JCR watchdogs etc. */

init_job_server(director->MaxConcurrentJobs);
init_job_server(me->MaxConcurrentJobs);

dbg_jcr_add_hook(db_debug_print); /* used to debug B_DB connexion after fatal signal */

Expand Down Expand Up @@ -388,8 +383,8 @@ void terminate_dird(int sig)
db_sql_pool_destroy();
db_flush_backends();
unload_dir_plugins();
write_state_file(director->working_directory, "bareos-dir", get_first_port_host_order(director->DIRaddrs));
delete_pid_file(director->pid_directory, "bareos-dir", get_first_port_host_order(director->DIRaddrs));
write_state_file(me->working_directory, "bareos-dir", get_first_port_host_order(me->DIRaddrs));
delete_pid_file(me->pid_directory, "bareos-dir", get_first_port_host_order(me->DIRaddrs));
term_scheduler();
term_job_server();
if (runjob) {
Expand Down Expand Up @@ -576,9 +571,7 @@ void reload_config(int sig)
}

/* Reset globals */
set_working_directory(director->working_directory);
FDConnectTimeout = director->FDConnectTimeout;
SDConnectTimeout = director->SDConnectTimeout;
set_working_directory(me->working_directory);
Dmsg0(10, "Director's configuration file reread.\n");

/* Now release saved resources, if no jobs using the resources */
Expand Down Expand Up @@ -612,27 +605,27 @@ static bool check_resources()
LockRes();

job = (JOBRES *)GetNextRes(R_JOB, NULL);
director = (DIRRES *)GetNextRes(R_DIRECTOR, NULL);
if (!director) {
me = (DIRRES *)GetNextRes(R_DIRECTOR, NULL);
if (!me) {
Jmsg(NULL, M_FATAL, 0, _("No Director resource defined in %s\n"
"Without that I don't know who I am :-(\n"), configfile);
OK = false;
} else {
set_working_directory(director->working_directory);
if (!director->messages) { /* If message resource not specified */
director->messages = (MSGSRES *)GetNextRes(R_MSGS, NULL);
if (!director->messages) {
set_working_directory(me->working_directory);
if (!me->messages) { /* If message resource not specified */
me->messages = (MSGSRES *)GetNextRes(R_MSGS, NULL);
if (!me->messages) {
Jmsg(NULL, M_FATAL, 0, _("No Messages resource defined in %s\n"), configfile);
OK = false;
}
}

if (director->optimize_for_size && director->optimize_for_speed) {
if (me->optimize_for_size && me->optimize_for_speed) {
Jmsg(NULL, M_FATAL, 0, _("Cannot optimize for speed and size define only one in %s\n"), configfile);
OK = false;
}

if (GetNextRes(R_DIRECTOR, (RES *)director) != NULL) {
if (GetNextRes(R_DIRECTOR, (RES *)me) != NULL) {
Jmsg(NULL, M_FATAL, 0, _("Only one Director resource permitted in %s\n"),
configfile);
OK = false;
Expand All @@ -641,56 +634,54 @@ static bool check_resources()
/*
* tls_require implies tls_enable
*/
if (director->tls_require) {
if (me->tls_require) {
if (have_tls) {
director->tls_enable = true;
me->tls_enable = true;
} else {
Jmsg(NULL, M_FATAL, 0, _("TLS required but not configured in BAREOS.\n"));
OK = false;
}
}

need_tls = director->tls_enable || director->tls_authenticate;
need_tls = me->tls_enable || me->tls_authenticate;

if (!director->tls_certfile && need_tls) {
Jmsg(NULL, M_FATAL, 0, _("\"TLS Certificate\" file not defined for Director \"%s\" in %s.\n"),
director->name(), configfile);
if (!me->tls_certfile && need_tls) {
Jmsg(NULL, M_FATAL, 0, _("\"TLS Certificate\" file not defined for Director \"%s\" in %s.\n"), me->name(), configfile);
OK = false;
}

if (!director->tls_keyfile && need_tls) {
Jmsg(NULL, M_FATAL, 0, _("\"TLS Key\" file not defined for Director \"%s\" in %s.\n"),
director->name(), configfile);
if (!me->tls_keyfile && need_tls) {
Jmsg(NULL, M_FATAL, 0, _("\"TLS Key\" file not defined for Director \"%s\" in %s.\n"), me->name(), configfile);
OK = false;
}

if ((!director->tls_ca_certfile && !director->tls_ca_certdir) &&
need_tls && director->tls_verify_peer) {
if ((!me->tls_ca_certfile && !me->tls_ca_certdir) &&
need_tls && me->tls_verify_peer) {
Jmsg(NULL, M_FATAL, 0, _("Neither \"TLS CA Certificate\" or \"TLS CA"
" Certificate Dir\" are defined for Director \"%s\" in %s."
" At least one CA certificate store is required"
" when using \"TLS Verify Peer\".\n"),
director->name(), configfile);
me->name(), configfile);
OK = false;
}

/*
* If everything is well, attempt to initialize our per-resource TLS context
*/
if (OK && (need_tls || director->tls_require)) {
if (OK && (need_tls || me->tls_require)) {
/*
* Initialize TLS context:
* Args: CA certfile, CA certdir, Certfile, Keyfile,
* Keyfile PEM Callback, Keyfile CB Userdata, DHfile, Verify Peer
*/
director->tls_ctx = new_tls_context(director->tls_ca_certfile,
director->tls_ca_certdir, director->tls_crlfile, director->tls_certfile,
director->tls_keyfile, NULL, NULL, director->tls_dhfile,
director->tls_verify_peer);
me->tls_ctx = new_tls_context(me->tls_ca_certfile,
me->tls_ca_certdir, me->tls_crlfile, me->tls_certfile,
me->tls_keyfile, NULL, NULL, me->tls_dhfile,
me->tls_verify_peer);

if (!director->tls_ctx) {
if (!me->tls_ctx) {
Jmsg(NULL, M_FATAL, 0, _("Failed to initialize TLS context for Director \"%s\" in %s.\n"),
director->name(), configfile);
me->name(), configfile);
OK = false;
}
}
Expand Down Expand Up @@ -1022,7 +1013,7 @@ static bool check_resources()
UnlockRes();
if (OK) {
close_msg(NULL); /* close temp message handler */
init_msg(NULL, director->messages); /* open daemon message handler */
init_msg(NULL, me->messages); /* open daemon message handler */
}
return OK;
}
Expand Down Expand Up @@ -1098,7 +1089,7 @@ static bool check_catalog(cat_op mode)
}

/* Display a message if the db max_connections is too low */
if (!db_check_max_connections(NULL, db, director->MaxConcurrentJobs)) {
if (!db_check_max_connections(NULL, db, me->MaxConcurrentJobs)) {
Pmsg1(000, "Warning, settings problem for Catalog=%s\n", catalog->name());
Pmsg1(000, "%s", db_strerror(db));
}
Expand Down Expand Up @@ -1229,7 +1220,7 @@ static void cleanup_old_files()
struct dirent *entry, *result;
int rc, name_max;
int my_name_len = strlen(my_name);
int len = strlen(director->working_directory);
int len = strlen(me->working_directory);
POOLMEM *cleanup = get_pool_memory(PM_MESSAGE);
POOLMEM *basename = get_pool_memory(PM_MESSAGE);
regex_t preg1;
Expand All @@ -1242,8 +1233,8 @@ static void cleanup_old_files()
const char *pat1 = "^[^ ]+\\.(restore\\.[^ ]+\\.bsr|mail)$";

/* Setup working directory prefix */
pm_strcpy(basename, director->working_directory);
if (len > 0 && !IsPathSeparator(director->working_directory[len-1])) {
pm_strcpy(basename, me->working_directory);
if (len > 0 && !IsPathSeparator(me->working_directory[len-1])) {
pm_strcat(basename, "/");
}

Expand All @@ -1261,10 +1252,10 @@ static void cleanup_old_files()
name_max = 1024;
}

if (!(dp = opendir(director->working_directory))) {
if (!(dp = opendir(me->working_directory))) {
berrno be;
Pmsg2(000, "Failed to open working dir %s for cleanup: ERR=%s\n",
director->working_directory, be.bstrerror());
me->working_directory, be.bstrerror());
goto get_out1;
return;
}
Expand Down
4 changes: 1 addition & 3 deletions src/dird/dird.h
Expand Up @@ -43,9 +43,7 @@
#include "jobq.h"

/* Globals that dird.c exports */
extern DIRRES *director; /* Director resource */
extern int FDConnectTimeout;
extern int SDConnectTimeout;
extern DIRRES *me; /* "Global" daemon resource */

/* Used in ua_prune.c and ua_purge.c */

Expand Down
7 changes: 3 additions & 4 deletions src/dird/fd_cmds.c
Expand Up @@ -74,7 +74,6 @@ static bool send_list_item(JCR *jcr, const char *code, char *item, BSOCK *fd);

/* External functions */
extern DIRRES *director;
extern int FDConnectTimeout;

#define INC_LIST 0
#define EXC_LIST 1
Expand All @@ -94,15 +93,15 @@ int connect_to_file_daemon(JCR *jcr, int retry_interval, int max_retry_time, int
if (jcr->res.client->heartbeat_interval) {
heart_beat = jcr->res.client->heartbeat_interval;
} else {
heart_beat = director->heartbeat_interval;
heart_beat = me->heartbeat_interval;
}

if (!jcr->file_bsock) {
char name[MAX_NAME_LENGTH + 100];
bstrncpy(name, _("Client: "), sizeof(name));
bstrncat(name, jcr->res.client->name(), sizeof(name));

fd->set_source_address(director->DIRsrc_addr);
fd->set_source_address(me->DIRsrc_addr);
if (!fd->connect(jcr,retry_interval,max_retry_time, heart_beat, name,
jcr->res.client->address, NULL,
jcr->res.client->FDport, verbose)) {
Expand Down Expand Up @@ -813,7 +812,7 @@ bool cancel_file_daemon_job(UAContext *ua, JCR *jcr)
BSOCK *fd;

ua->jcr->res.client = jcr->res.client;
if (!connect_to_file_daemon(ua->jcr, 10, FDConnectTimeout, 1)) {
if (!connect_to_file_daemon(ua->jcr, 10, me->FDConnectTimeout, 1)) {
ua->error_msg(_("Failed to connect to File daemon.\n"));
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/dird/job.c
Expand Up @@ -1347,7 +1347,7 @@ void dird_free_jcr(JCR *jcr)
jcr->job_end_push.destroy();

if (jcr->JobId != 0) {
write_state_file(director->working_directory, "bareos-dir", get_first_port_host_order(director->DIRaddrs));
write_state_file(me->working_directory, "bareos-dir", get_first_port_host_order(me->DIRaddrs));
}

free_plugins(jcr); /* release instantiated plugins */
Expand Down

0 comments on commit 69ba056

Please sign in to comment.