From: Eric Bollengier Date: Thu, 28 Mar 2024 09:50:17 +0000 (+0100) Subject: Fix Client/Uname field not always updated after a status client X-Git-Tag: Release-15.0.3~62 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a44f18f634aaaf03f9b8a6909ec6f4d14b92caf1;p=thirdparty%2Fbacula.git Fix Client/Uname field not always updated after a status client --- diff --git a/bacula/src/dird/fd_cmds.c b/bacula/src/dird/fd_cmds.c index 6b2df0671..3958e4a7b 100644 --- a/bacula/src/dird/fd_cmds.c +++ b/bacula/src/dird/fd_cmds.c @@ -200,27 +200,53 @@ int connect_to_file_daemon(JCR *jcr, int retry_interval, int max_retry_time, jcr->client->hdr.name, fd->msg); return 0; - } else if (jcr->db) { - CLIENT_DBR cr; - memset(&cr, 0, sizeof(cr)); - bstrncpy(cr.Name, jcr->client->hdr.name, sizeof(cr.Name)); - cr.AutoPrune = jcr->client->AutoPrune; - cr.FileRetention = jcr->client->FileRetention; - cr.JobRetention = jcr->client->JobRetention; - - /* information about plugins can be found after the Uname */ - char *pos = strchr(fd->msg+strlen(OKjob)+1, ';'); - if (pos) { - *pos = 0; - bstrncpy(cr.Plugins, pos+1, sizeof(cr.Plugins)); - } - bstrncpy(cr.Uname, fd->msg+strlen(OKjob)+1, sizeof(cr.Uname)); - jcr->client_version = scan_version(cr.Uname); - - if (!db_update_client_record(jcr, jcr->db, &cr)) { - Jmsg(jcr, M_WARNING, 0, _("[DE0028] Error updating Client record. ERR=%s\n"), - db_strerror(jcr->db)); - } + } else { + bool close_db = false; + if (!jcr->db) { + close_db = true; + CAT *cat = jcr->client->catalog; + jcr->db = db_init_database(jcr, cat->db_driver, cat->db_name, + cat->db_user, + cat->db_password, cat->db_address, + cat->db_port, cat->db_socket, + cat->db_ssl_mode, cat->db_ssl_key, + cat->db_ssl_cert, cat->db_ssl_ca, + cat->db_ssl_capath, cat->db_ssl_cipher, + cat->mult_db_connections, + cat->disable_batch_insert); + if (!jcr->db || !db_open_database(jcr, jcr->db)) { + if (jcr->db) { + db_close_database(jcr, jcr->db); + jcr->db = NULL; + } + } + } + if (jcr->db) { + CLIENT_DBR cr; + memset(&cr, 0, sizeof(cr)); + bstrncpy(cr.Name, jcr->client->hdr.name, sizeof(cr.Name)); + cr.AutoPrune = jcr->client->AutoPrune; + cr.FileRetention = jcr->client->FileRetention; + cr.JobRetention = jcr->client->JobRetention; + + /* information about plugins can be found after the Uname */ + char *pos = strchr(fd->msg+strlen(OKjob)+1, ';'); + if (pos) { + *pos = 0; + bstrncpy(cr.Plugins, pos+1, sizeof(cr.Plugins)); + } + bstrncpy(cr.Uname, fd->msg+strlen(OKjob)+1, sizeof(cr.Uname)); + jcr->client_version = scan_version(cr.Uname); + + if (!db_update_client_record(jcr, jcr->db, &cr)) { + Jmsg(jcr, M_WARNING, 0, _("[DE0028] Error updating Client record. ERR=%s\n"), + db_strerror(jcr->db)); + } + if (close_db) { + db_close_database(jcr, jcr->db); + jcr->db = NULL; + } + } } } else { Mmsg(jcr->errmsg, _("[DE0031] FD gave bad response to JobId command: %s\n"),