From 66f873e958fc247cfcb54a7dff7e477a1f5c1da4 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sat, 8 Jul 2006 07:57:43 +0000 Subject: [PATCH] ======================= Warning ========================== Implemented new method of getting the default Storage from the Media record rather than from the MediaType for restore. As a fall back, if no Storage is defined, use the MediaType. This eliminates most all prompts if there are multiple MediaTypes used. This is an important and fundamental change. ========================================================== - Add more detail (Storage, Device) to list of volumes printed for restore. - More code in migrate. In particular start multiple jobs if migrating a volume. - Probably overkill, but ensure that the bsr is unique even within a job in FD and SD. - Rework bsys.c drop() so that it now should work as expected. - Update a bunch of old copyrights -- particularly in .h files. - Remove src/lib/bshm.c/h git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@3128 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/examples/reports/check_bacula_pools.sh | 179 ++++++++++++++++++ bacula/kernstodo | 1 + bacula/kes-1.39 | 32 +++- bacula/src/dird/bsr.c | 55 ++++-- bacula/src/dird/migrate.c | 89 +++++---- bacula/src/dird/protos.h | 1 + bacula/src/dird/ua_restore.c | 139 +++++++------- bacula/src/filed/job.c | 10 +- bacula/src/lib/.cvsignore | 1 + bacula/src/lib/Makefile.in | 4 +- bacula/src/lib/address_conf.h | 21 +- bacula/src/lib/attr.h | 19 +- bacula/src/lib/bshm.c | 150 --------------- bacula/src/lib/bshm.h | 42 ---- bacula/src/lib/bsys.c | 71 ++++--- bacula/src/lib/btime.h | 56 +++--- bacula/src/lib/btree.h | 2 +- bacula/src/lib/lib.h | 1 - bacula/src/lib/md5.h | 21 +- bacula/src/lib/message.h | 39 ++-- bacula/src/lib/openssl.h | 2 +- bacula/src/lib/queue.h | 26 +-- bacula/src/lib/runscript.h | 2 +- bacula/src/lib/semlock.h | 17 +- bacula/src/lib/serial.h | 25 +-- bacula/src/lib/smartall.h | 2 +- bacula/src/lib/var.h | 17 +- bacula/src/lib/waitq.h | 33 ++-- bacula/src/lib/watchdog.h | 33 ++-- bacula/src/lib/workq.h | 25 +-- bacula/src/stored/fd_cmds.c | 10 +- bacula/src/stored/mac.c | 2 +- bacula/src/version.h | 6 +- 33 files changed, 584 insertions(+), 549 deletions(-) create mode 100755 bacula/examples/reports/check_bacula_pools.sh delete mode 100644 bacula/src/lib/bshm.c delete mode 100644 bacula/src/lib/bshm.h diff --git a/bacula/examples/reports/check_bacula_pools.sh b/bacula/examples/reports/check_bacula_pools.sh new file mode 100755 index 0000000000..8c51790328 --- /dev/null +++ b/bacula/examples/reports/check_bacula_pools.sh @@ -0,0 +1,179 @@ +#! /bin/sh +# Author : Ludovic Strappazon. l.strappazon@gmail.com +# Copyright : Kern Sibbald +# Any comment, advice or enhancement are welcome :-) + +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin +MYSQL="/usr/bin/mysql -u bacula --password=cW8s9_aH" +TMP=/tmp +BACULA=/usr/local/bacula + +PROGNAME=`basename $0` +PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'` +STATUS="" + +. $PROGPATH/utils.sh + +print_usage() { + echo "Usage: $PROGNAME -P -M -w -c [-S]" +} + +print_help() { + echo "" + print_usage + echo "" + echo "This plugin checks the space available in the pool against the space required for the next scheduled backups" + echo "Example : $PROGNAME -P default -M LTO -w 20 -c 10 will check the default pool, return OK if (available space) > 1,20*(required space), WARNING if 1,20*(required space) > (available space) > 1,10*(required space), and CRITICAL else." + echo "" + echo "With the -S option, it will check the pool named Scratch and return WARNING instead of CRITICAL if the Scratch pool can save the situation." + echo "Example : $PROGNAME -P default -M LTO -w 20 -c 10 -S will check the default pool, return OK if (available space) > 1,20*(required space), WARNING if 1,20*(required space) > (available space) > 1,10*(required space) or if (available space in default and Scratch) > 1,10*(required space) > (available space in default), and CRITICAL else." + echo "" + echo "The evaluation of the space required is done by adding the biggest backups of the same level than the scheduled jobs" + echo "The available space is evaluated by the number of out of retention tapes and the average VolBytes of these Full tapes" + echo "" + echo "The Information Status are : \"Required, Available, Volume Errors\" and \"Will use Scratch pool\" if necessary." + echo "" + echo "I think this plugin should be used in passive mode, and ran by a RunAfterJob" + exit 3 +} + +NB_ARGS=$# +SCRATCH=0 +while getopts :P:M:w:c:hS OPTION +do + case $OPTION in + P) POOL="$OPTARG" + ;; + M) MEDIA_TYPE="$OPTARG" + ;; + S) SCRATCH=1 + ;; + w) WARNING="$OPTARG" + ;; + c) CRITICAL="$OPTARG" + ;; + h) print_help + exit 3 + ;; + *) print_usage + exit 3 + ;; + esac +done +shift $(($OPTIND - 1)) + +if [ "$NB_ARGS" -ne 8 -a "$NB_ARGS" -ne 9 ]; then + print_revision $PROGNAME 13/06/2006 + print_usage + exit 3 +fi + +LAST_CHECK=`ps -ef | grep check_ba[Cc]ula_pools.sh | awk {'print $5'} | uniq | wc -l` +if [ "$LAST_CHECK" -gt 1 ]; then + echo "The last check was not complete, you should increase the check_period." + exit 3 +fi + +NB_VOLUMES=`$MYSQL << EOF +USE bacula +SELECT COUNT(MediaId) from Media, Pool where Media.PoolId=Pool.PoolId and Pool.Name="$POOL" AND Inchanger = "1"; +EOF` + +NB_VOLUMES=`echo $NB_VOLUMES | cut -f 2 -d ' '` + +echo "st +1 +q" | $BACULA/etc/bconsole | sed -n /Scheduled/,/Running/p | grep Backup | tr -s [:blank:] | tr '[:blank:]' '@' > ${TMP}/Scheduled.txt + +CAPA_REQUIRED=0 +for LINE in `cat ${TMP}/Scheduled.txt` +do + SCHEDULED_JOB=`echo $LINE | awk -F@ '{print $6}'` + LEVEL=`echo $LINE | awk -F@ '{print $1}' | cut -c 1` + +MAX_VOLUME_JOB_FOR_LEVEL=`$MYSQL << EOF +USE bacula +SELECT MAX(JobBytes) from Job, Pool where Level="$LEVEL" AND Job.Name="$SCHEDULED_JOB" AND Job.PoolId=Pool.PoolId AND Pool.Name="$POOL"; +EOF +` +MAX_VOLUME_JOB_FOR_LEVEL=`echo $MAX_VOLUME_JOB_FOR_LEVEL | cut -f 2 -d ' ' ` + +CAPA_REQUIRED=$[CAPA_REQUIRED+MAX_VOLUME_JOB_FOR_LEVEL] +done + +rm ${TMP}/Scheduled.txt + + +if [ $NB_VOLUMES -gt 0 ] +then + + NB_VOLUMES_OUT_OF_RETENTION=`$MYSQL << EOF +USE bacula +SELECT COUNT(MediaId) from Media, Pool where Media.PoolId=Pool.PoolId and Pool.Name="$POOL" AND LastWritten <> "0000-00-00 00:00:00" AND UNIX_TIMESTAMP()-UNIX_TIMESTAMP(LastWritten)>Media.VolRetention AND Inchanger = "1"; +EOF +` + NB_VOLUMES_OUT_OF_RETENTION=`echo $NB_VOLUMES_OUT_OF_RETENTION | cut -f 2 -d ' '` + +NB_VOLUMES_ERROR=`$MYSQL << EOF +USE bacula +SELECT COUNT(MediaId) from Media, Pool where Media.PoolId=Pool.PoolId and Pool.Name="$POOL" AND VolStatus="Error" AND Inchanger = "1"; +EOF +` +NB_VOLUMES_ERROR=`echo $NB_VOLUMES_ERROR | cut -f 2 -d ' '` + +AVERAGE_CAPA_VOLUME=`$MYSQL << EOF +USE bacula +SELECT SUM(VolBytes)/COUNT(MediaId) FROM Media where VolStatus="Full" AND MediaType="$MEDIA_TYPE"; +EOF +` +AVERAGE_CAPA_VOLUME=`echo $AVERAGE_CAPA_VOLUME | cut -f 2 -d ' ' | cut -f 1 -d '.'` + +CAPA_VOLUMES_APPEND=`$MYSQL << EOF +USE bacula +SELECT SUM("$AVERAGE_CAPA_VOLUME"-VolBytes) from Media, Pool where Media.PoolId=Pool.PoolId and Pool.Name="$POOL" AND (VolStatus = "Append" OR VolStatus = "Recycle" OR VolStatus = "Purge") AND Inchanger = "1" AND MediaType="$MEDIA_TYPE"; +EOF +` +CAPA_VOLUMES_APPEND=`echo $CAPA_VOLUMES_APPEND | cut -f 2 -d ' '` + +if [ $SCRATCH -eq 1 ] +then +CAPA_VOLUMES_SCRATCH=`$MYSQL << EOF +USE bacula +SELECT SUM("$AVERAGE_CAPA_VOLUME"-VolBytes) from Media, Pool where Media.PoolId=Pool.PoolId and Pool.Name="Scratch" AND VolStatus = "Append" AND Inchanger = "1" AND MediaType="$MEDIA_TYPE"; +EOF +` +CAPA_VOLUMES_SCRATCH=`echo $CAPA_VOLUMES_SCRATCH | cut -f 2 -d ' '` +else +CAPA_VOLUMES_SCRATCH=0 +fi + +CAPA_WARNING=`echo $[(WARNING+100)*CAPA_REQUIRED]/100 | bc | cut -f 1 -d '.'` +CAPA_CRITICAL=`echo $[(CRITICAL+100)*CAPA_REQUIRED]/100 | bc | cut -f 1 -d '.'` +CAPA_DISP=$[NB_VOLUMES_OUT_OF_RETENTION*AVERAGE_CAPA_VOLUME+CAPA_VOLUMES_APPEND] +CAPA_DISP_INCLUDING_SCRATCH=$[CAPA_DISP+CAPA_VOLUMES_SCRATCH] + +MESSAGE="Required : $[CAPA_REQUIRED/1000000000] Go, available : $[CAPA_DISP/1000000000] Go, Volumes Error : $NB_VOLUMES_ERROR" + +if [ "$CAPA_DISP" -gt $CAPA_WARNING ]; then + echo $MESSAGE + exit 0 +elif [ "$CAPA_DISP" -gt $CAPA_CRITICAL ];then + echo $MESSAGE + exit 1 +elif [ "$CAPA_DISP_INCLUDING_SCRATCH" -gt $CAPA_CRITICAL ];then + MESSAGE="${MESSAGE}. Will use Scratch Pool !" + echo $MESSAGE + exit 1 +else + exit 2 +fi +exit 3 + +else + echo "No volume in pool ${POOL}" + if [ "$CAPA_REQUIRED" -gt 0 ] + then exit 2 + else exit 0 + fi +fi + diff --git a/bacula/kernstodo b/bacula/kernstodo index 858368f0d9..adf57fb016 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -23,6 +23,7 @@ Document: Priority: For 1.39: +- Remove queue.c code. - Correct the Include syntax in the m4.xxx files in examples/conf - Get Perl replacement for bregex.c - Make base64.c (bin_to_base64) take a buffer length diff --git a/bacula/kes-1.39 b/bacula/kes-1.39 index 3934e27f4a..d75367ee01 100644 --- a/bacula/kes-1.39 +++ b/bacula/kes-1.39 @@ -2,6 +2,24 @@ Kern Sibbald General: +08Jul06 + ======================= Warning ========================== + Implemented new method of getting the default Storage from the Media + record rather than from the MediaType for restore. As a fall + back, if no Storage is defined, use the MediaType. This + eliminates most all prompts if there are multiple MediaTypes + used. This is an important and fundamental change. + ========================================================== + +- Add more detail (Storage, Device) to list of volumes printed + for restore. +- More code in migrate. In particular start multiple jobs if + migrating a volume. +- Probably overkill, but ensure that the bsr is unique even within a + job in FD and SD. +- Rework bsys.c drop() so that it now should work as expected. +- Update a bunch of old copyrights -- particularly in .h files. +- Remove src/lib/bshm.c/h 05Jul06 - Migration fixes 04Jul06 @@ -25,7 +43,6 @@ General: - Rename the cram_md5 routine names to be slightly more appropriate to what they are doing (challenge and respond). - Robert committed his #ifdef and header cleanup. - 30Jun06 - Fix a complier warning in files/backup.c - Cleanup NOT NULL vs DEFALT 0 in database creation. @@ -39,11 +56,11 @@ General: - Write install/uninstall of new manpages. There are now a pile of man pages. Some of which need a lot of work. - ============= Warning ================================== + ======================= Warning ========================== The --mandir ./configure option now points to the top level man directory. The man files will be installed under mandir/man8 and mandir/man1 as appropriate. - =========================================================== + ========================================================== - Add complete text of GPL to LICENSE. - Implement job report that indicates where Storage and Pool @@ -65,14 +82,19 @@ General: - Detect GCC correctly (I hope) - If using GCC (actually g++) add the following compiler flags -fno-strict-aliasing -fno-exceptions -fno-rtti -- Turn on new bsnprintf() code. + + ===================== Warning ============================= + Turn on new bsnprintf() code. This could cause print output + to look different. + =========================================================== + - Fix crypto when not using openssl. I previously overlooked this. - Eliminate crypto type punning problems by eliminating void * and using uint8_t * instead. - Harden authentication failure in FD by single threading errors and forcing a 6 second wait. - ============= Warning ================================== + ===================== Warning ============================= Removed "Accept Any Volume" directive. =========================================================== diff --git a/bacula/src/dird/bsr.c b/bacula/src/dird/bsr.c index ae4317c452..3d98793e23 100644 --- a/bacula/src/dird/bsr.c +++ b/bacula/src/dird/bsr.c @@ -84,7 +84,7 @@ static bool get_storage_device(char *device, char *storage) * We are called here once for each JobMedia record * for each Volume. */ -static uint32_t write_findex(UAContext *ua, RBSR_FINDEX *fi, +static uint32_t write_findex(RBSR_FINDEX *fi, int32_t FirstIndex, int32_t LastIndex, FILE *fd) { uint32_t count = 0; @@ -194,7 +194,7 @@ bool complete_bsr(UAContext *ua, RBSR *bsr) static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static uint32_t uniq = 0; -void make_unique_restore_filename(UAContext *ua, POOLMEM **fname) +static void make_unique_restore_filename(UAContext *ua, POOL_MEM &fname) { JCR *jcr = ua->jcr; int i = find_arg_with_value(ua, "bootstrap"); @@ -211,7 +211,7 @@ void make_unique_restore_filename(UAContext *ua, POOLMEM **fname) if (jcr->RestoreBootstrap) { free(jcr->RestoreBootstrap); } - jcr->RestoreBootstrap = bstrdup(*fname); + jcr->RestoreBootstrap = bstrdup(fname.c_str()); } /* @@ -220,24 +220,30 @@ void make_unique_restore_filename(UAContext *ua, POOLMEM **fname) uint32_t write_bsr_file(UAContext *ua, RESTORE_CTX &rx) { FILE *fd; - POOLMEM *fname = get_pool_memory(PM_MESSAGE); + POOL_MEM fname(PM_MESSAGE); + POOL_MEM volmsg(PM_MESSAGE); uint32_t count = 0;; bool err; char *p; JobId_t JobId; + char Device[MAX_NAME_LENGTH]; - make_unique_restore_filename(ua, &fname); - fd = fopen(fname, "w+b"); + make_unique_restore_filename(ua, fname); + fd = fopen(fname.c_str(), "w+b"); if (!fd) { berrno be; bsendmsg(ua, _("Unable to create bootstrap file %s. ERR=%s\n"), - fname, be.strerror()); + fname.c_str(), be.strerror()); goto bail_out; } /* Write them to file */ count = write_bsr(ua, rx, fd); err = ferror(fd); fclose(fd); + if (count == 0) { + bsendmsg(ua, _("No files found to restore.\n")); + goto bail_out; + } if (err) { bsendmsg(ua, _("Error writing bsr file.\n")); count = 0; @@ -245,11 +251,13 @@ uint32_t write_bsr_file(UAContext *ua, RESTORE_CTX &rx) } - bsendmsg(ua, _("Bootstrap records written to %s\n"), fname); + bsendmsg(ua, _("Bootstrap records written to %s\n"), fname.c_str()); /* Tell the user what he will need to mount */ bsendmsg(ua, "\n"); - bsendmsg(ua, _("The job will require the following Volumes:\n")); + bsendmsg(ua, _("The job will require the following\n" + " Volume(s) Storage(s) SD Device(s)\n" + "===========================================================================\n")); /* Create Unique list of Volumes using prompt list */ start_prompt(ua, ""); if (*rx.JobIds) { @@ -261,7 +269,13 @@ uint32_t write_bsr_file(UAContext *ua, RESTORE_CTX &rx) } for (int i=0; i < nbsr->VolCount; i++) { if (nbsr->VolParams[i].VolumeName[0]) { - add_prompt(ua, nbsr->VolParams[i].VolumeName); + if (!get_storage_device(Device, nbsr->VolParams[i].Storage)) { + Device[0] = 0; + } + Mmsg(volmsg, "%-25.25s %-25.25s %-25.25s", + nbsr->VolParams[i].VolumeName, + nbsr->VolParams[i].Storage, Device); + add_prompt(ua, volmsg.c_str()); } } } @@ -271,7 +285,13 @@ uint32_t write_bsr_file(UAContext *ua, RESTORE_CTX &rx) for (RBSR *nbsr=rx.bsr; nbsr; nbsr=nbsr->next) { for (int i=0; i < nbsr->VolCount; i++) { if (nbsr->VolParams[i].VolumeName[0]) { - add_prompt(ua, nbsr->VolParams[i].VolumeName); + if (!get_storage_device(Device, nbsr->VolParams[i].Storage)) { + Device[0] = 0; + } + Mmsg(volmsg, "%-25.25s %-25.25s %-25.25s", + nbsr->VolParams[i].VolumeName, + nbsr->VolParams[i].Storage, Device); + add_prompt(ua, volmsg.c_str()); } } } @@ -288,7 +308,6 @@ uint32_t write_bsr_file(UAContext *ua, RESTORE_CTX &rx) bsendmsg(ua, "\n"); bail_out: - free_pool_memory(fname); return count; } @@ -322,6 +341,10 @@ static uint32_t write_bsr(UAContext *ua, RESTORE_CTX &rx, FILE *fd) bsr->VolParams[i].VolumeName[0] = 0; /* zap VolumeName */ continue; } + if (!rx.store) { + find_storage_resource(ua, rx, bsr->VolParams[i].Storage, + bsr->VolParams[i].MediaType); + } fprintf(fd, "Volume=\"%s\"\n", bsr->VolParams[i].VolumeName); fprintf(fd, "MediaType=\"%s\"\n", bsr->VolParams[i].MediaType); if (get_storage_device(device, bsr->VolParams[i].Storage)) { @@ -347,7 +370,7 @@ static uint32_t write_bsr(UAContext *ua, RESTORE_CTX &rx, FILE *fd) // Dmsg2(100, "bsr VolParam FI=%u LI=%u\n", // bsr->VolParams[i].FirstIndex, bsr->VolParams[i].LastIndex); - count = write_findex(ua, bsr->fi, bsr->VolParams[i].FirstIndex, + count = write_findex(bsr->fi, bsr->VolParams[i].FirstIndex, bsr->VolParams[i].LastIndex, fd); if (count) { fprintf(fd, "Count=%u\n", count); @@ -381,6 +404,10 @@ static uint32_t write_bsr(UAContext *ua, RESTORE_CTX &rx, FILE *fd) bsr->VolParams[i].VolumeName[0] = 0; /* zap VolumeName */ continue; } + if (!rx.store) { + find_storage_resource(ua, rx, bsr->VolParams[i].Storage, + bsr->VolParams[i].MediaType); + } fprintf(fd, "Volume=\"%s\"\n", bsr->VolParams[i].VolumeName); fprintf(fd, "MediaType=\"%s\"\n", bsr->VolParams[i].MediaType); if (get_storage_device(device, bsr->VolParams[i].Storage)) { @@ -406,7 +433,7 @@ static uint32_t write_bsr(UAContext *ua, RESTORE_CTX &rx, FILE *fd) // Dmsg2(100, "bsr VolParam FI=%u LI=%u\n", // bsr->VolParams[i].FirstIndex, bsr->VolParams[i].LastIndex); - count = write_findex(ua, bsr->fi, bsr->VolParams[i].FirstIndex, + count = write_findex(bsr->fi, bsr->VolParams[i].FirstIndex, bsr->VolParams[i].LastIndex, fd); if (count) { fprintf(fd, "Count=%u\n", count); diff --git a/bacula/src/dird/migrate.c b/bacula/src/dird/migrate.c index 1172638831..1a4059c1e9 100644 --- a/bacula/src/dird/migrate.c +++ b/bacula/src/dird/migrate.c @@ -38,6 +38,8 @@ #include #endif +static const int dbglevel = 100; + static char OKbootstrap[] = "3000 OK bootstrap\n"; static bool get_job_to_migrate(JCR *jcr); struct idpkt; @@ -79,9 +81,7 @@ bool do_migration_init(JCR *jcr) return false; } - if (!create_restore_bootstrap_file(jcr)) { - return false; - } + create_restore_bootstrap_file(jcr); return true; } @@ -100,17 +100,17 @@ bool do_migration(JCR *jcr) JOB *job, *prev_job; JCR *prev_jcr; /* newly migrated job */ - if (jcr->previous_jr.JobId == 0) { + if (jcr->previous_jr.JobId == 0 || jcr->ExpectedFiles == 0) { set_jcr_job_status(jcr, JS_Terminated); migration_cleanup(jcr, jcr->JobStatus); return true; /* no work */ } - Dmsg4(000, "Previous: Name=%s JobId=%d Type=%c Level=%c\n", + Dmsg4(dbglevel, "Previous: Name=%s JobId=%d Type=%c Level=%c\n", jcr->previous_jr.Name, jcr->previous_jr.JobId, jcr->previous_jr.JobType, jcr->previous_jr.JobLevel); - Dmsg4(000, "Current: Name=%s JobId=%d Type=%c Level=%c\n", + Dmsg4(dbglevel, "Current: Name=%s JobId=%d Type=%c Level=%c\n", jcr->jr.Name, jcr->jr.JobId, jcr->jr.JobType, jcr->jr.JobLevel); @@ -145,7 +145,7 @@ bool do_migration(JCR *jcr) prev_jcr->jr.FileSetId = jcr->jr.FileSetId; prev_jcr->jr.JobId = prev_jcr->JobId; - Dmsg4(000, "Prev_jcr: Name=%s JobId=%d Type=%c Level=%c\n", + Dmsg4(dbglevel, "Prev_jcr: Name=%s JobId=%d Type=%c Level=%c\n", prev_jcr->jr.Name, prev_jcr->jr.JobId, prev_jcr->jr.JobType, prev_jcr->jr.JobLevel); @@ -199,7 +199,7 @@ bool do_migration(JCR *jcr) set_jcr_job_status(jcr, JS_Running); set_jcr_job_status(prev_jcr, JS_Running); - Dmsg2(000, "JobId=%d JobLevel=%c\n", jcr->jr.JobId, jcr->jr.JobLevel); + Dmsg2(dbglevel, "JobId=%d JobLevel=%c\n", jcr->jr.JobId, jcr->jr.JobLevel); /* Update job start record for this migration job */ if (!db_update_job_start_record(jcr, jcr->db, &jcr->jr)) { @@ -207,7 +207,7 @@ bool do_migration(JCR *jcr) return false; } - Dmsg4(000, "Prev_jcr: Name=%s JobId=%d Type=%c Level=%c\n", + Dmsg4(dbglevel, "Prev_jcr: Name=%s JobId=%d Type=%c Level=%c\n", prev_jcr->jr.Name, prev_jcr->jr.JobId, prev_jcr->jr.JobType, prev_jcr->jr.JobLevel); @@ -237,7 +237,7 @@ bool do_migration(JCR *jcr) /* * Now start a job with the Storage daemon */ - Dmsg2(000, "Read store=%s, write store=%s\n", + Dmsg2(dbglevel, "Read store=%s, write store=%s\n", ((STORE *)prev_jcr->storage->first())->hdr.name, ((STORE *)jcr->storage->first())->hdr.name); if (!start_storage_daemon_job(jcr, prev_jcr->storage, jcr->storage)) { @@ -289,7 +289,7 @@ static int dbid_handler(void *ctx, int num_fields, char **row) { idpkt *ids = (idpkt *)ctx; - Dmsg3(000, "count=%d Ids=%p %s\n", ids->count, ids->list, ids->list); + Dmsg3(dbglevel, "count=%d Ids=%p %s\n", ids->count, ids->list, ids->list); if (ids->count == 0) { ids->list[0] = 0; } else { @@ -322,7 +322,7 @@ static int unique_name_handler(void *ctx, int num_fields, char **row) memset(new_item, 0, sizeof(uitem)); new_item->item = bstrdup(row[0]); - Dmsg1(000, "Item=%s\n", row[0]); + Dmsg1(dbglevel, "Item=%s\n", row[0]); item = (uitem *)list->binary_insert((void *)new_item, item_compare); if (item != new_item) { /* already in list */ free(new_item->item); @@ -423,12 +423,12 @@ static bool get_job_to_migrate(JCR *jcr) idpkt ids; ids.list = get_pool_memory(PM_MESSAGE); - Dmsg1(000, "list=%p\n", ids.list); + Dmsg1(dbglevel, "list=%p\n", ids.list); ids.list[0] = 0; ids.count = 0; if (jcr->MigrateJobId != 0) { - Dmsg1(000, "previous jobid=%u\n", jcr->MigrateJobId); + Dmsg1(000, "At Job start previous jobid=%u\n", jcr->MigrateJobId); edit_uint64(jcr->MigrateJobId, ids.list); ids.count = 1; } else { @@ -439,14 +439,12 @@ static bool get_job_to_migrate(JCR *jcr) } break; case MT_CLIENT: - if (!regex_find_jobids(jcr, &ids, sql_client, - sql_jobids_from_client, "Client")) { + if (!regex_find_jobids(jcr, &ids, sql_client, sql_jobids_from_client, "Client")) { goto bail_out; } break; case MT_VOLUME: - if (!regex_find_jobids(jcr, &ids, sql_vol, - sql_jobids_from_vol, "Volume")) { + if (!regex_find_jobids(jcr, &ids, sql_vol, sql_jobids_from_vol, "Volume")) { goto bail_out; } break; @@ -455,7 +453,7 @@ static bool get_job_to_migrate(JCR *jcr) Jmsg(jcr, M_FATAL, 0, _("No Migration SQL selection pattern specified.\n")); goto bail_out; } - Dmsg1(000, "SQL=%s\n", jcr->job->selection_pattern); + Dmsg1(dbglevel, "SQL=%s\n", jcr->job->selection_pattern); if (!db_sql_query(jcr->db, jcr->job->selection_pattern, dbid_handler, (void *)&ids)) { Jmsg(jcr, M_FATAL, 0, @@ -489,12 +487,31 @@ static bool get_job_to_migrate(JCR *jcr) } } + /* + * Loop over all jobids except the last one, sending + * them to start_migration_job(), which will start a job + * for each of them. For the last JobId, we handle it below. + */ p = ids.list; + for (int i=1; i < (int)ids.count; i++) { + JobId = 0; + stat = get_next_jobid_from_list(&p, &JobId); + Dmsg2(000, "get_next_jobid stat=%d JobId=%u\n", stat, JobId); + jcr->MigrateJobId = JobId; + start_migration_job(jcr); + if (stat < 0) { + Jmsg(jcr, M_FATAL, 0, _("Invalid JobId found.\n")); + goto bail_out; + } else if (stat == 0) { + Jmsg(jcr, M_INFO, 0, _("No JobIds found to migrate.\n")); + goto ok_out; + } + } + + /* Now get the last JobId and handle it in the current job */ JobId = 0; stat = get_next_jobid_from_list(&p, &JobId); - Dmsg2(000, "get_next_jobid stat=%d JobId=%u\n", stat, JobId); - jcr->MigrateJobId = JobId; - start_migration_job(jcr); + Dmsg2(000, "Last get_next_jobid stat=%d JobId=%u\n", stat, JobId); if (stat < 0) { Jmsg(jcr, M_FATAL, 0, _("Invalid JobId found.\n")); goto bail_out; @@ -502,9 +519,9 @@ static bool get_job_to_migrate(JCR *jcr) Jmsg(jcr, M_INFO, 0, _("No JobIds found to migrate.\n")); goto ok_out; } - + jcr->previous_jr.JobId = JobId; - Dmsg1(000, "Previous jobid=%d\n", jcr->previous_jr.JobId); + Dmsg1(100, "Previous jobid=%d\n", jcr->previous_jr.JobId); if (!db_get_job_record(jcr, jcr->db, &jcr->previous_jr)) { Jmsg(jcr, M_FATAL, 0, _("Could not get job record for JobId %s to migrate. ERR=%s"), @@ -531,10 +548,10 @@ static void start_migration_job(JCR *jcr) ua->batch = true; Mmsg(ua->cmd, "run %s jobid=%s", jcr->job->hdr.name, edit_uint64(jcr->MigrateJobId, ed1)); - Dmsg1(000, "=============== Migration cmd=%s\n", ua->cmd); + Dmsg1(dbglevel, "=============== Migration cmd=%s\n", ua->cmd); parse_ua_args(ua); /* parse command */ -// int stat = run_cmd(ua, ua->cmd); - int stat = (int)jcr->MigrateJobId; + int stat = run_cmd(ua, ua->cmd); +// int stat = (int)jcr->MigrateJobId; if (stat == 0) { Jmsg(jcr, M_ERROR, 0, _("Could not start migration job.\n")); } else { @@ -561,7 +578,7 @@ static bool regex_find_jobids(JCR *jcr, idpkt *ids, const char *query1, type); goto bail_out; } - Dmsg1(000, "regex=%s\n", jcr->job->selection_pattern); + Dmsg1(dbglevel, "regex=%s\n", jcr->job->selection_pattern); /* Compile regex expression */ rc = regcomp(&preg, jcr->job->selection_pattern, REG_EXTENDED); if (rc != 0) { @@ -572,7 +589,7 @@ static bool regex_find_jobids(JCR *jcr, idpkt *ids, const char *query1, } /* Basic query for names */ Mmsg(query, query1, jcr->pool->hdr.name); - Dmsg1(000, "query1=%s\n", query.c_str()); + Dmsg1(dbglevel, "query1=%s\n", query.c_str()); if (!db_sql_query(jcr->db, query.c_str(), unique_name_handler, (void *)item_chain)) { Jmsg(jcr, M_FATAL, 0, @@ -584,11 +601,11 @@ static bool regex_find_jobids(JCR *jcr, idpkt *ids, const char *query1, const int nmatch = 30; regmatch_t pmatch[nmatch]; if (last_item) { - Dmsg1(000, "Remove item %s\n", last_item->item); + Dmsg1(dbglevel, "Remove item %s\n", last_item->item); free(last_item->item); item_chain->remove(last_item); } - Dmsg1(000, "Jobitem=%s\n", item->item); + Dmsg1(dbglevel, "Item=%s\n", item->item); rc = regexec(&preg, item->item, nmatch, pmatch, 0); if (rc == 0) { last_item = NULL; /* keep this one */ @@ -598,7 +615,7 @@ static bool regex_find_jobids(JCR *jcr, idpkt *ids, const char *query1, } if (last_item) { free(last_item->item); - Dmsg1(000, "Remove item %s\n", last_item->item); + Dmsg1(dbglevel, "Remove item %s\n", last_item->item); item_chain->remove(last_item); } regfree(&preg); @@ -609,9 +626,9 @@ static bool regex_find_jobids(JCR *jcr, idpkt *ids, const char *query1, */ ids->count = 0; foreach_dlist(item, item_chain) { - Dmsg1(000, "Got Job: %s\n", item->item); + Dmsg2(dbglevel, "Got %s: %s\n", type, item->item); Mmsg(query, query2, item->item, jcr->pool->hdr.name); - Dmsg1(000, "query2=%s\n", query.c_str()); + Dmsg1(dbglevel, "query2=%s\n", query.c_str()); if (!db_sql_query(jcr->db, query.c_str(), dbid_handler, (void *)ids)) { Jmsg(jcr, M_FATAL, 0, _("SQL failed. ERR=%s\n"), db_strerror(jcr->db)); @@ -623,9 +640,9 @@ static bool regex_find_jobids(JCR *jcr, idpkt *ids, const char *query1, } ok = true; bail_out: - Dmsg2(000, "Count=%d Jobids=%s\n", ids->count, ids->list); + Dmsg2(dbglevel, "Count=%d Jobids=%s\n", ids->count, ids->list); delete item_chain; - Dmsg0(000, "After delete item_chain\n"); + Dmsg0(dbglevel, "After delete item_chain\n"); return ok; } diff --git a/bacula/src/dird/protos.h b/bacula/src/dird/protos.h index 0658a0767c..da56c4701c 100644 --- a/bacula/src/dird/protos.h +++ b/bacula/src/dird/protos.h @@ -175,6 +175,7 @@ RUN *find_next_run(RUN *run, JOB *job, time_t &runtime, int ndays); /* ua_restore.c */ int get_next_jobid_from_list(char **p, JobId_t *JobId); +void find_storage_resource(UAContext *ua, RESTORE_CTX &rx, char *Storage, char *MediaType); /* ua_server.c */ void bsendmsg(void *sock, const char *fmt, ...); diff --git a/bacula/src/dird/ua_restore.c b/bacula/src/dird/ua_restore.c index 78889be8ff..f93bc7a342 100644 --- a/bacula/src/dird/ua_restore.c +++ b/bacula/src/dird/ua_restore.c @@ -53,10 +53,7 @@ static int last_full_handler(void *ctx, int num_fields, char **row); static int jobid_handler(void *ctx, int num_fields, char **row); static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx); static int fileset_handler(void *ctx, int num_fields, char **row); -static void print_name_list(UAContext *ua, NAME_LIST *name_list); -static int unique_name_list_handler(void *ctx, int num_fields, char **row); static void free_name_list(NAME_LIST *name_list); -static void get_storage_from_mediatype(UAContext *ua, NAME_LIST *name_list, RESTORE_CTX *rx); static bool select_backups_before_date(UAContext *ua, RESTORE_CTX *rx, char *date); static bool build_directory_tree(UAContext *ua, RESTORE_CTX *rx); static void free_rx(RESTORE_CTX *rx); @@ -370,12 +367,7 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) } pm_strcpy(ua->cmd, ua->argv[i]); insert_one_file_or_dir(ua, rx, date, j==4); - if (rx->name_list.num_ids) { - /* Check MediaType and select storage that corresponds */ - get_storage_from_mediatype(ua, &rx->name_list, rx); - done = true; - } - break; + return 2; case 5: /* select */ if (!have_date) { bstrutime(date, sizeof(date), time(NULL)); @@ -410,9 +402,6 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) break; } } - if (rx->name_list.num_ids) { - return 2; /* filename list made */ - } if (!done) { bsendmsg(ua, _("\nFirst you select one or more JobIds that contain files\n" @@ -508,10 +497,6 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) } insert_one_file_or_dir(ua, rx, date, false); } - /* Check MediaType and select storage that corresponds */ - if (rx->name_list.num_ids) { - get_storage_from_mediatype(ua, &rx->name_list, rx); - } return 2; case 7: /* enter files backed up before specified time */ if (!get_date(ua, date, sizeof(date))) { @@ -533,10 +518,6 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) } insert_one_file_or_dir(ua, rx, date, false); } - /* Check MediaType and select storage that corresponds */ - if (rx->name_list.num_ids) { - get_storage_from_mediatype(ua, &rx->name_list, rx); - } return 2; case 8: /* Find JobIds for current backup */ @@ -591,10 +572,6 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) } insert_one_file_or_dir(ua, rx, date, true); } - /* Check MediaType and select storage that corresponds */ - if (rx->name_list.num_ids) { - get_storage_from_mediatype(ua, &rx->name_list, rx); - } return 2; case 11: /* Cancel or quit */ @@ -720,8 +697,6 @@ static void insert_one_file_or_dir(UAContext *ua, RESTORE_CTX *rx, char *date, b static bool insert_file_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *file, char *date) { - char ed1[50]; - strip_trailing_newline(file); split_path_and_filename(rx, file); if (*rx->JobIds == 0) { @@ -741,14 +716,6 @@ static bool insert_file_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *f bsendmsg(ua, _("No database record found for: %s\n"), file); return true; } - /* - * Find the MediaTypes for this JobId and add to the name_list - */ - Mmsg(rx->query, uar_mediatype, edit_int64(rx->JobId, ed1)); - if (!db_sql_query(ua->db, rx->query, unique_name_list_handler, (void *)&rx->name_list)) { - bsendmsg(ua, "%s", db_strerror(ua->db)); - return false; - } return true; } @@ -759,8 +726,6 @@ static bool insert_file_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *f static bool insert_dir_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *dir, char *date) { - char ed1[50]; - strip_trailing_junk(dir); if (*rx->JobIds == 0) { bsendmsg(ua, _("No JobId specified cannot continue.\n")); @@ -779,14 +744,6 @@ static bool insert_dir_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *di bsendmsg(ua, _("No database record found for: %s\n"), dir); return true; } - /* - * Find the MediaTypes for this JobId and add to the name_list - */ - Mmsg(rx->query, uar_mediatype, edit_int64(rx->JobId, ed1)); - if (!db_sql_query(ua->db, rx->query, unique_name_list_handler, (void *)&rx->name_list)) { - bsendmsg(ua, "%s", db_strerror(ua->db)); - return false; - } return true; } @@ -795,8 +752,6 @@ static bool insert_dir_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *di */ static bool insert_table_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *table) { - char ed1[50]; - strip_trailing_junk(table); Mmsg(rx->query, uar_jobid_fileindex_from_table, table); @@ -810,14 +765,6 @@ static bool insert_table_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char * bsendmsg(ua, _("No table found: %s\n"), table); return true; } - /* - * Find the MediaTypes for this JobId and add to the name_list - */ - Mmsg(rx->query, uar_mediatype, edit_int64(rx->JobId, ed1)); - if (!db_sql_query(ua->db, rx->query, unique_name_list_handler, (void *)&rx->name_list)) { - bsendmsg(ua, "%s", db_strerror(ua->db)); - return false; - } return true; } @@ -922,13 +869,6 @@ static bool build_directory_tree(UAContext *ua, RESTORE_CTX *rx) if (!db_sql_query(ua->db, rx->query, insert_tree_handler, (void *)&tree)) { bsendmsg(ua, "%s", db_strerror(ua->db)); } - /* - * Find the MediaTypes for this JobId and add to the name_list - */ - Mmsg(rx->query, uar_mediatype, edit_int64(JobId, ed1)); - if (!db_sql_query(ua->db, rx->query, unique_name_list_handler, (void *)&rx->name_list)) { - bsendmsg(ua, "%s", db_strerror(ua->db)); - } } if (tree.FileCount == 0) { bsendmsg(ua, _("\nThere were no files inserted into the tree, so file selection\n" @@ -968,9 +908,6 @@ static bool build_directory_tree(UAContext *ua, RESTORE_CTX *rx) } } - /* Check MediaType and select storage that corresponds */ - get_storage_from_mediatype(ua, &rx->name_list, rx); - if (find_arg(ua, NT_("done")) < 0) { /* Let the user interact in selecting which files to restore */ OK = user_select_files_from_tree(&tree); @@ -1248,11 +1185,12 @@ static int fileset_handler(void *ctx, int num_fields, char **row) return 0; } +#ifdef xxxx_needed /* * Called here with each name to be added to the list. The name is * added to the list if it is not already in the list. * - * Used to make unique list of FileSets and MediaTypes + * Used to make unique list of FileSets */ static int unique_name_list_handler(void *ctx, int num_fields, char **row) { @@ -1290,6 +1228,7 @@ static void print_name_list(UAContext *ua, NAME_LIST *name_list) bsendmsg(ua, "%s\n", name_list->name[i]); } } +#endif /* @@ -1308,15 +1247,80 @@ static void free_name_list(NAME_LIST *name_list) name_list->num_ids = 0; } +void find_storage_resource(UAContext *ua, RESTORE_CTX &rx, char *Storage, char *MediaType) +{ + STORE *store; + + if (rx.store) { + return; + } + /* + * Try looking up Storage by name + */ + LockRes(); + foreach_res(store, R_STORAGE) { + if (strcmp(Storage, store->hdr.name) == 0) { + if (acl_access_ok(ua, Storage_ACL, store->hdr.name)) { + rx.store = store; + } + break; + } + } + UnlockRes(); + + if (rx.store) { + /* Check if an explicit storage resource is given */ + store = NULL; + int i = find_arg_with_value(ua, "storage"); + if (i > 0) { + store = (STORE *)GetResWithName(R_STORAGE, ua->argv[i]); + if (store && !acl_access_ok(ua, Storage_ACL, store->hdr.name)) { + store = NULL; + } + } + if (store && (store != rx.store)) { + bsendmsg(ua, _("Warning default storage overridden by \"%s\" on command line.\n"), + store->hdr.name); + rx.store = store; + } + return; + } + + /* If no storage resource, try to find one from MediaType */ + if (!rx.store) { + LockRes(); + foreach_res(store, R_STORAGE) { + if (strcmp(MediaType, store->media_type) == 0) { + if (acl_access_ok(ua, Storage_ACL, store->hdr.name)) { + rx.store = store; + bsendmsg(ua, _("Storage \"%s\" not found, using Storage \"%s\" from MediaType \"%s\".\n"), + Storage, store->hdr.name, MediaType); + } + UnlockRes(); + return; + } + } + UnlockRes(); + bsendmsg(ua, _("\nUnable to find Storage resource for\n" + "MediaType \"%s\", needed by the Jobs you selected.\n"), MediaType); + } + + /* Take command line arg, or ask user if none */ + rx.store = get_storage_resource(ua, false /* don't use default */); + +} + + +#ifdef xxxx_needed static void get_storage_from_mediatype(UAContext *ua, NAME_LIST *name_list, RESTORE_CTX *rx) { STORE *store; if (name_list->num_ids > 1) { bsendmsg(ua, _("Warning, the JobIds that you selected refer to more than one MediaType.\n" - "Restore is not possible. The MediaTypes used are:\n")); + "Restore may not be possible. The MediaTypes used are:\n")); print_name_list(ua, name_list); - rx->store = select_storage_resource(ua); +// rx->store = select_storage_resource(ua); return; } @@ -1370,3 +1374,4 @@ static void get_storage_from_mediatype(UAContext *ua, NAME_LIST *name_list, REST name_list->name[0]); } } +#endif diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index 9768fe2e30..367a3ca8cb 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -993,6 +993,9 @@ static void free_bootstrap(JCR *jcr) } +static pthread_mutex_t bsr_mutex = PTHREAD_MUTEX_INITIALIZER; +static uint32_t bsr_uniq = 0; + /* * The Director sends us the bootstrap file, which * we will in turn pass to the SD. @@ -1004,8 +1007,11 @@ static int bootstrap_cmd(JCR *jcr) FILE *bs; free_bootstrap(jcr); - Mmsg(fname, "%s/%s.%s.bootstrap", me->working_directory, me->hdr.name, - jcr->Job); + P(bsr_mutex); + bsr_uniq++; + Mmsg(fname, "%s/%s.%s.%d.bootstrap", me->working_directory, me->hdr.name, + jcr->Job, bsr_uniq); + V(bsr_mutex); Dmsg1(400, "bootstrap=%s\n", fname); jcr->RestoreBootstrap = fname; bs = fopen(fname, "a+b"); /* create file */ diff --git a/bacula/src/lib/.cvsignore b/bacula/src/lib/.cvsignore index ee20fd266e..a961abbf51 100644 --- a/bacula/src/lib/.cvsignore +++ b/bacula/src/lib/.cvsignore @@ -1,3 +1,4 @@ +bsnprintf save 1 Makefile diff --git a/bacula/src/lib/Makefile.in b/bacula/src/lib/Makefile.in index e4364eb66e..6225e71eca 100644 --- a/bacula/src/lib/Makefile.in +++ b/bacula/src/lib/Makefile.in @@ -24,7 +24,7 @@ dummy: LIBSRCS = alloc.c attr.c base64.c berrno.c bsys.c bget_msg.c \ bnet.c bnet_server.c runscript.c \ - bpipe.c bshm.c bsnprintf.c btime.c \ + bpipe.c bsnprintf.c btime.c \ cram-md5.c crc32.c crypto.c daemon.c edit.c fnmatch.c \ hmac.c idcache.c jcr.c lex.c alist.c dlist.c \ md5.c message.c mem_pool.c openssl.c parse_conf.c \ @@ -37,7 +37,7 @@ LIBSRCS = alloc.c attr.c base64.c berrno.c bsys.c bget_msg.c \ LIBOBJS = alloc.o attr.o base64.o berrno.o bsys.o bget_msg.o \ bnet.o bnet_server.o runscript.o \ - bpipe.o bshm.o bsnprintf.o btime.o \ + bpipe.o bsnprintf.o btime.o \ cram-md5.o crc32.o crypto.o daemon.o edit.o fnmatch.o \ hmac.o idcache.o jcr.o lex.o alist.o dlist.o \ md5.o message.o mem_pool.o openssl.o parse_conf.o \ diff --git a/bacula/src/lib/address_conf.h b/bacula/src/lib/address_conf.h index 9ded23ec5b..64842aeb5d 100644 --- a/bacula/src/lib/address_conf.h +++ b/bacula/src/lib/address_conf.h @@ -1,31 +1,24 @@ /* * - * Written by Meno Abels, June MMIIII + * Written by Meno Abels, June MMIV * * Version $Id$ */ - /* - Copyright (C) 2004-2005 Kern Sibbald + Copyright (C) 2004-2006 Kern Sibbald This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. + modify it under the terms of the GNU General Public License + version 2 as amended with additional clauses defined in the + file LICENSE in the main source directory. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + the file LICENSE for additional details. */ - class IPADDR : public SMARTALLOC { public: typedef enum { R_SINGLE, R_SINGLE_PORT, R_SINGLE_ADDR, R_MULTIPLE, diff --git a/bacula/src/lib/attr.h b/bacula/src/lib/attr.h index b393b49236..b510017a6f 100644 --- a/bacula/src/lib/attr.h +++ b/bacula/src/lib/attr.h @@ -5,27 +5,22 @@ * * Version $Id$ */ - /* - Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker + Copyright (C) 2003-2006 Kern Sibbald This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. + modify it under the terms of the GNU General Public License + version 2 as amended with additional clauses defined in the + file LICENSE in the main source directory. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + the file LICENSE for additional details. */ + struct ATTR { int32_t stream; /* attribute stream id */ int32_t data_stream; /* id of data stream to follow */ diff --git a/bacula/src/lib/bshm.c b/bacula/src/lib/bshm.c deleted file mode 100644 index 7849266e39..0000000000 --- a/bacula/src/lib/bshm.c +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Bacula shared memory routines - * - * To avoid problems with several return arguments, we - * pass a packet. - * - * BSHM definition is in bshm.h - * - * By Kern Sibbald, May MM - * - * Version $Id$ - * - * Note, this routine was originally written so that the DEVICE structures - * could be shared between the child processes. Now that the Storage - * daemon is threaded, these routines are no longer needed. Rather than - * rewrite all the code, I simply #ifdef it on NEED_SHARED_MEMORY, and - * when not defined, I simply malloc() a buffer, which is, of course, - * available to all the threads. - * - */ -/* - Copyright (C) 2000-2006 Kern Sibbald - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - version 2 as amended with additional clauses defined in the - file LICENSE in the main source directory. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - the file LICENSE for additional details. - - */ - - -#ifdef implemented - -#include "bacula.h" - -#if !defined(HAVE_WIN32) - -#ifdef NEED_SHARED_MEMORY -#define SHM_KEY 0x0BACB01 /* key for shared memory */ -static key_t shmkey = SHM_KEY; -#define MAX_TRIES 1000 - -#else /* threaded model */ -/* Multiple thread protection */ -static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; -#endif - - -/* Create shared memory segment defined by BSHM */ -void shm_create(BSHM *shm) -{ -#ifdef NEED_SHARED_MEMORY - int shmid, i; - int not_found = TRUE; - - Dmsg1(110, "shm_create size=%d\n", shm->size); - for (i=0; isize, shm->perms | IPC_CREAT)) < 0) { - Emsg1(M_WARN, 0, _("shmget failure key = %x\n"), shmkey); - shmkey++; - continue; - } - not_found = FALSE; - break; - } - if (not_found) - Emsg2(M_ABORT, 0, _("Could not get %d bytes of shared memory: %s\n"), shm->size, strerror(errno)); - shm->shmkey = shmkey; - shm->shmid = shmid; - Dmsg2(110, "shm_create return key=%x id=%d\n", shmkey, shmid); - shmkey++; /* leave set for next time */ -#else - shm->shmbuf = NULL; - shm->shmkey = 0; /* reference count */ -#endif -} - -/* Attach to shared memory segement defined in BSHM */ -void *shm_open(BSHM *shm) -{ -#ifdef NEED_SHARED_MEMORY - int shmid; - char *shmbuf; - - Dmsg2(110, "shm_open key=%x size=%d\n", shm->shmkey, shm->size); - if ((shmid = shmget(shm->shmkey, shm->size, 0)) < 0) - Emsg2(M_ABORT, 0, "Could not get %d bytes of shared memory: %s\n", shm->size, strerror(errno)); - Dmsg1(110, "shm_open shmat with id=%d\n", shmid); - shmbuf = shmat(shmid, NULL, 0); - Dmsg1(110, "shm_open buf=%x\n", shmbuf); - if (shmbuf == (char *) -1) - Emsg1(M_ABORT, 0, _("Could not attach shared memory: %s\n"), strerror(errno)); - shm->shmbuf = shmbuf; - shm->shmid = shmid; - return shmbuf; -#else - P(mutex); - if (!shm->shmbuf) { - shm->shmbuf = bmalloc(shm->size); - } - shm->shmkey++; /* reference count */ - V(mutex); - return shm->shmbuf; -#endif -} - -/* Detach from shared memory segement */ -void shm_close(BSHM *shm) -{ -#ifdef NEED_SHARED_MEMORY - if (shm->size) { - if (shmdt(shm->shmbuf) < 0) { - Emsg1(M_ERROR, 0, _("Error detaching shared memory: %s\n"), strerror(errno)); - } - } -#else - P(mutex); - shm->shmkey--; /* reference count */ - V(mutex); -#endif -} - -/* Destroy the shared memory segment */ -void shm_destroy(BSHM *shm) -{ -#ifdef NEED_SHARED_MEMORY - if (shm->size) { - if (shmctl(shm->shmid, IPC_RMID, NULL) < 0) { - Emsg1(M_ERROR, 0, _("Could not destroy shared memory: %s\n"), strerror(errno)); - } - } -#else - /* We really should check that the ref count is zero */ - P(mutex); - if (shm->shmbuf) { - free(shm->shmbuf); - shm->shmbuf = NULL; - } - V(mutex); -#endif -} - -#endif /* ! HAVE_WIN32 */ - -#endif diff --git a/bacula/src/lib/bshm.h b/bacula/src/lib/bshm.h deleted file mode 100644 index 15e913ec22..0000000000 --- a/bacula/src/lib/bshm.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Bacula Shared Memory structure - * - * Kern Sibbald, May MM - * - * NB: these items are deprecated. Shared memory was - * used in a first version of the Storage daemon - * when it forked. Since then it has been converted - * to use threads. However, there are still some - * vestiges of the shared memory code that remain and - * can be removed. - * - * Version $Id$ - */ -/* - Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA. - - */ - -typedef struct s_bshm { - int size; /* length desired */ - int perms; /* permissions desired */ - - int shmid; /* id set by shm_create and shm_open */ - key_t shmkey; /* key set by shm_create */ - void *shmbuf; /* set by shm_open */ -} BSHM; diff --git a/bacula/src/lib/bsys.c b/bacula/src/lib/bsys.c index 26a9b72cae..86b437f073 100644 --- a/bacula/src/lib/bsys.c +++ b/bacula/src/lib/bsys.c @@ -615,38 +615,65 @@ bail_out: /* * Drop to privilege new userid and new gid if non-NULL */ -void drop(char *uid, char *gid) +void drop(char *uname, char *gname) { -#ifdef HAVE_GRP_H - if (gid) { - struct group *group; - gid_t gr_list[1]; +#if defined(HAVE_PWD_H) && defined(HAVE_GRP_H) + struct passwd *passw = NULL; + struct group *group = NULL; + gid_t gid; + + Dmsg2(900, "uname=%s gname=%s\n", uname?uname:"NONE", gname?gname:"NONE"); + if (!uname && !gname) { + return; /* Nothing to do */ + } - if ((group = getgrnam(gid)) == NULL) { - Emsg1(M_ERROR_TERM, 0, _("Could not find specified group: %s\n"), gid); + if (uname) { + if ((passw = getpwnam(uname)) == NULL) { + berrno be; + Emsg2(M_ERROR_TERM, 0, _("Could not find userid=%s: ERR=%s\n"), uname, + be.strerror()); } - if (setgid(group->gr_gid)) { - Emsg1(M_ERROR_TERM, 0, _("Could not set specified group: %s\n"), gid); + } else { + if ((passw = getpwuid(getuid())) == NULL) { + berrno be; + Emsg1(M_ERROR_TERM, 0, _("Could not find password entry. ERR=%s\n"), + be.strerror()); + } else { + uname = passw->pw_name; } - gr_list[0] = group->gr_gid; - if (setgroups(1, gr_list)) { - Emsg1(M_ERROR_TERM, 0, _("Could not set specified group: %s\n"), gid); + } + if (gname) { + if ((group = getgrnam(gname)) == NULL) { + berrno be; + Emsg2(M_ERROR_TERM, 0, _("Could not find group=%s: ERR=%s\n"), gname, + be.strerror()); } + gid = group->gr_gid; + } else { + gid = passw->pw_gid; } -#endif - -#ifdef HAVE_PWD_H - if (uid) { - struct passwd *passw; - if ((passw = getpwnam(uid)) == NULL) { - Emsg1(M_ERROR_TERM, 0, _("Could not find specified userid: %s\n"), uid); + if (initgroups(passw->pw_name, passw->pw_gid)) { + berrno be; + if (gname) { + Emsg3(M_ERROR_TERM, 0, _("Could not initgroups for group=%s, userid=%s: ERR=%s\n"), + gname, uname, be.strerror()); + } else { + Emsg2(M_ERROR_TERM, 0, _("Could not initgroups for userid=%s: ERR=%s\n"), + uname, be.strerror()); } - if (setuid(passw->pw_uid)) { - Emsg1(M_ERROR_TERM, 0, _("Could not set specified userid: %s\n"), uid); + } + if (gname) { + if (setgid(group->gr_gid)) { + berrno be; + Emsg2(M_ERROR_TERM, 0, _("Could not set group=%s: ERR=%s\n"), gname, + be.strerror()); } } + if (setuid(passw->pw_uid)) { + berrno be; + Emsg1(M_ERROR_TERM, 0, _("Could not set specified userid: %s\n"), uname); + } #endif - } diff --git a/bacula/src/lib/btime.h b/bacula/src/lib/btime.h index 60d49fe1ca..7158e1b85c 100644 --- a/bacula/src/lib/btime.h +++ b/bacula/src/lib/btime.h @@ -6,24 +6,18 @@ Version $Id$ */ - /* - Copyright (C) 2000-2004 Kern Sibbald and John Walker + Copyright (C) 2000-2006 Kern Sibbald This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. + modify it under the terms of the GNU General Public License + version 2 as amended with additional clauses defined in the + file LICENSE in the main source directory. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + the file LICENSE for additional details. */ @@ -48,47 +42,47 @@ utime_t str_to_utime(char *str); /* =========================================================== */ -/* old code deprecated below. Do not use. */ +/* old code deprecated below. Do not use. */ -typedef float64_t fdate_t; /* Date type */ -typedef float64_t ftime_t; /* Time type */ +typedef float64_t fdate_t; /* Date type */ +typedef float64_t ftime_t; /* Time type */ struct date_time { - fdate_t julian_day_number; /* Julian day number */ + fdate_t julian_day_number; /* Julian day number */ ftime_t julian_day_fraction; /* Julian day fraction */ }; /* In arguments and results of the following functions, quantities are expressed as follows. - year Year in the Common Era. The canonical - date of adoption of the Gregorian calendar - (October 5, 1582 in the Julian calendar) - is assumed. + year Year in the Common Era. The canonical + date of adoption of the Gregorian calendar + (October 5, 1582 in the Julian calendar) + is assumed. - month Month index with January 0, December 11. + month Month index with January 0, December 11. - day Day number of month, 1 to 31. + day Day number of month, 1 to 31. */ extern fdate_t date_encode(uint32_t year, uint8_t month, uint8_t day); extern ftime_t time_encode(uint8_t hour, uint8_t minute, uint8_t second, - float32_t second_fraction); + float32_t second_fraction); extern void date_time_encode(struct date_time *dt, - uint32_t year, uint8_t month, uint8_t day, - uint8_t hour, uint8_t minute, uint8_t second, - float32_t second_fraction); + uint32_t year, uint8_t month, uint8_t day, + uint8_t hour, uint8_t minute, uint8_t second, + float32_t second_fraction); extern void date_decode(fdate_t date, uint32_t *year, uint8_t *month, - uint8_t *day); + uint8_t *day); extern void time_decode(ftime_t time, uint8_t *hour, uint8_t *minute, - uint8_t *second, float32_t *second_fraction); + uint8_t *second, float32_t *second_fraction); extern void date_time_decode(struct date_time *dt, - uint32_t *year, uint8_t *month, uint8_t *day, - uint8_t *hour, uint8_t *minute, uint8_t *second, - float32_t *second_fraction); + uint32_t *year, uint8_t *month, uint8_t *day, + uint8_t *hour, uint8_t *minute, uint8_t *second, + float32_t *second_fraction); extern int date_time_compare(struct date_time *dt1, struct date_time *dt2); diff --git a/bacula/src/lib/btree.h b/bacula/src/lib/btree.h index df25085341..e3f8c946d9 100644 --- a/bacula/src/lib/btree.h +++ b/bacula/src/lib/btree.h @@ -2,7 +2,7 @@ * Version $Id$ */ /* - Copyright (C) 2005 Kern Sibbald + Copyright (C) 2005-2006 Kern Sibbald This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/bacula/src/lib/lib.h b/bacula/src/lib/lib.h index 9f86b25a83..73c23e8857 100644 --- a/bacula/src/lib/lib.h +++ b/bacula/src/lib/lib.h @@ -41,7 +41,6 @@ #include "parse_conf.h" #include "tls.h" #include "bsock.h" -#include "bshm.h" #include "workq.h" #ifndef HAVE_FNMATCH #include "fnmatch.h" diff --git a/bacula/src/lib/md5.h b/bacula/src/lib/md5.h index f97e00d403..2ee8a8f5ab 100644 --- a/bacula/src/lib/md5.h +++ b/bacula/src/lib/md5.h @@ -6,22 +6,17 @@ * Version $Id$ */ /* - Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker + Copyright (C) 2001-2006 Kern Sibbald - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + version 2 as amended with additional clauses defined in the + file LICENSE in the main source directory. - This library is distributed in the hope that it will be useful, + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, - MA 02111-1307, USA. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + the file LICENSE for additional details. */ diff --git a/bacula/src/lib/message.h b/bacula/src/lib/message.h index 7f73169d68..a9a6152229 100644 --- a/bacula/src/lib/message.h +++ b/bacula/src/lib/message.h @@ -5,22 +5,17 @@ * Version $Id$ */ /* - Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker + Copyright (C) 2000-2006 Kern Sibbald This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. + modify it under the terms of the GNU General Public License + version 2 as amended with additional clauses defined in the + file LICENSE in the main source directory. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + the file LICENSE for additional details. */ @@ -105,16 +100,18 @@ typedef struct s_dest { } DEST; /* Message Destination values for dest field of DEST */ -#define MD_SYSLOG 1 /* send msg to syslog */ -#define MD_MAIL 2 /* email group of messages */ -#define MD_FILE 3 /* write messages to a file */ -#define MD_APPEND 4 /* append messages to a file */ -#define MD_STDOUT 5 /* print messages */ -#define MD_STDERR 6 /* print messages to stderr */ -#define MD_DIRECTOR 7 /* send message to the Director */ -#define MD_OPERATOR 8 /* email a single message to the operator */ -#define MD_CONSOLE 9 /* send msg to UserAgent or console */ -#define MD_MAIL_ON_ERROR 10 /* email messages if job errors */ +enum { + MD_SYSLOG = 1, /* send msg to syslog */ + MD_MAIL, /* email group of messages */ + MD_FILE, /* write messages to a file */ + MD_APPEND, /* append messages to a file */ + MD_STDOUT, /* print messages */ + MD_STDERR, /* print messages to stderr */ + MD_DIRECTOR, /* send message to the Director */ + MD_OPERATOR, /* email a single message to the operator */ + MD_CONSOLE, /* send msg to UserAgent or console */ + MD_MAIL_ON_ERROR /* email messages if job errors */ +}; /* Queued message item */ struct MQUEUE_ITEM { diff --git a/bacula/src/lib/openssl.h b/bacula/src/lib/openssl.h index 7654e177cf..4ec6ea020d 100644 --- a/bacula/src/lib/openssl.h +++ b/bacula/src/lib/openssl.h @@ -19,7 +19,7 @@ * license please contact Landon Fuller . */ /* - Copyright (C) 2005 Kern Sibbald + Copyright (C) 2005-2006 Kern Sibbald This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/bacula/src/lib/queue.h b/bacula/src/lib/queue.h index c6cbe1080d..91f0713e7c 100644 --- a/bacula/src/lib/queue.h +++ b/bacula/src/lib/queue.h @@ -1,42 +1,34 @@ /* * Version $Id$ */ - - /* - Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker + Copyright (C) 2000-2006 Kern Sibbald This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. + modify it under the terms of the GNU General Public License + version 2 as amended with additional clauses defined in the + file LICENSE in the main source directory. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + the file LICENSE for additional details. */ - /* General purpose queue */ struct b_queue { - struct b_queue *qnext, /* Next item in queue */ - *qprev; /* Previous item in queue */ + struct b_queue *qnext, /* Next item in queue */ + *qprev; /* Previous item in queue */ }; typedef struct b_queue BQUEUE; /* Queue functions */ -void qinsert(BQUEUE *qhead, BQUEUE *object); +void qinsert(BQUEUE *qhead, BQUEUE *object); BQUEUE *qnext(BQUEUE *qhead, BQUEUE *qitem); BQUEUE *qdchain(BQUEUE *qitem); BQUEUE *qremove(BQUEUE *qhead); diff --git a/bacula/src/lib/runscript.h b/bacula/src/lib/runscript.h index 85538059d8..f50feb9699 100644 --- a/bacula/src/lib/runscript.h +++ b/bacula/src/lib/runscript.h @@ -4,7 +4,7 @@ * Version $Id$ */ /* - Copyright (C) 2000-2006 Kern Sibbald + Copyright (C) 2006-2006 Kern Sibbald This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/bacula/src/lib/semlock.h b/bacula/src/lib/semlock.h index 6051341dcd..d03904dac8 100644 --- a/bacula/src/lib/semlock.h +++ b/bacula/src/lib/semlock.h @@ -12,22 +12,17 @@ * Version $Id$ */ /* - Copyright (C) 2000-2003 Kern Sibbald and John Walker + Copyright (C) 2000-2006 Kern Sibbald This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. + modify it under the terms of the GNU General Public License + version 2 as amended with additional clauses defined in the + file LICENSE in the main source directory. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + the file LICENSE for additional details. */ diff --git a/bacula/src/lib/serial.h b/bacula/src/lib/serial.h index 528819739e..e3e0013910 100644 --- a/bacula/src/lib/serial.h +++ b/bacula/src/lib/serial.h @@ -2,27 +2,22 @@ * * Version $Id$ */ - /* - Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker + Copyright (C) 2000-2006 Kern Sibbald This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. + modify it under the terms of the GNU General Public License + version 2 as amended with additional clauses defined in the + file LICENSE in the main source directory. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + the file LICENSE for additional details. */ + /* Serialisation support functions from serial.c. */ extern void serial_int16(uint8_t * * const ptr, const int16_t v); @@ -47,7 +42,7 @@ extern void unserial_string(uint8_t * * const ptr, char * const str); /* - Serialisation Macros + Serialisation Macros These macros use a uint8_t pointer, ser_ptr, which must be defined by the code which uses them. @@ -66,7 +61,7 @@ extern void unserial_string(uint8_t * * const ptr, char * const str); #define unser_begin(x, s) ser_ptr = ((uint8_t *)(x)) /* ser_length -- Determine length in bytes of serialised into a - buffer x. */ + buffer x. */ #define ser_length(x) (ser_ptr - (uint8_t *)(x)) #define unser_length(x) (ser_ptr - (uint8_t *)(x)) @@ -75,7 +70,7 @@ extern void unserial_string(uint8_t * * const ptr, char * const str); #define unser_end(x, s) ASSERT(ser_length(x) <= (s)) /* ser_check(x, s) -- Verify length of serialised data in buffer x is - expected length s. */ + expected length s. */ #define ser_check(x, s) ASSERT(ser_length(x) == (s)) /* Serialisation */ diff --git a/bacula/src/lib/smartall.h b/bacula/src/lib/smartall.h index 1ddd3cacff..439f990ea1 100644 --- a/bacula/src/lib/smartall.h +++ b/bacula/src/lib/smartall.h @@ -7,7 +7,7 @@ */ /* - Copyright (C) 2000-2005 Kern Sibbald + Copyright (C) 2000-2006 Kern Sibbald This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/bacula/src/lib/var.h b/bacula/src/lib/var.h index 45da4b00ac..e79c84b705 100644 --- a/bacula/src/lib/var.h +++ b/bacula/src/lib/var.h @@ -18,22 +18,17 @@ * Modified for use with Bacula by Kern Sibbald, June 2003 */ /* - Copyright (C) 2000-2003 Kern Sibbald and John Walker + Copyright (C) 2003-2006 Kern Sibbald This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. + modify it under the terms of the GNU General Public License + version 2 as amended with additional clauses defined in the + file LICENSE in the main source directory. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + the file LICENSE for additional details. */ diff --git a/bacula/src/lib/waitq.h b/bacula/src/lib/waitq.h index ec0c8d8560..3225fee23d 100644 --- a/bacula/src/lib/waitq.h +++ b/bacula/src/lib/waitq.h @@ -11,22 +11,17 @@ * */ /* - Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker + Copyright (C) 2001-2006 Kern Sibbald This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. + modify it under the terms of the GNU General Public License + version 2 as amended with additional clauses defined in the + file LICENSE in the main source directory. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + the file LICENSE for additional details. */ @@ -38,20 +33,20 @@ */ typedef struct waitq_ele_tag { struct waitq_ele_tag *next; - int done_flag; /* predicate for wait */ - pthread_cont_t done; /* wait for completion */ - void *msg; /* message to be passed */ + int done_flag; /* predicate for wait */ + pthread_cont_t done; /* wait for completion */ + void *msg; /* message to be passed */ } waitq_ele_t; /* * Structure describing a wait queue */ typedef struct workq_tag { - pthread_mutex_t mutex; /* queue access control */ - pthread_cond_t wait_req; /* wait for OK */ - int num_msgs; /* number of waiters */ - waitq_ele_t *first; /* wait queue first item */ - waitq_ele_t *last; /* wait queue last item */ + pthread_mutex_t mutex; /* queue access control */ + pthread_cond_t wait_req; /* wait for OK */ + int num_msgs; /* number of waiters */ + waitq_ele_t *first; /* wait queue first item */ + waitq_ele_t *last; /* wait queue last item */ } workq_t; extern int waitq_init(waitq_t *wq); diff --git a/bacula/src/lib/watchdog.h b/bacula/src/lib/watchdog.h index 8763928e0b..3c47ab9124 100644 --- a/bacula/src/lib/watchdog.h +++ b/bacula/src/lib/watchdog.h @@ -5,22 +5,17 @@ * */ /* - Copyright (C) 2002-2004 Kern Sibbald and John Walker + Copyright (C) 2002-2006 Kern Sibbald This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. + modify it under the terms of the GNU General Public License + version 2 as amended with additional clauses defined in the + file LICENSE in the main source directory. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + the file LICENSE for additional details. */ @@ -33,14 +28,14 @@ enum { #define TIMEOUT_SIGNAL SIGUSR2 struct s_watchdog_t { - bool one_shot; - time_t interval; - void (*callback)(struct s_watchdog_t *wd); - void (*destructor)(struct s_watchdog_t *wd); - void *data; - /* Private data below - don't touch outside of watchdog.c */ - dlink link; - time_t next_fire; + bool one_shot; + time_t interval; + void (*callback)(struct s_watchdog_t *wd); + void (*destructor)(struct s_watchdog_t *wd); + void *data; + /* Private data below - don't touch outside of watchdog.c */ + dlink link; + time_t next_fire; }; typedef struct s_watchdog_t watchdog_t; diff --git a/bacula/src/lib/workq.h b/bacula/src/lib/workq.h index 2c4c11d27e..7e5fab5429 100644 --- a/bacula/src/lib/workq.h +++ b/bacula/src/lib/workq.h @@ -10,22 +10,17 @@ * Version $Id$ */ /* - Copyright (C) 2000-2003 Kern Sibbald and John Walker + Copyright (C) 2001-2006 Kern Sibbald This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. + modify it under the terms of the GNU General Public License + version 2 as amended with additional clauses defined in the + file LICENSE in the main source directory. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + the file LICENSE for additional details. */ @@ -59,10 +54,10 @@ typedef struct workq_tag { #define WORKQ_VALID 0xdec1992 extern int workq_init( - workq_t *wq, - int threads, /* maximum threads */ - void *(*engine)(void *) /* engine routine */ - ); + workq_t *wq, + int threads, /* maximum threads */ + void *(*engine)(void *) /* engine routine */ + ); extern int workq_destroy(workq_t *wq); extern int workq_add(workq_t *wq, void *element, workq_ele_t **work_item, int priority); extern int workq_remove(workq_t *wq, workq_ele_t *work_item); diff --git a/bacula/src/stored/fd_cmds.c b/bacula/src/stored/fd_cmds.c index af51981731..6e491361a7 100644 --- a/bacula/src/stored/fd_cmds.c +++ b/bacula/src/stored/fd_cmds.c @@ -310,6 +310,9 @@ static bool bootstrap_cmd(JCR *jcr) return get_bootstrap_file(jcr, jcr->file_bsock); } +static pthread_mutex_t bsr_mutex = PTHREAD_MUTEX_INITIALIZER; +static uint32_t bsr_uniq = 0; + bool get_bootstrap_file(JCR *jcr, BSOCK *sock) { POOLMEM *fname = get_pool_memory(PM_FNAME); @@ -320,8 +323,11 @@ bool get_bootstrap_file(JCR *jcr, BSOCK *sock) unlink(jcr->RestoreBootstrap); free_pool_memory(jcr->RestoreBootstrap); } - Mmsg(fname, "%s/%s.%s.bootstrap", me->working_directory, me->hdr.name, - jcr->Job); + P(bsr_mutex); + bsr_uniq++; + Mmsg(fname, "%s/%s.%s.%d.bootstrap", me->working_directory, me->hdr.name, + jcr->Job, bsr_uniq); + V(bsr_mutex); Dmsg1(400, "bootstrap=%s\n", fname); jcr->RestoreBootstrap = fname; bs = fopen(fname, "a+b"); /* create file */ diff --git a/bacula/src/stored/mac.c b/bacula/src/stored/mac.c index eda7a3e925..035df19854 100644 --- a/bacula/src/stored/mac.c +++ b/bacula/src/stored/mac.c @@ -75,7 +75,7 @@ bool do_mac(JCR *jcr) goto bail_out; } - Dmsg3(000, "Found %d volumes names for %s. First=%s\n", jcr->NumVolumes, + Dmsg3(200, "Found %d volumes names for %s. First=%s\n", jcr->NumVolumes, jcr->VolList->VolumeName, Type); /* Ready devices for reading and writing */ diff --git a/bacula/src/version.h b/bacula/src/version.h index 63b6e1f781..ee05851925 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -3,9 +3,9 @@ */ #undef VERSION -#define VERSION "1.39.15" -#define BDATE "5 July 2006" -#define LSMDATE "05Jul06" +#define VERSION "1.39.16" +#define BDATE "8 July 2006" +#define LSMDATE "08Jul06" /* Debug flags */ #undef DEBUG -- 2.39.5