From 8268ec22f24717fbde200a0ee144767188d7707c Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sun, 7 Sep 2003 17:04:45 +0000 Subject: [PATCH] Fix console prompt + apply Nic's file descriptor leak fix git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@690 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/kernstodo | 3 ++- bacula/src/console/console.c | 4 ++- bacula/src/stored/append.c | 52 ++++++++++++++++++++++++++++++------ bacula/src/version.h | 4 +-- 4 files changed, 51 insertions(+), 12 deletions(-) diff --git a/bacula/kernstodo b/bacula/kernstodo index 19907ae21a..296cdf0367 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -28,6 +28,8 @@ Testing to do: (painful) - Figure out how to use ssh or stunnel to protect Bacula communications. For 1.32: +- Add restore by filename test. +- Add test of exclusion, test multiple Include {} statements. - Enhance "update slots" to include a "scan" feature scan 1; scan 1-5; scan 1,2,4 ... to update the catalog - Allow a slot or range of slots on the label barcodes command. @@ -888,4 +890,3 @@ Done: (see kernsdone for more) - Specify list of files to restore - Implement ClientRunBeforeJob and ClientRunAfterJob. - Make | and < work on FD side. - diff --git a/bacula/src/console/console.c b/bacula/src/console/console.c index 8e9849bc93..deba1f9c25 100644 --- a/bacula/src/console/console.c +++ b/bacula/src/console/console.c @@ -191,7 +191,9 @@ static void read_and_process_input(FILE *input, BSOCK *UA_sock) if (stat < 0) { break; /* error */ } else if (stat == 0) { /* timeout */ - bnet_fsend(UA_sock, ".messages"); + if (at_prompt) { + bnet_fsend(UA_sock, ".messages"); + } } else { at_prompt = FALSE; /* @ => internal command for us */ diff --git a/bacula/src/stored/append.c b/bacula/src/stored/append.c index 8195769e85..a73ce428c6 100644 --- a/bacula/src/stored/append.c +++ b/bacula/src/stored/append.c @@ -31,6 +31,12 @@ /* Responses sent to the File daemon */ static char OK_data[] = "3000 OK data\n"; +/* Forward referenced functions */ +static bool is_spooled(JCR *jcr); +static int begin_attribute_spool(JCR *jcr); +static int discard_attribute_spool(JCR *jcr); +static int commit_attribute_spool(JCR *jcr); + /* * Append Data sent from File daemon * @@ -51,15 +57,14 @@ int do_append_data(JCR *jcr) /* Tell File daemon to send data */ bnet_fsend(fd_sock, OK_data); - if (!jcr->no_attributes && jcr->spool_attributes) { - open_spool_file(jcr, jcr->dir_bsock); - } + begin_attribute_spool(jcr); ds = fd_sock; if (!bnet_set_buffer_size(ds, MAX_NETWORK_BUFFER_SIZE, BNET_SETBUF_WRITE)) { set_jcr_job_status(jcr, JS_ErrorTerminated); Jmsg(jcr, M_FATAL, 0, _("Unable to set network buffer size.\n")); + discard_attribute_spool(jcr); return 0; } @@ -77,6 +82,7 @@ int do_append_data(JCR *jcr) if (!(dev=acquire_device_for_append(jcr, dev, block))) { set_jcr_job_status(jcr, JS_ErrorTerminated); free_block(block); + discard_attribute_spool(jcr); return 0; } Dmsg0(100, "Just after acquire_device_for_append\n"); @@ -205,7 +211,7 @@ int do_append_data(JCR *jcr) if (stream == STREAM_UNIX_ATTRIBUTES || stream == STREAM_MD5_SIGNATURE || stream == STREAM_UNIX_ATTRIBUTES_EX || stream == STREAM_SHA1_SIGNATURE) { if (!jcr->no_attributes) { - if (jcr->spool_attributes && jcr->dir_bsock->spool_fd) { + if (is_spooled(jcr)) { jcr->dir_bsock->spool = 1; } Dmsg0(200, "Send attributes.\n"); @@ -267,13 +273,43 @@ int do_append_data(JCR *jcr) free_block(block); - if (jcr->spool_attributes && jcr->dir_bsock->spool_fd) { - bnet_despool(jcr->dir_bsock); - close_spool_file(jcr, jcr->dir_bsock); - } + commit_attribute_spool(jcr); dir_send_job_status(jcr); /* update director */ Dmsg1(100, "return from do_append_data() stat=%d\n", ok); return ok ? 1 : 0; } + +static bool is_spooled(JCR *jcr) +{ + if (jcr->spool_attributes && jcr->dir_bsock->spool_fd) { + return true; + } + return false; +} + +static int begin_attribute_spool(JCR *jcr) +{ + if (!jcr->no_attributes && jcr->spool_attributes) { + return 0; + } + return open_spool_file(jcr, jcr->dir_bsock); +} + +static int discard_attribute_spool(JCR *jcr) +{ + if (!is_spooled(jcr)) { + return 0; + } + return close_spool_file(jcr, jcr->dir_bsock); +} + +static int commit_attribute_spool(JCR *jcr) +{ + if (!is_spooled(jcr)) { + return 0; + } + bnet_despool(jcr->dir_bsock); + return close_spool_file(jcr, jcr->dir_bsock); +} diff --git a/bacula/src/version.h b/bacula/src/version.h index 0f34138c30..809c094d63 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -2,8 +2,8 @@ #undef VERSION #define VERSION "1.32" #define VSTRING "1" -#define BDATE "06 Sep 2003" -#define LSMDATE "06Sep03" +#define BDATE "07 Sep 2003" +#define LSMDATE "07Sep03" /* Debug flags */ #undef DEBUG -- 2.39.5