From: Eric Bollengier Date: Thu, 10 Nov 2022 09:54:32 +0000 (+0100) Subject: Fix bconsole command issue after a first error X-Git-Tag: Release-13.0.2~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=03c3b62716c3ee9e5002905fbcba6bddb5f3eac4;p=thirdparty%2Fbacula.git Fix bconsole command issue after a first error --- diff --git a/bacula/src/dird/job.c b/bacula/src/dird/job.c index 7706c3d8d..82d440096 100644 --- a/bacula/src/dird/job.c +++ b/bacula/src/dird/job.c @@ -547,6 +547,8 @@ void sd_msg_thread_send_signal(JCR *jcr, int sig) static bool cancel_file_daemon_job(UAContext *ua, const char *cmd, JCR *jcr) { CLIENT *old_client; + bool ret = false; + BSOCK *fd; if (!jcr->client) { Dmsg0(100, "No client to cancel\n"); @@ -556,20 +558,22 @@ static bool cancel_file_daemon_job(UAContext *ua, const char *cmd, JCR *jcr) 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")); - ua->jcr->client = old_client; - return false; + goto bail_out; } Dmsg3(10, "Connected to file daemon %s for cancel ua.jcr=%p jcr=%p\n", ua->jcr->client->name(), ua->jcr, jcr); - BSOCK *fd = ua->jcr->file_bsock; + fd = ua->jcr->file_bsock; fd->fsend("%s Job=%s\n", cmd, jcr->Job); while (fd->recv() >= 0) { ua->send_msg("%s", fd->msg); } fd->signal(BNET_TERMINATE); + ret = true; + +bail_out: free_bsock(ua->jcr->file_bsock); ua->jcr->client = old_client; - return true; + return ret; } static bool cancel_sd_job(UAContext *ua, const char *cmd, JCR *jcr) diff --git a/bacula/src/dird/snapshot.c b/bacula/src/dird/snapshot.c index 39e6f5821..c9599f6cf 100644 --- a/bacula/src/dird/snapshot.c +++ b/bacula/src/dird/snapshot.c @@ -152,7 +152,7 @@ int delete_snapshot(UAContext *ua) POOL_MEM buf; POOLMEM *out; SNAPSHOT_DBR snapdbr; - CLIENT *client; + CLIENT *client, *old_client; BSOCK *fd; if (!open_new_client_db(ua)) { @@ -175,6 +175,7 @@ int delete_snapshot(UAContext *ua) } /* Connect to File daemon */ + old_client = ua->jcr->client; ua->jcr->client = client; /* Try to connect for 15 seconds */ @@ -182,7 +183,8 @@ int delete_snapshot(UAContext *ua) client->name(), get_client_address(ua->jcr, client, buf.addr()), client->FDport); if (!connect_to_file_daemon(ua->jcr, 1, 15, 0)) { ua->error_msg(_("Failed to connect to Client.\n")); - ua->jcr->client = NULL; + free_bsock(ua->jcr->file_bsock); + ua->jcr->client = old_client; return 0; } @@ -199,8 +201,7 @@ int delete_snapshot(UAContext *ua) ua->jcr->file_bsock->signal(BNET_TERMINATE); free_bsock(ua->jcr->file_bsock); - ua->jcr->client = NULL; - + ua->jcr->client = old_client; db_delete_snapshot_record(ua->jcr, ua->db, &snapdbr); ua->send_msg(_("Snapshot \"%s\" deleted from catalog\n"), snapdbr.Name); return 1; @@ -214,8 +215,9 @@ int list_snapshot(UAContext *ua, alist *snap_list) POOL_MEM tmp; SNAPSHOT_DBR snap; POOLMEM *buf; - CLIENT *client; + CLIENT *client, *old_client; BSOCK *fd; + int ret = 0; client = select_client_resource(ua, JT_BACKUP_RESTORE); if (!client) { @@ -223,6 +225,7 @@ int list_snapshot(UAContext *ua, alist *snap_list) } /* Connect to File daemon */ + old_client = ua->jcr->client; ua->jcr->client = client; /* Try to connect for 15 seconds */ @@ -231,7 +234,7 @@ int list_snapshot(UAContext *ua, alist *snap_list) if (!connect_to_file_daemon(ua->jcr, 1, 15, 0)) { ua->error_msg(_("Failed to connect to Client.\n")); - return 0; + goto bail_out; } fd = ua->jcr->file_bsock; @@ -258,10 +261,13 @@ int list_snapshot(UAContext *ua, alist *snap_list) parse_args(ua->cmd, &ua->args, &ua->argc, ua->argk, ua->argv, MAX_CMD_ARGS); ua->jcr->file_bsock->signal(BNET_TERMINATE); - free_bsock(ua->jcr->file_bsock); - ua->jcr->client = NULL; free_pool_memory(buf); - return 1; + ret = 1; + +bail_out: + free_bsock(ua->jcr->file_bsock); + ua->jcr->client = old_client; + return ret; } static void storeit(void *ctx, const char *msg) @@ -283,6 +289,7 @@ int prune_snapshot(UAContext *ua) SNAPSHOT_DBR snapdbr; alist *lst; intptr_t id; + CLIENT *old_client = ua->jcr->client; snapshot_scan_cmdline(ua, 0, &snapdbr); snapdbr.expired = true; @@ -350,11 +357,10 @@ int prune_snapshot(UAContext *ua) if (ua->jcr->file_bsock) { ua->jcr->file_bsock->signal(BNET_TERMINATE); free_bsock(ua->jcr->file_bsock); - ua->jcr->client = NULL; } - free_pool_memory(buf); delete lst; + ua->jcr->client = old_client; return 1; } diff --git a/bacula/src/dird/ua_cmds.c b/bacula/src/dird/ua_cmds.c index 9f7ab116d..7c105ed7f 100644 --- a/bacula/src/dird/ua_cmds.c +++ b/bacula/src/dird/ua_cmds.c @@ -772,10 +772,10 @@ static int setbwlimit_client(UAContext *ua, CLIENT *client, char *Job, int64_t l } ua->jcr->file_bsock->signal(BNET_TERMINATE); - free_bsock(ua->jcr->file_bsock); ua->jcr->max_bandwidth = 0; bail_out: + free_bsock(ua->jcr->file_bsock); ua->jcr->client = old_client; return 1; } @@ -1096,8 +1096,7 @@ static void do_client_setdebug(UAContext *ua, CLIENT *client, 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; + goto bail_out; } Dmsg0(120, "Connected to file daemon\n"); @@ -1113,6 +1112,8 @@ static void do_client_setdebug(UAContext *ua, CLIENT *client, ua->send_msg("%s", fd->msg); } fd->signal(BNET_TERMINATE); + +bail_out: free_bsock(ua->jcr->file_bsock); ua->jcr->client = old_client; return; @@ -1543,7 +1544,7 @@ static int estimate_cmd(UAContext *ua, const char *cmd) jcr->client->name(), get_client_address(jcr, jcr->client, buf.addr()), jcr->client->FDport); if (!connect_to_file_daemon(jcr, 1, 15, 0)) { ua->error_msg(_("Failed to connect to Client.\n")); - return 1; + goto bail_out; } /* The level string change if accurate mode is enabled */ @@ -2449,7 +2450,7 @@ static void do_storage_cmd(UAContext *ua, const char *command) if (!connect_to_storage_daemon(jcr, 10, SDConnectTimeout, 1)) { ua->error_msg(_("Failed to connect to Storage daemon.\n")); - return; + goto bail_out; } /* Keep track of this important event */ @@ -2463,6 +2464,8 @@ static void do_storage_cmd(UAContext *ua, const char *command) ua->send_msg("%s", sd->msg); } sd->signal(BNET_TERMINATE); + +bail_out: free_bsock(ua->jcr->store_bsock); } diff --git a/bacula/src/dird/ua_dotcmds.c b/bacula/src/dird/ua_dotcmds.c index 8e1744eb9..13d3728f0 100644 --- a/bacula/src/dird/ua_dotcmds.c +++ b/bacula/src/dird/ua_dotcmds.c @@ -1731,7 +1731,7 @@ static void do_client_cmd(UAContext *ua, CLIENT *client, const char *cmd) client->name(), get_client_address(ua->jcr, client, buf.addr()), client->FDport); if (!connect_to_file_daemon(ua->jcr, 1, 15, 0)) { ua->error_msg(_("Failed to connect to Client.\n")); - return; + goto bail_out; } Dmsg0(120, "Connected to file daemon\n"); fd = ua->jcr->file_bsock; @@ -1740,6 +1740,8 @@ static void do_client_cmd(UAContext *ua, CLIENT *client, const char *cmd) ua->send_msg("%s", fd->msg); } fd->signal(BNET_TERMINATE); + +bail_out: free_bsock(ua->jcr->file_bsock); return; } @@ -2293,6 +2295,8 @@ static bool dot_querycmd(UAContext *ua, const char *cmd) POOL_MEM esc1, esc2, esc3; JCR *jcr = ua->jcr; int i; + bool ret = false; + CLIENT *old_client = jcr->client; Dmsg0(200, "dot_querycmd()\n"); @@ -2343,7 +2347,7 @@ static bool dot_querycmd(UAContext *ua, const char *cmd) if (!connect_to_file_daemon(jcr, 1, 15, 0)) { ua->error_msg(_("error=Failed to connect to Client.\n")); - return false; + goto bail_out; } if (!jcr->file_bsock->fsend("query parameter=%s plugin=%s value=%s\n", @@ -2358,12 +2362,15 @@ static bool dot_querycmd(UAContext *ua, const char *cmd) ua->send_msg("%s", jcr->file_bsock->msg); } + ret = true; + bail_out: if (jcr->file_bsock) { jcr->file_bsock->signal(BNET_TERMINATE); free_bsock(ua->jcr->file_bsock); } - return true; + jcr->client = old_client; + return ret; } static bool tagscmd(UAContext *ua, const char *cmd)