From 1445dc267fc1717b121ceb0fa4cd8b52cf8852ee Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Thu, 20 Nov 2014 14:10:01 +0100 Subject: [PATCH] Possible fix for NULL client bug #2105 --- bacula/src/dird/job.c | 14 +++++++++----- bacula/src/dird/ua_cmds.c | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/bacula/src/dird/job.c b/bacula/src/dird/job.c index 08c9fee330..62181bd198 100644 --- a/bacula/src/dird/job.c +++ b/bacula/src/dird/job.c @@ -367,16 +367,20 @@ void sd_msg_thread_send_signal(JCR *jcr, int sig) jcr->unlock(); } -static int cancel_file_daemon_job(UAContext *ua, const char *cmd, JCR *jcr) +static bool cancel_file_daemon_job(UAContext *ua, const char *cmd, JCR *jcr) { + CLIENT *old_client; + if (!jcr->client) { Dmsg0(100, "No client to cancel\n"); - return 0; + return false; } + old_client = ua->jcr->client; ua->jcr->client = jcr->client; if (!connect_to_file_daemon(ua->jcr, 10, FDConnectTimeout, 1)) { ua->error_msg(_("Failed to connect to File daemon.\n")); - return 0; + ua->jcr->client = old_client; + return false; } Dmsg0(100, "Connected to file daemon\n"); BSOCK *fd = ua->jcr->file_bsock; @@ -386,8 +390,8 @@ static int cancel_file_daemon_job(UAContext *ua, const char *cmd, JCR *jcr) } fd->signal(BNET_TERMINATE); free_bsock(ua->jcr->file_bsock); - ua->jcr->client = NULL; - return 1; + ua->jcr->client = old_client; + return true; } static bool cancel_sd_job(UAContext *ua, const char *cmd, JCR *jcr) diff --git a/bacula/src/dird/ua_cmds.c b/bacula/src/dird/ua_cmds.c index b01b8cc19e..c1c626d06a 100644 --- a/bacula/src/dird/ua_cmds.c +++ b/bacula/src/dird/ua_cmds.c @@ -650,11 +650,14 @@ extern char *configfile; static int setbwlimit_client(UAContext *ua, CLIENT *client, char *Job, int64_t limit) { + CLIENT *old_client; + if (!client) { return 1; } /* Connect to File daemon */ + old_client = ua->jcr->client; ua->jcr->client = client; ua->jcr->max_bandwidth = limit; @@ -663,7 +666,7 @@ static int setbwlimit_client(UAContext *ua, CLIENT *client, char *Job, int64_t l client->name(), client->address, client->FDport); if (!connect_to_file_daemon(ua->jcr, 1, 15, 0)) { ua->error_msg(_("Failed to connect to Client.\n")); - return 1; + goto bail_out; } Dmsg0(120, "Connected to file daemon\n"); @@ -671,14 +674,17 @@ static int setbwlimit_client(UAContext *ua, CLIENT *client, char *Job, int64_t l ua->error_msg(_("Failed to set bandwidth limit to Client.\n")); } else { + /* Note, we add 2000 OK that was sent by FD to us to message */ ua->info_msg(_("2000 OK Limiting bandwidth to %lldkb/s %s\n"), limit/1024, *Job?Job:_("on running and future jobs")); } ua->jcr->file_bsock->signal(BNET_TERMINATE); free_bsock(ua->jcr->file_bsock); - ua->jcr->client = NULL; ua->jcr->max_bandwidth = 0; + +bail_out: + ua->jcr->client = old_client; return 1; } @@ -866,16 +872,19 @@ static void do_storage_setdebug(UAContext *ua, STORE *store, static void do_client_setdebug(UAContext *ua, CLIENT *client, int64_t level, int trace, int hangup, char *options, char *tags) { + CLIENT *old_client; BSOCK *fd; /* Connect to File daemon */ + old_client = ua->jcr->client; ua->jcr->client = client; /* Try to connect for 15 seconds */ ua->send_msg(_("Connecting to Client %s at %s:%d\n"), client->name(), client->address, client->FDport); if (!connect_to_file_daemon(ua->jcr, 1, 15, 0)) { ua->error_msg(_("Failed to connect to Client.\n")); + ua->jcr->client = old_client; return; } Dmsg0(120, "Connected to file daemon\n"); @@ -893,6 +902,7 @@ static void do_client_setdebug(UAContext *ua, CLIENT *client, } fd->signal(BNET_TERMINATE); free_bsock(ua->jcr->file_bsock); + ua->jcr->client = old_client; return; } -- 2.39.5