From 05f086fe0c4430f1a805c9e604cf502a32d6c1e7 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Fri, 28 Sep 2007 21:10:18 +0000 Subject: [PATCH] Eliminate more strerror() and replace with bstrerror(). git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@5683 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/cats/mysql.c | 3 ++- bacula/src/cats/sqlite.c | 3 ++- bacula/src/console/console.c | 3 ++- bacula/src/dird/ua_query.c | 3 ++- bacula/src/dird/ua_run.c | 3 ++- bacula/src/stored/block.c | 12 ++++++++---- bacula/src/stored/bls.c | 26 ++++++++++++++------------ bacula/src/stored/dircmd.c | 5 +++-- bacula/src/stored/fd_cmds.c | 3 ++- bacula/src/stored/label.c | 5 ----- bacula/src/stored/lock.c | 5 +++-- bacula/src/stored/stored.c | 6 ++++-- bacula/technotes-2.3 | 1 + 13 files changed, 45 insertions(+), 33 deletions(-) diff --git a/bacula/src/cats/mysql.c b/bacula/src/cats/mysql.c index e54db4cebc..c0068b1b1d 100644 --- a/bacula/src/cats/mysql.c +++ b/bacula/src/cats/mysql.c @@ -149,8 +149,9 @@ db_open_database(JCR *jcr, B_DB *mdb) } if ((errstat=rwl_init(&mdb->lock)) != 0) { + berrno be; Mmsg1(&mdb->errmsg, _("Unable to initialize DB lock. ERR=%s\n"), - strerror(errstat)); + be.bstrerror(errstat)); V(mutex); return 0; } diff --git a/bacula/src/cats/sqlite.c b/bacula/src/cats/sqlite.c index 964c30d9c1..b4331dd815 100644 --- a/bacula/src/cats/sqlite.c +++ b/bacula/src/cats/sqlite.c @@ -158,8 +158,9 @@ db_open_database(JCR *jcr, B_DB *mdb) mdb->connected = FALSE; if ((errstat=rwl_init(&mdb->lock)) != 0) { + berrno be; Mmsg1(&mdb->errmsg, _("Unable to initialize DB lock. ERR=%s\n"), - strerror(errstat)); + be.bstrerror(errstat)); V(mutex); return 0; } diff --git a/bacula/src/console/console.c b/bacula/src/console/console.c index c2c4dd5f73..0874558b4a 100644 --- a/bacula/src/console/console.c +++ b/bacula/src/console/console.c @@ -898,8 +898,9 @@ static int inputcmd(FILE *input, BSOCK *UA_sock) } fd = fopen(argk[1], "rb"); if (!fd) { + berrno be; senditf(_("Cannot open file %s for input. ERR=%s\n"), - argk[1], strerror(errno)); + argk[1], be.bstrerror()); return 1; } read_and_process_input(fd, UA_sock); diff --git a/bacula/src/dird/ua_query.c b/bacula/src/dird/ua_query.c index 2ab55acb39..231e41700b 100644 --- a/bacula/src/dird/ua_query.c +++ b/bacula/src/dird/ua_query.c @@ -69,8 +69,9 @@ int querycmd(UAContext *ua, const char *cmd) goto bail_out; } if ((fd=fopen(query_file, "rb")) == NULL) { + berrno be; ua->error_msg(_("Could not open %s: ERR=%s\n"), query_file, - strerror(errno)); + be.bstrerror()); goto bail_out; } diff --git a/bacula/src/dird/ua_run.c b/bacula/src/dird/ua_run.c index b844db6cbc..4f5f86a66b 100644 --- a/bacula/src/dird/ua_run.c +++ b/bacula/src/dird/ua_run.c @@ -376,8 +376,9 @@ try_again: jcr->RestoreBootstrap = bstrdup(ua->cmd); fd = fopen(jcr->RestoreBootstrap, "rb"); if (!fd) { + berrno be; ua->send_msg(_("Warning cannot open %s: ERR=%s\n"), - jcr->RestoreBootstrap, strerror(errno)); + jcr->RestoreBootstrap, be.bstrerror()); free(jcr->RestoreBootstrap); jcr->RestoreBootstrap = NULL; } else { diff --git a/bacula/src/stored/block.c b/bacula/src/stored/block.c index 9bca599f84..e5b95b624d 100644 --- a/bacula/src/stored/block.c +++ b/bacula/src/stored/block.c @@ -576,9 +576,12 @@ bool write_block_to_dev(DCR *dcr) dev->VolCatInfo.VolCatName, dev->file, dev->block_num, dev->print_name(), wlen, stat); } - Dmsg7(100, "=== Write error. fd=%d size=%u rtn=%d dev_blk=%d blk_blk=%d errno=%d: ERR=%s\n", - dev->fd(), wlen, stat, dev->block_num, block->BlockNumber, - dev->dev_errno, strerror(dev->dev_errno)); + if (debug_level >= 100) { + berrno be; + Dmsg7(100, "=== Write error. fd=%d size=%u rtn=%d dev_blk=%d blk_blk=%d errno=%d: ERR=%s\n", + dev->fd(), wlen, stat, dev->block_num, block->BlockNumber, + dev->dev_errno, be.bstrerror(dev->dev_errno)); + } ok = terminate_writing_volume(dcr); if (!ok && !forge_on) { @@ -767,9 +770,10 @@ static bool terminate_writing_volume(DCR *dcr) /* This may not be fatal since we already wrote an EOF */ Jmsg(dcr->jcr, M_ERROR, 0, "%s", dev->errmsg); } + bail_out: dev->set_ateot(); /* no more writing this tape */ - Dmsg1(100, "Leave terminate_writing_volume -- %s\n", ok?"OK":"ERROR"); + Dmsg1(50, "*** Leave terminate_writing_volume -- %s\n", ok?"OK":"ERROR"); return ok; } diff --git a/bacula/src/stored/bls.c b/bacula/src/stored/bls.c index 7e54fe79e7..92d6fbcc95 100644 --- a/bacula/src/stored/bls.c +++ b/bacula/src/stored/bls.c @@ -1,15 +1,7 @@ -/* - * - * Dumb program to do an "ls" of a Bacula 1.0 mortal file. - * - * Kern Sibbald, MM - * - * Version $Id$ - */ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2006 Free Software Foundation Europe e.V. + Copyright (C) 2000-2007 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -33,6 +25,14 @@ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. */ +/* + * + * Dumb program to do an "ls" of a Bacula 1.0 mortal file. + * + * Kern Sibbald, MM + * + * Version $Id$ + */ #include "bacula.h" #include "stored.h" @@ -137,8 +137,9 @@ int main (int argc, char *argv[]) case 'e': /* exclude list */ if ((fd = fopen(optarg, "rb")) == NULL) { + berrno be; Pmsg2(0, _("Could not open exclude file: %s, ERR=%s\n"), - optarg, strerror(errno)); + optarg, be.bstrerror()); exit(1); } while (fgets(line, sizeof(line), fd) != NULL) { @@ -151,8 +152,9 @@ int main (int argc, char *argv[]) case 'i': /* include list */ if ((fd = fopen(optarg, "rb")) == NULL) { + berrno be; Pmsg2(0, _("Could not open include file: %s, ERR=%s\n"), - optarg, strerror(errno)); + optarg, be.bstrerror()); exit(1); } while (fgets(line, sizeof(line), fd) != NULL) { @@ -273,7 +275,7 @@ static void do_blocks(char *infname) char buf1[100], buf2[100]; for ( ;; ) { if (!read_block_from_device(dcr, NO_BLOCK_NUMBER_CHECK)) { - Dmsg1(100, "!read_block(): ERR=%s\n", dev->strerror()); + Dmsg1(100, "!read_block(): ERR=%s\n", dev->bstrerror()); if (dev->at_eot()) { if (!mount_next_read_volume(dcr)) { Jmsg(jcr, M_INFO, 0, _("Got EOM at file %u on device %s, Volume \"%s\"\n"), diff --git a/bacula/src/stored/dircmd.c b/bacula/src/stored/dircmd.c index f54994bb97..95a05e075a 100644 --- a/bacula/src/stored/dircmd.c +++ b/bacula/src/stored/dircmd.c @@ -190,7 +190,8 @@ void *handle_connection_request(void *arg) /* Initialize FD start condition variable */ int errstat = pthread_cond_init(&jcr->job_start_wait, NULL); if (errstat != 0) { - Jmsg1(jcr, M_FATAL, 0, _("Unable to init job cond variable: ERR=%s\n"), strerror(errstat)); + berrno be; + Jmsg1(jcr, M_FATAL, 0, _("Unable to init job cond variable: ERR=%s\n"), be.bstrerror(errstat)); goto bail_out; } @@ -457,7 +458,7 @@ static void label_volume_if_ok(DCR *dcr, char *oldname, bstrncpy(dcr->VolCatInfo.VolCatName, volname, sizeof(dcr->VolCatInfo.VolCatName)); if (dev->open(dcr, mode) < 0) { dir->fsend(_("3910 Unable to open device %s: ERR=%s\n"), - dev->print_name(), dev->strerror()); + dev->print_name(), dev->bstrerror()); goto bail_out; } diff --git a/bacula/src/stored/fd_cmds.c b/bacula/src/stored/fd_cmds.c index e6e35a0953..66a2301489 100644 --- a/bacula/src/stored/fd_cmds.c +++ b/bacula/src/stored/fd_cmds.c @@ -352,8 +352,9 @@ bool get_bootstrap_file(JCR *jcr, BSOCK *sock) jcr->RestoreBootstrap = fname; bs = fopen(fname, "a+b"); /* create file */ if (!bs) { + berrno be; Jmsg(jcr, M_FATAL, 0, _("Could not create bootstrap file %s: ERR=%s\n"), - jcr->RestoreBootstrap, strerror(errno)); + jcr->RestoreBootstrap, be.bstrerror()); goto bail_out; } Dmsg0(10, "=== Bootstrap file ===\n"); diff --git a/bacula/src/stored/label.c b/bacula/src/stored/label.c index 8f926bb7cc..e56e32c39b 100644 --- a/bacula/src/stored/label.c +++ b/bacula/src/stored/label.c @@ -733,16 +733,11 @@ bool write_session_label(DCR *dcr, int label) Dmsg0(150, "Cannot write session label to block.\n"); if (!write_block_to_device(dcr)) { Dmsg0(130, "Got session label write_block_to_dev error.\n"); - /* ****FIXME***** errno is not set here */ - Jmsg(jcr, M_FATAL, 0, _("Error writing Session label to %s: %s\n"), - dev_vol_name(dev), strerror(errno)); free_record(rec); return false; } } if (!write_record_to_block(block, rec)) { - Jmsg(jcr, M_FATAL, 0, _("Error writing Session label to %s: %s\n"), - dev_vol_name(dev), strerror(errno)); free_record(rec); return false; } diff --git a/bacula/src/stored/lock.c b/bacula/src/stored/lock.c index a52ff4e5e3..28200047b9 100644 --- a/bacula/src/stored/lock.c +++ b/bacula/src/stored/lock.c @@ -88,13 +88,14 @@ const int dbglvl = 500; * DEVICE::dlock() does P(m_mutex) (in dev.h) * DEVICE::dunlock() does V(m_mutex) * - * DEVICE::r_dlock() does recursive locking + * DEVICE::r_dlock() allows locking the device when this thread + already has the device blocked. * dlock() * if blocked and not same thread that locked * pthread_cond_wait * leaves device locked * - * DEVICE::r_dunlock() + * DEVICE::r_dunlock() unlocks but does not unblock * same as dunlock(); * * DEVICE::dblock(why) does diff --git a/bacula/src/stored/stored.c b/bacula/src/stored/stored.c index 070e788d8f..74c69e08c1 100644 --- a/bacula/src/stored/stored.c +++ b/bacula/src/stored/stored.c @@ -253,7 +253,8 @@ int main (int argc, char *argv[]) */ create_volume_list(); /* do before device_init */ if (pthread_create(&thid, NULL, device_initialization, NULL) != 0) { - Emsg1(M_ABORT, 0, _("Unable to create thread. ERR=%s\n"), strerror(errno)); + berrno be; + Emsg1(M_ABORT, 0, _("Unable to create thread. ERR=%s\n"), be.bstrerror()); } start_watchdog(); /* start watchdog thread */ @@ -471,7 +472,8 @@ void *device_initialization(void *arg) /* Initialize FD start condition variable */ int errstat = pthread_cond_init(&jcr->job_start_wait, NULL); if (errstat != 0) { - Jmsg1(jcr, M_ABORT, 0, _("Unable to init job cond variable: ERR=%s\n"), strerror(errstat)); + berrno be; + Jmsg1(jcr, M_ABORT, 0, _("Unable to init job cond variable: ERR=%s\n"), be.bstrerror(errstat)); } foreach_res(device, R_DEVICE) { diff --git a/bacula/technotes-2.3 b/bacula/technotes-2.3 index a3ceb47fa4..f1c537019c 100644 --- a/bacula/technotes-2.3 +++ b/bacula/technotes-2.3 @@ -2,6 +2,7 @@ General: 28Sep07 +kes Eliminate more strerror() and replace with bstrerror(). kes Remove BSD getopt and replace with unrestricted IBM version kes Fix Win32 build. kes More tweaks to the mount volume routines to get everything -- 2.39.5