From 3367d739fa7999e8290eeaeb1243bcca3025a583 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Wed, 26 Sep 2007 09:48:11 +0000 Subject: [PATCH] kes Make SD code that contructs attribute insert check string lengths more carefully. kes If Dir gets an error during inserting attributes, cancel SD. This reduces unnecessary error messages. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@5648 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/dird/catreq.c | 30 +++++++++++++++++------------- bacula/src/dird/getmsg.c | 2 +- bacula/src/lib/message.c | 2 +- bacula/src/stored/askdir.c | 11 ++++++----- bacula/src/version.h | 4 ++-- bacula/technotes-2.3 | 5 +++++ 6 files changed, 32 insertions(+), 22 deletions(-) diff --git a/bacula/src/dird/catreq.c b/bacula/src/dird/catreq.c index 41f705bc38..8609039e17 100644 --- a/bacula/src/dird/catreq.c +++ b/bacula/src/dird/catreq.c @@ -126,7 +126,7 @@ void catalog_request(JCR *jcr, BSOCK *bs) if (!jcr->db) { omsg = get_memory(bs->msglen+1); pm_strcpy(omsg, bs->msg); - bnet_fsend(bs, _("1990 Invalid Catalog Request: %s"), omsg); + bs->fsend(_("1990 Invalid Catalog Request: %s"), omsg); Jmsg1(jcr, M_FATAL, 0, _("Invalid Catalog request; DB not open: %s"), omsg); free_memory(omsg); return; @@ -151,7 +151,7 @@ void catalog_request(JCR *jcr, BSOCK *bs) if (ok) { send_volume_info_to_storage_daemon(jcr, bs, &mr); } else { - bnet_fsend(bs, _("1901 No Media.\n")); + bs->fsend(_("1901 No Media.\n")); Dmsg0(500, "1901 No Media.\n"); } @@ -200,12 +200,12 @@ void catalog_request(JCR *jcr, BSOCK *bs) send_volume_info_to_storage_daemon(jcr, bs, &mr); } else { /* Not suitable volume */ - bnet_fsend(bs, _("1998 Volume \"%s\" status is %s, %s.\n"), mr.VolumeName, + bs->fsend(_("1998 Volume \"%s\" status is %s, %s.\n"), mr.VolumeName, mr.VolStatus, reason); } } else { - bnet_fsend(bs, _("1997 Volume \"%s\" not in catalog.\n"), mr.VolumeName); + bs->fsend(_("1997 Volume \"%s\" not in catalog.\n"), mr.VolumeName); Dmsg1(100, "1997 Volume \"%s\" not in catalog.\n", mr.VolumeName); } @@ -229,7 +229,7 @@ void catalog_request(JCR *jcr, BSOCK *bs) if (!db_get_media_record(jcr, jcr->db, &mr)) { Jmsg(jcr, M_ERROR, 0, _("Unable to get Media record for Volume %s: ERR=%s\n"), mr.VolumeName, db_strerror(jcr->db)); - bnet_fsend(bs, _("1991 Catalog Request for vol=%s failed: %s"), + bs->fsend(_("1991 Catalog Request for vol=%s failed: %s"), mr.VolumeName, db_strerror(jcr->db)); db_unlock(jcr->db); return; @@ -259,7 +259,7 @@ void catalog_request(JCR *jcr, BSOCK *bs) Jmsg(jcr, M_FATAL, 0, _("Volume Files at %u being set to %u" " for Volume \"%s\". This is incorrect.\n"), mr.VolFiles, sdmr.VolFiles, mr.VolumeName); - bnet_fsend(bs, _("1992 Update Media error. VolFiles=%u, CatFiles=%u\n"), + bs->fsend(_("1992 Update Media error. VolFiles=%u, CatFiles=%u\n"), sdmr.VolFiles, mr.VolFiles); db_unlock(jcr->db); return; @@ -293,7 +293,7 @@ void catalog_request(JCR *jcr, BSOCK *bs) if (!db_update_media_record(jcr, jcr->db, &mr)) { Jmsg(jcr, M_FATAL, 0, _("Catalog error updating Media record. %s"), db_strerror(jcr->db)); - bnet_fsend(bs, _("1993 Update Media error\n")); + bs->fsend(_("1993 Update Media error\n")); Dmsg0(400, "send error\n"); } else { (void)has_volume_expired(jcr, &mr); @@ -319,16 +319,16 @@ void catalog_request(JCR *jcr, BSOCK *bs) if (!db_create_jobmedia_record(jcr, jcr->db, &jm)) { Jmsg(jcr, M_FATAL, 0, _("Catalog error creating JobMedia record. %s"), db_strerror(jcr->db)); - bnet_fsend(bs, _("1991 Update JobMedia error\n")); + bs->fsend(_("1991 Update JobMedia error\n")); } else { Dmsg0(400, "JobMedia record created\n"); - bnet_fsend(bs, OK_create); + bs->fsend(OK_create); } } else { omsg = get_memory(bs->msglen+1); pm_strcpy(omsg, bs->msg); - bnet_fsend(bs, _("1990 Invalid Catalog Request: %s"), omsg); + bs->fsend(_("1990 Invalid Catalog Request: %s"), omsg); Jmsg1(jcr, M_FATAL, 0, _("Invalid Catalog request: %s"), omsg); free_memory(omsg); } @@ -359,15 +359,15 @@ void catalog_update(JCR *jcr, BSOCK *bs) Dsm_check(1); if (!jcr->pool->catalog_files) { - return; /* user disabled cataloging */ + goto bail_out; /* user disabled cataloging */ } if (!jcr->db) { omsg = get_memory(bs->msglen+1); pm_strcpy(omsg, bs->msg); - bnet_fsend(bs, _("1991 Invalid Catalog Update: %s"), omsg); + bs->fsend(_("1991 Invalid Catalog Update: %s"), omsg); Jmsg1(jcr, M_FATAL, 0, _("Invalid Catalog Update; DB not open: %s"), omsg); free_memory(omsg); - return; + goto bail_out; } /* Start transaction allocates jcr->attr and jcr->ar if needed */ @@ -486,4 +486,8 @@ void catalog_update(JCR *jcr, BSOCK *bs) } } } +bail_out: + if (job_canceled(jcr)) { + cancel_storage_daemon_job(jcr); + } } diff --git a/bacula/src/dird/getmsg.c b/bacula/src/dird/getmsg.c index ae4a190bf6..16e88291c4 100644 --- a/bacula/src/dird/getmsg.c +++ b/bacula/src/dird/getmsg.c @@ -213,7 +213,7 @@ int bget_dirmsg(BSOCK *bs) free_jcr(jcr); continue; } - if (bs->msg[0] == 'U') { /* Catalog update */ + if (bs->msg[0] == 'U') { /* SD sending attributes */ Dmsg2(900, "Catalog upd jcr 0x%x: %s", jcr, bs->msg); catalog_update(jcr, bs); Dmsg1(900, "Calling freejcr 0x%x\n", jcr); diff --git a/bacula/src/lib/message.c b/bacula/src/lib/message.c index 620aa32b38..70073f6355 100644 --- a/bacula/src/lib/message.c +++ b/bacula/src/lib/message.c @@ -1084,7 +1084,7 @@ Jmsg(JCR *jcr, int type, time_t mtime, const char *fmt,...) dir->msglen = bvsnprintf(dir->msg, sizeof_pool_memory(dir->msg), fmt, arg_ptr); va_end(arg_ptr); - bnet_send(jcr->dir_bsock); + jcr->dir_bsock->send(); return; } diff --git a/bacula/src/stored/askdir.c b/bacula/src/stored/askdir.c index 753f1a34ae..73252c0869 100644 --- a/bacula/src/stored/askdir.c +++ b/bacula/src/stored/askdir.c @@ -406,7 +406,7 @@ bool dir_create_jobmedia_record(DCR *dcr) if (bnet_recv(dir) <= 0) { Dmsg0(190, "create_jobmedia error bnet_recv\n"); Jmsg(jcr, M_FATAL, 0, _("Error creating JobMedia record: ERR=%s\n"), - bnet_strerror(dir)); + dir->bstrerror()); return false; } Dmsg2(100, "JobId, dir->msg); @@ -432,9 +432,10 @@ bool dir_update_file_attributes(DCR *dcr, DEV_RECORD *rec) return true; #endif - dir->msglen = sprintf(dir->msg, FileAttributes, jcr->Job); - dir->msg = check_pool_memory_size(dir->msg, dir->msglen + - sizeof(DEV_RECORD) + rec->data_len); + dir->msg = check_pool_memory_size(dir->msg, sizeof(FileAttributes) + + MAX_NAME_LENGTH + sizeof(DEV_RECORD) + rec->data_len + 1); + dir->msglen = bsnprintf(dir->msg, sizeof(FileAttributes) + + MAX_NAME_LENGTH + 1, FileAttributes, jcr->Job); ser_begin(dir->msg + dir->msglen, 0); ser_uint32(rec->VolSessionId); ser_uint32(rec->VolSessionTime); @@ -444,7 +445,7 @@ bool dir_update_file_attributes(DCR *dcr, DEV_RECORD *rec) ser_bytes(rec->data, rec->data_len); dir->msglen = ser_length(dir->msg); Dmsg2(1800, ">dird jid=%u: %s\n", (uint32_t)jcr->JobId, dir->msg); /* Attributes */ - return bnet_send(dir); + return dir->send(); } diff --git a/bacula/src/version.h b/bacula/src/version.h index db28a38de3..6d5be57357 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -4,8 +4,8 @@ #undef VERSION #define VERSION "2.3.5" -#define BDATE "24 September 2007" -#define LSMDATE "24Sep07" +#define BDATE "26 September 2007" +#define LSMDATE "26Sep07" #define PROG_COPYRIGHT "Copyright (C) %d-2007 Free Software Foundation Europe e.V.\n" #define BYEAR "2007" /* year for copyright messages in progs */ diff --git a/bacula/technotes-2.3 b/bacula/technotes-2.3 index f540134f1a..a84090c41e 100644 --- a/bacula/technotes-2.3 +++ b/bacula/technotes-2.3 @@ -1,6 +1,11 @@ Technical notes on version 2.3 General: +26Sep07 +kes Make SD code that contructs attribute insert check string lengths + more carefully. +kes If Dir gets an error during inserting attributes, cancel SD. + This reduces unnecessary error messages. 24Sep07 kes Correct search boolean for getting Volume info ebl Cleanup batch code. -- 2.39.5