]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Fix bconsole command issue after a first error
authorEric Bollengier <eric@baculasystems.com>
Thu, 10 Nov 2022 09:54:32 +0000 (10:54 +0100)
committerEric Bollengier <eric@baculasystems.com>
Sat, 18 Feb 2023 09:21:25 +0000 (10:21 +0100)
bacula/src/dird/job.c
bacula/src/dird/snapshot.c
bacula/src/dird/ua_cmds.c
bacula/src/dird/ua_dotcmds.c

index 7706c3d8d9b7fdd1427ac01e6ca6464567045bdc..82d44009633ce5cfe1027c9b436ad943352195be 100644 (file)
@@ -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)
index 39e6f58216d7e1c88cfcb38cb7837b7cd34e3650..c9599f6cf1b5e4881f07e6d610ee2eb7291a70f3 100644 (file)
@@ -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;
 }
 
index 9f7ab116d29a326bfef964b7be8f95ddf34a3b59..7c105ed7f2447baf2e637e4b10d7800c8321c91f 100644 (file)
@@ -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);
 }
 
index 8e1744eb94020a2d1dd6e6664bdc1626d0be5702..13d3728f0b0066b86d1f1af2755a2f89f999f522 100644 (file)
@@ -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)