From 0826016d9a5e59d2729f425976e18847154064c4 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sun, 25 Jul 2004 08:42:57 +0000 Subject: [PATCH] Fix new DCRs in bscan + 32/64 bit editing checks in btape git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1489 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/autoconf/aclocal.m4 | 62 +++++++++++++++++------------------ bacula/configure | 62 +++++++++++++++++------------------ bacula/examples/ssh-tunnel.sh | 47 ++++++++++++++++++++++++++ bacula/kernstodo | 3 +- bacula/src/lib/bnet.c | 2 +- bacula/src/lib/message.c | 14 ++++---- bacula/src/stored/acquire.c | 1 + bacula/src/stored/bscan.c | 35 ++++++++++---------- bacula/src/stored/btape.c | 23 ++++++++++++- bacula/src/stored/dev.c | 2 ++ bacula/src/stored/device.c | 9 +++-- bacula/src/version.h | 4 +-- bacula/src/win32/README.win32 | 11 +++++++ 13 files changed, 180 insertions(+), 95 deletions(-) create mode 100755 bacula/examples/ssh-tunnel.sh diff --git a/bacula/autoconf/aclocal.m4 b/bacula/autoconf/aclocal.m4 index 725e7773ab..32a4bca5de 100644 --- a/bacula/autoconf/aclocal.m4 +++ b/bacula/autoconf/aclocal.m4 @@ -494,42 +494,42 @@ AC_ARG_WITH(sqlite, a number of common places for the SQLite files.], [ if test "$withval" != "no"; then - if test "$withval" = "yes"; then - if test -f /usr/local/include/sqlite.h; then - SQLITE_INCDIR=/usr/local/include - SQLITE_LIBDIR=/usr/local/lib - SQLITE_BINDIR=/usr/local/bin - elif test -f /usr/include/sqlite.h; then - SQLITE_INCDIR=/usr/include - SQLITE_LIBDIR=/usr/lib - SQLITE_BINDIR=/usr/bin - else - AC_MSG_RESULT(no) - AC_MSG_ERROR(Unable to find sqlite.h in standard locations) - fi + if test "$withval" = "yes"; then + if test -f /usr/local/include/sqlite.h; then + SQLITE_INCDIR=/usr/local/include + SQLITE_LIBDIR=/usr/local/lib + SQLITE_BINDIR=/usr/local/bin + elif test -f /usr/include/sqlite.h; then + SQLITE_INCDIR=/usr/include + SQLITE_LIBDIR=/usr/lib + SQLITE_BINDIR=/usr/bin else - if test -f $withval/sqlite.h; then - SQLITE_INCDIR=$withval - SQLITE_LIBDIR=$withval - SQLITE_BINDIR=$withval - else - AC_MSG_RESULT(no) - AC_MSG_ERROR(Invalid SQLite directory $withval - unable to find sqlite.h under $withval) - fi + AC_MSG_RESULT(no) + AC_MSG_ERROR(Unable to find sqlite.h in standard locations) fi - SQL_INCLUDE=-I$SQLITE_INCDIR - SQL_LFLAGS="-L$SQLITE_LIBDIR -lsqlite" - SQL_BINDIR=$SQLITE_BINDIR + else + if test -f $withval/sqlite.h; then + SQLITE_INCDIR=$withval + SQLITE_LIBDIR=$withval + SQLITE_BINDIR=$withval + else + AC_MSG_RESULT(no) + AC_MSG_ERROR(Invalid SQLite directory $withval - unable to find sqlite.h under $withval) + fi + fi + SQL_INCLUDE=-I$SQLITE_INCDIR + SQL_LFLAGS="-L$SQLITE_LIBDIR -lsqlite" + SQL_BINDIR=$SQLITE_BINDIR - AC_DEFINE(HAVE_SQLITE) - AC_MSG_RESULT(yes) - db_found=yes - support_sqlite=yes - db_name=SQLite - DB_NAME=sqlite + AC_DEFINE(HAVE_SQLITE) + AC_MSG_RESULT(yes) + db_found=yes + support_sqlite=yes + db_name=SQLite + DB_NAME=sqlite else - AC_MSG_RESULT(no) + AC_MSG_RESULT(no) fi ],[ AC_MSG_RESULT(no) diff --git a/bacula/configure b/bacula/configure index 836e187dd4..5ea5e5a539 100755 --- a/bacula/configure +++ b/bacula/configure @@ -7534,52 +7534,52 @@ if test "${with_sqlite+set}" = set; then withval="$with_sqlite" if test "$withval" != "no"; then - if test "$withval" = "yes"; then - if test -f /usr/local/include/sqlite.h; then - SQLITE_INCDIR=/usr/local/include - SQLITE_LIBDIR=/usr/local/lib - SQLITE_BINDIR=/usr/local/bin - elif test -f /usr/include/sqlite.h; then - SQLITE_INCDIR=/usr/include - SQLITE_LIBDIR=/usr/lib - SQLITE_BINDIR=/usr/bin - else - echo "$as_me:$LINENO: result: no" >&5 + if test "$withval" = "yes"; then + if test -f /usr/local/include/sqlite.h; then + SQLITE_INCDIR=/usr/local/include + SQLITE_LIBDIR=/usr/local/lib + SQLITE_BINDIR=/usr/local/bin + elif test -f /usr/include/sqlite.h; then + SQLITE_INCDIR=/usr/include + SQLITE_LIBDIR=/usr/lib + SQLITE_BINDIR=/usr/bin + else + echo "$as_me:$LINENO: result: no" >&5 echo "${ECHO_T}no" >&6 - { { echo "$as_me:$LINENO: error: Unable to find sqlite.h in standard locations" >&5 + { { echo "$as_me:$LINENO: error: Unable to find sqlite.h in standard locations" >&5 echo "$as_me: error: Unable to find sqlite.h in standard locations" >&2;} { (exit 1); exit 1; }; } - fi + fi + else + if test -f $withval/sqlite.h; then + SQLITE_INCDIR=$withval + SQLITE_LIBDIR=$withval + SQLITE_BINDIR=$withval else - if test -f $withval/sqlite.h; then - SQLITE_INCDIR=$withval - SQLITE_LIBDIR=$withval - SQLITE_BINDIR=$withval - else - echo "$as_me:$LINENO: result: no" >&5 + echo "$as_me:$LINENO: result: no" >&5 echo "${ECHO_T}no" >&6 - { { echo "$as_me:$LINENO: error: Invalid SQLite directory $withval - unable to find sqlite.h under $withval" >&5 + { { echo "$as_me:$LINENO: error: Invalid SQLite directory $withval - unable to find sqlite.h under $withval" >&5 echo "$as_me: error: Invalid SQLite directory $withval - unable to find sqlite.h under $withval" >&2;} { (exit 1); exit 1; }; } - fi fi - SQL_INCLUDE=-I$SQLITE_INCDIR - SQL_LFLAGS="-L$SQLITE_LIBDIR -lsqlite" - SQL_BINDIR=$SQLITE_BINDIR + fi + SQL_INCLUDE=-I$SQLITE_INCDIR + SQL_LFLAGS="-L$SQLITE_LIBDIR -lsqlite" + SQL_BINDIR=$SQLITE_BINDIR - cat >>confdefs.h <<\_ACEOF + cat >>confdefs.h <<\_ACEOF #define HAVE_SQLITE 1 _ACEOF - echo "$as_me:$LINENO: result: yes" >&5 + echo "$as_me:$LINENO: result: yes" >&5 echo "${ECHO_T}yes" >&6 - db_found=yes - support_sqlite=yes - db_name=SQLite - DB_NAME=sqlite + db_found=yes + support_sqlite=yes + db_name=SQLite + DB_NAME=sqlite else - echo "$as_me:$LINENO: result: no" >&5 + echo "$as_me:$LINENO: result: no" >&5 echo "${ECHO_T}no" >&6 fi diff --git a/bacula/examples/ssh-tunnel.sh b/bacula/examples/ssh-tunnel.sh new file mode 100755 index 0000000000..d1b1a7e7e7 --- /dev/null +++ b/bacula/examples/ssh-tunnel.sh @@ -0,0 +1,47 @@ +#!/bin/sh +# script for creating / stopping a ssh-tunnel to a backupclient +# Stephan Holl +# +# + +# variables +USER=xxxx +CLIENT=domain.com +CLIENT_PORT=9112 +LOCAL=192.168.2.4 +LOCAL_PORT=$CLIENT_PORT +SSH=/usr/bin/ssh + + +case "$1" in + start) + # create ssh-tunnel + + echo "Start SSH-tunnel to $CLIENT..." + $SSH -vfnCNg2 -o PreferredAuthentications=publickey -i /var/lib/bacula/.ssh/id_dsa -l $USER -L $CLIENT_PORT:$CLIENT:$LOCAL_PORT -R 9101:$LOCAL:9101 -R 9103:$LOCAL:9103 $CLIENT + exit 0 + ;; + + stop) + # remove tunnel + echo "Stop SSH-tunnel to $CLIENT..." + + # find PID killem + PID=`ps ax|grep "/usr/bin/ssh -vfnCNg2 -o PreferredAuthentications=publickey -i /var/lib/bacula/.ssh/id_dsa -l $USER -L $CLIENT_PORT:$CLIENT:$LOCAL_PORT -R 9101:$LOCAL:9101 -R 9103:$LOCAL:9103 $CLIENT &"|cut -d" " -f1` + kill $PID + exit 0 + ;; + *) + # usage: + echo " " + echo " Start SSH-tunnel to client-host" + echo " to bacula-director and storage-daemon" + echo " " + echo " USAGE:" + echo " ssh-tunnel.sh {start|stop}" + echo " " + exit 1 + ;; +esac + + diff --git a/bacula/kernstodo b/bacula/kernstodo index 50cc64f0a4..377e7e83ac 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -2,6 +2,7 @@ 22 July 2004 1.35 Items to do: +- Add bscan to four-concurrent-jobs regression. - Do tape alerts -- see tapealert.txt - Fix errno handling in win32 compat routines. - Add better error codes to run_program (10000+) @@ -25,6 +26,7 @@ bscan-test. - Fix restore ++++ that get intermingled with "Building directory tree" - Solve the termcap.h problem on Solaris configure. +- Fix ./configure to handle installed SQLite Documentation to do: (any release a little bit at a time) - Document query file format. @@ -1113,4 +1115,3 @@ Block Position: 0 Building directory tree for JobId 856 ... Building directory tree for JobId 797 ...3 Jobs inserted into the tree. - diff --git a/bacula/src/lib/bnet.c b/bacula/src/lib/bnet.c index 95ced20fe9..e4641f4266 100644 --- a/bacula/src/lib/bnet.c +++ b/bacula/src/lib/bnet.c @@ -708,7 +708,7 @@ again: va_start(arg_ptr, fmt); bs->msglen = bvsnprintf(mp_chr(bs->msg), maxlen, fmt, arg_ptr); va_end(arg_ptr); - if (bs->msglen < 0 || bs->msglen >= maxlen) { + if (bs->msglen < 0 || bs->msglen >= (maxlen-5)) { bs->msg = realloc_pool_memory(bs->msg, maxlen + maxlen / 2); goto again; } diff --git a/bacula/src/lib/message.c b/bacula/src/lib/message.c index 98bc6c36c0..93e82570a4 100755 --- a/bacula/src/lib/message.c +++ b/bacula/src/lib/message.c @@ -1068,7 +1068,7 @@ void j_msg(const char *file, int line, JCR *jcr, int type, int level, const char va_start(arg_ptr, fmt); len = bvsnprintf(pool_buf+i, maxlen, fmt, arg_ptr); va_end(arg_ptr); - if (len < 0 || len >= maxlen) { + if (len < 0 || len >= (maxlen-5)) { pool_buf = realloc_pool_memory(pool_buf, maxlen + i + maxlen/2); continue; } @@ -1082,7 +1082,7 @@ void j_msg(const char *file, int line, JCR *jcr, int type, int level, const char /* * Edit a message into a Pool memory buffer, with file:lineno - */ + */ int m_msg(const char *file, int line, POOLMEM **pool_buf, const char *fmt, ...) { va_list arg_ptr; @@ -1095,7 +1095,7 @@ int m_msg(const char *file, int line, POOLMEM **pool_buf, const char *fmt, ...) va_start(arg_ptr, fmt); len = bvsnprintf(*pool_buf+i, maxlen, fmt, arg_ptr); va_end(arg_ptr); - if (len < 0 || len >= maxlen) { + if (len < 0 || len >= (maxlen-5)) { *pool_buf = realloc_pool_memory(*pool_buf, maxlen + i + maxlen/2); continue; } @@ -1118,7 +1118,7 @@ int Mmsg(POOLMEM **pool_buf, const char *fmt, ...) va_start(arg_ptr, fmt); len = bvsnprintf(*pool_buf, maxlen, fmt, arg_ptr); va_end(arg_ptr); - if (len < 0 || len >= maxlen) { + if (len < 0 || len >= (maxlen-5)) { *pool_buf = realloc_pool_memory(*pool_buf, maxlen + maxlen/2); continue; } @@ -1150,7 +1150,7 @@ void Qmsg(JCR *jcr, int type, int level, const char *fmt,...) va_start(arg_ptr, fmt); len = bvsnprintf(pool_buf, maxlen, fmt, arg_ptr); va_end(arg_ptr); - if (len < 0 || len >= maxlen) { + if (len < 0 || len >= (maxlen-5)) { pool_buf = realloc_pool_memory(pool_buf, maxlen + maxlen/2); continue; } @@ -1190,7 +1190,7 @@ void dequeue_messages(JCR *jcr) jcr->msg_queue->destroy(); jcr->dequeuing = false; V(msg_queue_mutex); -} +} /* @@ -1211,7 +1211,7 @@ void q_msg(const char *file, int line, JCR *jcr, int type, int level, const char va_start(arg_ptr, fmt); len = bvsnprintf(pool_buf+i, maxlen, fmt, arg_ptr); va_end(arg_ptr); - if (len < 0 || len >= maxlen) { + if (len < 0 || len >= (maxlen-5)) { pool_buf = realloc_pool_memory(pool_buf, maxlen + i + maxlen/2); continue; } diff --git a/bacula/src/stored/acquire.c b/bacula/src/stored/acquire.c index 147137deae..0a492a61f5 100644 --- a/bacula/src/stored/acquire.c +++ b/bacula/src/stored/acquire.c @@ -410,6 +410,7 @@ bool release_device(JCR *jcr) } else { Jmsg2(jcr, M_ERROR, 0, _("BAD ERROR: release_device %s, Volume \"%s\" not in use.\n"), dev_name(dev), NPRT(jcr->VolumeName)); + Jmsg2(jcr, M_ERROR, 0, _("num_writers=%d state=%x\n"), dev->num_writers, dev->state); } // detach_jcr_from_device(dev, jcr); if (dev->prev && !dev_state(dev, ST_READ) && !dev->num_writers) { diff --git a/bacula/src/stored/bscan.c b/bacula/src/stored/bscan.c index d0c111cc55..fde90cac3d 100644 --- a/bacula/src/stored/bscan.c +++ b/bacula/src/stored/bscan.c @@ -278,13 +278,12 @@ int main (int argc, char *argv[]) static bool bscan_mount_next_read_volume(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) { Dmsg1(100, "Walk attached jcrs. Volume=%s\n", dev->VolCatInfo.VolCatName); -#ifdef xxx - for (JCR *mjcr=NULL; (mjcr=next_attached_jcr(dev, mjcr)); ) { - DCR *dcr = mjcr->dcr; -#endif DCR *dcr; foreach_dlist(dcr, dev->attached_dcrs) { JCR *mjcr = dcr->jcr; + if (mjcr->JobId == 0) { + continue; + } if (verbose) { Pmsg1(000, _("Create JobMedia for Job %s\n"), mjcr->Job); } @@ -305,8 +304,6 @@ static bool bscan_mount_next_read_volume(JCR *jcr, DEVICE *dev, DEV_BLOCK *block * have the Volume list, but we get attached. */ bool stat = mount_next_read_volume(jcr, dev, block); - /* we must once more detach ourselves (attached by mount_next ...) */ - detach_jcr_from_device(dev, jcr); /* detach bscan jcr */ return stat; } @@ -322,16 +319,15 @@ static void do_scan() memset(&fr, 0, sizeof(fr)); /* Detach bscan's jcr as we are not a real Job on the tape */ - detach_jcr_from_device(dev, bjcr); read_records(bjcr->dcr, record_cb, bscan_mount_next_read_volume); - release_device(bjcr); +// release_device(bjcr); free_attr(attr); } /* - * Returns: true if OK + * Returns: true if OK * false if error */ static bool record_cb(JCR *bjcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec) @@ -417,8 +413,7 @@ static bool record_cb(JCR *bjcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec) Pmsg1(000, _("Media type \"%s\" is OK.\n"), mr.MediaType); } /* Reset some JCR variables */ - for (mjcr=NULL; (mjcr=next_attached_jcr(dev, mjcr)); ) { - dcr = mjcr->dcr; + foreach_dlist(dcr, dev->attached_dcrs) { dcr->VolFirstIndex = dcr->FileIndex = 0; dcr->StartBlock = dcr->EndBlock = 0; dcr->StartFile = dcr->EndFile = 0; @@ -530,7 +525,7 @@ static bool record_cb(JCR *bjcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec) /* Create JobMedia record */ create_jobmedia_record(db, mjcr); - detach_jcr_from_device(dev, mjcr); + dev->attached_dcrs->remove(mjcr->dcr); free_jcr(mjcr); break; @@ -544,10 +539,14 @@ static bool record_cb(JCR *bjcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec) * them. */ if (update_db) { - mjcr=next_attached_jcr(dev, NULL); - for ( ; mjcr; ) { - JCR *njcr; + DCR *mdcr; + foreach_dlist(mdcr, dev->attached_dcrs) { + JCR *mjcr = mdcr->jcr; + if (!mjcr || mjcr->JobId == 0) { + continue; + } jr.JobId = mjcr->JobId; + /* Mark Job as Error Terimined */ jr.JobStatus = JS_ErrorTerminated; jr.JobFiles = mjcr->JobFiles; jr.JobBytes = mjcr->JobBytes; @@ -558,9 +557,8 @@ static bool record_cb(JCR *bjcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec) if (!db_update_job_end_record(bjcr, db, &jr)) { Pmsg1(0, _("Could not update job record. ERR=%s\n"), db_strerror(db)); } - njcr = mjcr->next_dev; + mjcr->dcr = NULL; free_jcr(mjcr); - mjcr = njcr; } } mr.VolFiles = rec->File; @@ -1002,7 +1000,8 @@ static int update_job_record(B_DB *db, JOB_DBR *jr, SESSION_LABEL *elabel, return 0; } if (verbose) { - Pmsg1(000, _("Updated Job termination record for new JobId=%u\n"), jr->JobId); + Pmsg2(000, _("Updated Job termination record for JobId=%u TermStat=%c\n"), jr->JobId, + jr->JobStatus); } if (verbose > 1) { const char *term_msg; diff --git a/bacula/src/stored/btape.c b/bacula/src/stored/btape.c index 674307dbb3..99c24113dd 100644 --- a/bacula/src/stored/btape.c +++ b/bacula/src/stored/btape.c @@ -144,7 +144,10 @@ int get_cmd(const char *prompt); */ int main(int margc, char *margv[]) { - int ch; + int ch, i; + uint32_t x32, y32; + uint64_t x64, y64; + char buf[1000]; /* Sanity checks */ if (TAPE_BSIZE % DEV_BSIZE != 0 || TAPE_BSIZE / DEV_BSIZE == 0) { @@ -154,6 +157,24 @@ int main(int margc, char *margv[]) if (TAPE_BSIZE != (1 << (ffs(TAPE_BSIZE)-1))) { Emsg1(M_ABORT, 0, "Tape block size (%d) is not a power of 2\n", TAPE_BSIZE); } + if (sizeof(off_t) < 8) { + Pmsg1(-1, "\n\n!!!! Warning large disk addressing disabled. off_t=%d should be 8 or more !!!!!\n\n\n", + sizeof(off_t)); + } + x32 = 123456789; + bsnprintf(buf, sizeof(buf), "%u", x32); + i = bsscanf(buf, "%u", &y32); + if (i != 1 || x32 != y32) { + Pmsg3(-1, "32 bit printf/scanf problem. i=%d x32=%u y32=%u\n", i, x32, y32); + exit(1); + } + x64 = 123456789012345678; + bsnprintf(buf, sizeof(buf), "%" llu, x64); + i = bsscanf(buf, "%llu", &y64); + if (i != 1 || x64 != y64) { + Pmsg3(-1, "64 bit printf/scanf problem. i=%d x64=%" llu " y64=%" llu "\n", i, x64, y64); + exit(1); + } printf("Tape block granularity is %d bytes.\n", TAPE_BSIZE); diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index 90772c41d8..658ea1aad1 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -1418,6 +1418,7 @@ term_dev(DEVICE *dev) } } +#ifdef xxxx /* * We attach a jcr to the device so that when * the Volume is full during writing, a @@ -1456,6 +1457,7 @@ JCR *next_attached_jcr(DEVICE *dev, JCR *jcr) } return jcr->next_dev; } +#endif /* * This routine initializes the device wait timers diff --git a/bacula/src/stored/device.c b/bacula/src/stored/device.c index 77fe763489..75c419405f 100644 --- a/bacula/src/stored/device.c +++ b/bacula/src/stored/device.c @@ -162,14 +162,17 @@ bool fixup_device_block_write_error(DCR *dcr, DEV_BLOCK *block) * Walk through all attached jcrs indicating the volume has changed */ Dmsg1(100, "Walk attached jcrs. Volume=%s\n", dev->VolCatInfo.VolCatName); - for (JCR *mjcr=NULL; (mjcr=next_attached_jcr(dev, mjcr)); ) { +// for (JCR *mjcr=NULL; (mjcr=next_attached_jcr(dev, mjcr)); ) { + DCR *mdcr; + foreach_dlist(mdcr, dev->attached_dcrs) { + JCR *mjcr = mdcr->jcr; if (mjcr->JobId == 0) { continue; /* ignore console */ } - mjcr->dcr->NewVol = true; + mdcr->NewVol = true; if (jcr != mjcr) { pm_strcpy(&mjcr->VolumeName, jcr->VolumeName); /* get a copy of the new volume */ - bstrncpy(mjcr->dcr->VolumeName, jcr->VolumeName, sizeof(mjcr->dcr->VolumeName)); + bstrncpy(mdcr->VolumeName, jcr->VolumeName, sizeof(mdcr->VolumeName)); } } diff --git a/bacula/src/version.h b/bacula/src/version.h index 5d67c12bfa..9c5c2795b6 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -1,8 +1,8 @@ /* */ #undef VERSION #define VERSION "1.35.1" -#define BDATE "22 July 2004" -#define LSMDATE "22Jul04" +#define BDATE "24 July 2004" +#define LSMDATE "24Jul04" /* Debug flags */ #undef DEBUG diff --git a/bacula/src/win32/README.win32 b/bacula/src/win32/README.win32 index bbaa22733f..58efef1d56 100644 --- a/bacula/src/win32/README.win32 +++ b/bacula/src/win32/README.win32 @@ -33,14 +33,25 @@ release section. To build it: - Make sure nmake is on your PATH. +- Make sure your COMSPEC is properly setup (see full dump of + my cygwin environment below). - The build is done in an rxvt window under the latest version of cygwin. - You need the Platform SDK installed. - You need Visual Studio installed. +- You need to load depkgs-win32, then + cd depkgs-win32 + cd wx + ./configure + (try doing a make, but it will probably fail) - You may have to build wx with VC++ (as was the case for me). After starting VC++, use File->Open Workspace then open wx/src/wxWindows.dsw then use Build->Build All or Build->build wxmsw.lib should work too. +- Then + cd depkgs-win32 + make + this will build pthreads and zlib - cd bacula ./configure --enable-client-only cd src/win32 -- 2.39.5