From d21102750b0e327f9bce58a634601bec9c2aab3c Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Thu, 1 Apr 2004 16:37:01 +0000 Subject: [PATCH 1/1] Lots of cleanups + Christopher Hull's patches git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1169 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/Makefile.in | 11 ++++----- bacula/kernstodo | 27 +++++++++++----------- bacula/src/cats/sql.c | 24 ++++++++++---------- bacula/src/cats/sql_create.c | 17 +++++++------- bacula/src/cats/sql_get.c | 24 +++++++++++++++++++- bacula/src/cats/sql_update.c | 2 +- bacula/src/dird/dird.c | 2 +- bacula/src/dird/job.c | 11 ++++----- bacula/src/dird/ua_status.c | 1 - bacula/src/filed/filed.c | 2 +- bacula/src/filed/status.c | 3 +++ bacula/src/lib/alist.c | 2 +- bacula/src/lib/bnet.c | 2 +- bacula/src/lib/dlist.c | 5 +++- bacula/src/lib/htable.c | 6 ++--- bacula/src/lib/jcr.c | 7 +----- bacula/src/lib/mem_pool.c | 2 +- bacula/src/lib/smartall.c | 35 ++++++++++++++++++++-------- bacula/src/lib/smartall.h | 24 +++++++++----------- bacula/src/lib/watchdog.c | 24 ++++++++++++++++---- bacula/src/stored/btape.c | 40 ++++++++++++++++---------------- bacula/src/stored/stored.c | 2 +- bacula/src/tools/dbcheck.c | 44 ++++++++++++++++++++++++++++++++++-- bacula/src/tools/testfind.c | 2 +- bacula/src/tools/testls.c | 2 +- bacula/src/version.h | 4 ++-- 26 files changed, 206 insertions(+), 119 deletions(-) diff --git a/bacula/Makefile.in b/bacula/Makefile.in index 312c91c4e8..c1af4b5acb 100755 --- a/bacula/Makefile.in +++ b/bacula/Makefile.in @@ -16,11 +16,10 @@ first_rule: all dummy: fd_subdirs = src scripts doc src/lib src/findlib src/filed \ - rescue rescue/linux + @READLINE_SRC@ src/console rescue rescue/linux -subdirs = src/cats @READLINE_SRC@ src/console src/dird \ - src/stored @GNOME_DIR@ src/tools +subdirs = src/cats src/dird src/stored @GNOME_DIR@ src/tools all_subdirs = ${fd_subdirs} ${@ALL_DIRS@} @@ -93,17 +92,17 @@ gnomedirs: $(MKDIR) $(DESTDIR)/etc/security/console.apps $(MKDIR) $(DESTDIR)/etc/pam.d -install-menu: installdirs gnomedirs +install-menu: gnomedirs ${INSTALL_DATA} scripts/bacula.png $(DESTDIR)/usr/share/pixmaps/bacula.png ${INSTALL_DATA} scripts/bacula.desktop.gnome1 $(DESTDIR)/usr/share/gnome/apps/System/bacula.desktop ${INSTALL_DATA} scripts/bacula.desktop.gnome2 $(DESTDIR)/usr/share/applications/bacula.desktop -install-menu-xsu: installdirs gnomedirs +install-menu-xsu: gnomedirs ${INSTALL_DATA} scripts/bacula.png $(DESTDIR)/usr/share/pixmaps/bacula.png ${INSTALL_DATA} scripts/bacula.desktop.gnome1.xsu $(DESTDIR)/usr/share/gnome/apps/System/bacula.desktop ${INSTALL_DATA} scripts/bacula.desktop.gnome2.xsu $(DESTDIR)/usr/share/applications/bacula.desktop -install-menu-consolehelper: installdirs gnomedirs +install-menu-consolehelper: gnomedirs ${INSTALL_DATA} scripts/bacula.png $(DESTDIR)/usr/share/pixmaps/bacula.png ${INSTALL_DATA} scripts/bacula.desktop.gnome1.consolehelper $(DESTDIR)/usr/share/gnome/apps/System/bacula.desktop ${INSTALL_DATA} scripts/bacula.desktop.gnome2.consolehelper $(DESTDIR)/usr/share/applications/bacula.desktop diff --git a/bacula/kernstodo b/bacula/kernstodo index b3f1ed56b8..f9ea23b2a6 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -1,5 +1,5 @@ Kern's ToDo List - 28 March 2004 + 31 March 2004 Documentation to do: (any release a little bit at a time) - DB upgrade to version 5 in bacula-1.27b, DB upgrade to @@ -38,9 +38,6 @@ Testing to do: (painful) For 1.33 Testing/Documentation: - Add counter variable test. -- Document ln -sf /usr/lib/libncurses.so /usr/lib/libtermcap.so - and install the esound-devĀ  package for compiling Console on SuSE. - This should read 'Document LDFLAGS="-L/usr/lib/termcap" ... ' - Add an example of using a FIFO in dirdconf.wml - Add an item to the FAQ about running jobs in different timezones. - Add some examples of job editing codes. @@ -59,23 +56,15 @@ For 1.33 Testing/Documentation: a consequence, Bacula will completely stall untilthe machine exporting the NSF mounts comes back up. If someone knows a wayaround this, please let me know."I haven't tried using NFS in years, but I think that the - "soft" and "intr"remount options may well help you. The only way of - being sure would be totry it.See, for example, + "soft" and "intr" remount options may well help you. The only way of + being sure would be to try it.See, for example, http://howtos.linux.com/guides/nag2/x-087-2-nfs.mountd.shtml For 1.33 -- Null dlist head and tail pointers if all items are removed. - Complete Win32 installer - Finish work on Gnome restore GUI. -- On unknown client in restore "client=xxx" - Could not find Client "Matou": ERR=Query failed: DROP TABLE temp1: - ERR=no such table: temp1 - Fix "llist jobid=xx" where no fileset or client exists. -- Build console in client-only build. - Test work on conio.c -- particularly linking. -- Phil says that Windows file sizes mismatch in Verify when they should, - and that either the file size or the catalog size was zero. -- Check time/dates printed during restore when using Win32 API. --- Maybe in 1.33 From Chris Hull: @@ -94,6 +83,8 @@ From Chris Hull: For version 1.35: +- Make sure list of Volumes needed is in correct order for restore. + See havana. - Remove paths (and files that reference them) that have no trailing slash in dbcheck -- or add a trailing slash. - Remove Filenames (and files that reference them) that have a trailing @@ -1421,3 +1412,11 @@ Block Position: 0 - Test Qmsg() code to be used in bnet.c to prevent recursion. Queue the message. If dequeueing toss the messages. Lock while dequeuing so that it cannot be called recursively and set dequeuing flag. +- On unknown client in restore "client=xxx" + Could not find Client "Matou": ERR=Query failed: DROP TABLE temp1: + ERR=no such table: temp1 +- Null dlist head and tail pointers if all items are removed. +- Build console in client-only build. +- Phil says that Windows file sizes mismatch in Verify when they should, + and that either the file size or the catalog size was zero. +- Check time/dates printed during restore when using Win32 API. diff --git a/bacula/src/cats/sql.c b/bacula/src/cats/sql.c index 26144925ac..b0e8e943c8 100644 --- a/bacula/src/cats/sql.c +++ b/bacula/src/cats/sql.c @@ -52,16 +52,16 @@ static int int_handler(void *ctx, int num_fields, char **row) { uint32_t *val = (uint32_t *)ctx; - Dmsg1(200, "int_handler starts with row pointing at %x\n", row); + Dmsg1(800, "int_handler starts with row pointing at %x\n", row); if (row[0]) { - Dmsg1(200, "int_handler finds '%s'\n", row[0]); + Dmsg1(800, "int_handler finds '%s'\n", row[0]); *val = atoi(row[0]); } else { - Dmsg0(200, "int_handler finds zero\n"); + Dmsg0(800, "int_handler finds zero\n"); *val = 0; } - Dmsg0(200, "int_handler finishes\n"); + Dmsg0(800, "int_handler finishes\n"); return 0; } @@ -383,17 +383,17 @@ list_result(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *send, void *ctx, e_list_type t int i, col_len, max_len = 0; char buf[2000], ewc[30]; - Dmsg0(200, "list_result starts\n"); + Dmsg0(800, "list_result starts\n"); if (mdb->result == NULL || sql_num_rows(mdb) == 0) { send(ctx, _("No results to list.\n")); return; } - Dmsg1(200, "list_result starts looking at %d fields\n", sql_num_fields(mdb)); + Dmsg1(800, "list_result starts looking at %d fields\n", sql_num_fields(mdb)); /* determine column display widths */ sql_field_seek(mdb, 0); for (i = 0; i < sql_num_fields(mdb); i++) { - Dmsg1(200, "list_result processing field %d\n", i); + Dmsg1(800, "list_result processing field %d\n", i); field = sql_fetch_field(mdb); col_len = strlen(field->name); if (type == VERT_LIST) { @@ -414,17 +414,17 @@ list_result(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *send, void *ctx, e_list_type t } } - Dmsg0(200, "list_result finished first loop\n"); + Dmsg0(800, "list_result finished first loop\n"); if (type == VERT_LIST) { goto vertical_list; } - Dmsg1(200, "list_result starts second loop looking at %d fields\n", sql_num_fields(mdb)); + Dmsg1(800, "list_result starts second loop looking at %d fields\n", sql_num_fields(mdb)); list_dashes(mdb, send, ctx); send(ctx, "|"); sql_field_seek(mdb, 0); for (i = 0; i < sql_num_fields(mdb); i++) { - Dmsg1(200, "list_result looking at field %d\n", i); + Dmsg1(800, "list_result looking at field %d\n", i); field = sql_fetch_field(mdb); bsnprintf(buf, sizeof(buf), " %-*s |", (int)field->max_length, field->name); send(ctx, buf); @@ -432,7 +432,7 @@ list_result(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *send, void *ctx, e_list_type t send(ctx, "\n"); list_dashes(mdb, send, ctx); - Dmsg1(200, "list_result starts third loop looking at %d fields\n", sql_num_fields(mdb)); + Dmsg1(800, "list_result starts third loop looking at %d fields\n", sql_num_fields(mdb)); while ((row = sql_fetch_row(mdb)) != NULL) { sql_field_seek(mdb, 0); send(ctx, "|"); @@ -455,7 +455,7 @@ list_result(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *send, void *ctx, e_list_type t vertical_list: - Dmsg1(200, "list_result starts vertical list at %d fields\n", sql_num_fields(mdb)); + Dmsg1(800, "list_result starts vertical list at %d fields\n", sql_num_fields(mdb)); while ((row = sql_fetch_row(mdb)) != NULL) { sql_field_seek(mdb, 0); for (i = 0; i < sql_num_fields(mdb); i++) { diff --git a/bacula/src/cats/sql_create.c b/bacula/src/cats/sql_create.c index a69471623d..9720b1f16e 100644 --- a/bacula/src/cats/sql_create.c +++ b/bacula/src/cats/sql_create.c @@ -515,6 +515,7 @@ int db_create_fileset_record(JCR *jcr, B_DB *mdb, FILESET_DBR *fsr) int db_create_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar) { + db_lock(mdb); Dmsg1(300, "Fname=%s\n", ar->fname); Dmsg0(500, "put_file_into_catalog\n"); /* @@ -524,36 +525,36 @@ int db_create_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar) ar->Stream == STREAM_UNIX_ATTRIBUTES_EX)) { Mmsg0(&mdb->errmsg, _("Attempt to put non-attributes into catalog\n")); Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg); - return 0; + goto bail_out; } - db_lock(mdb); split_path_and_file(jcr, mdb, ar->fname); if (!db_create_filename_record(jcr, mdb, ar)) { - db_unlock(mdb); - return 0; + goto bail_out; } Dmsg1(500, "db_create_filename_record: %s\n", mdb->esc_name); if (!db_create_path_record(jcr, mdb, ar)) { - db_unlock(mdb); - return 0; + goto bail_out; } Dmsg1(500, "db_create_path_record: %s\n", mdb->esc_name); /* Now create master File record */ if (!db_create_file_record(jcr, mdb, ar)) { - db_unlock(mdb); - return 0; + goto bail_out; } Dmsg0(500, "db_create_file_record OK\n"); Dmsg3(300, "CreateAttributes Path=%s File=%s FilenameId=%d\n", mdb->path, mdb->fname, ar->FilenameId); db_unlock(mdb); return 1; + +bail_out: + db_unlock(mdb); + return 0; } /* diff --git a/bacula/src/cats/sql_get.c b/bacula/src/cats/sql_get.c index 9594f74108..d02d251ac0 100644 --- a/bacula/src/cats/sql_get.c +++ b/bacula/src/cats/sql_get.c @@ -144,6 +144,8 @@ int db_get_file_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr, FILE_DBR *fdbr) fdbr->PathId, fdbr->FilenameId); } sql_free_result(mdb); + } else { + Mmsg(&mdb->errmsg, _("File record not found in Catalog.\n")); } return stat; @@ -189,6 +191,8 @@ static int db_get_filename_record(JCR *jcr, B_DB *mdb) Mmsg1(&mdb->errmsg, _("Filename record: %s not found.\n"), mdb->fname); } sql_free_result(mdb); + } else { + Mmsg(&mdb->errmsg, _("Filename record: %s not found in Catalog.\n"), mdb->fname); } return FilenameId; } @@ -246,6 +250,8 @@ static int db_get_path_record(JCR *jcr, B_DB *mdb) Mmsg1(&mdb->errmsg, _("Path record: %s not found.\n"), mdb->path); } sql_free_result(mdb); + } else { + Mmsg(&mdb->errmsg, _("Path record: %s not found in Catalog.\n"), mdb->path); } return PathId; } @@ -352,6 +358,8 @@ int db_get_job_volume_names(JCR *jcr, B_DB *mdb, uint32_t JobId, POOLMEM **Volum } } sql_free_result(mdb); + } else { + Mmsg(&mdb->errmsg, _("No Volume for JobId %d found in Catalog.\n"), JobId); } db_unlock(mdb); return stat; @@ -563,8 +571,12 @@ MaxVolBytes,PoolType,LabelFormat FROM Pool WHERE Pool.Name='%s'", pdbr->Name); bstrncpy(pdbr->LabelFormat, row[14]!=NULL?row[15]:"", sizeof(pdbr->LabelFormat)); stat = pdbr->PoolId; } + } else { + Mmsg(&mdb->errmsg, _("Pool record not found in Catalog.\n")); } sql_free_result(mdb); + } else { + Mmsg(&mdb->errmsg, _("Pool record not found in Catalog.\n")); } db_unlock(mdb); return stat; @@ -613,8 +625,12 @@ int db_get_client_record(JCR *jcr, B_DB *mdb, CLIENT_DBR *cdbr) cdbr->JobRetention = str_to_int64(row[5]); stat = 1; } + } else { + Mmsg(&mdb->errmsg, _("Client record not found in Catalog.\n")); } sql_free_result(mdb); + } else { + Mmsg(&mdb->errmsg, _("Client record not found in Catalog.\n")); } db_unlock(mdb); return stat; @@ -664,7 +680,9 @@ int db_get_counter_record(JCR *jcr, B_DB *mdb, COUNTER_DBR *cr) return 1; } sql_free_result(mdb); - } + } else { + Mmsg(&mdb->errmsg, _("Counter record: %s not found in Catalog.\n"), cr->Counter); + } db_unlock(mdb); return 0; } @@ -711,6 +729,8 @@ int db_get_fileset_record(JCR *jcr, B_DB *mdb, FILESET_DBR *fsr) stat = fsr->FileSetId; } sql_free_result(mdb); + } else { + Mmsg(&mdb->errmsg, _("FileSet record not found in Catalog.\n")); } db_unlock(mdb); return stat; @@ -854,6 +874,8 @@ int db_get_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr) } } sql_free_result(mdb); + } else { + Mmsg(&mdb->errmsg, _("Media record not found in Catalog.\n")); } db_unlock(mdb); return stat; diff --git a/bacula/src/cats/sql_update.c b/bacula/src/cats/sql_update.c index 98e5dd1e03..7ffad52f60 100644 --- a/bacula/src/cats/sql_update.c +++ b/bacula/src/cats/sql_update.c @@ -108,8 +108,8 @@ db_update_job_start_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr) (char)(jr->Level), dt, jr->ClientId, edit_uint64(JobTDate, ed1), jr->JobId); stat = UPDATE_DB(jcr, mdb, mdb->cmd); - db_unlock(mdb); mdb->changes = 0; + db_unlock(mdb); return stat; } diff --git a/bacula/src/dird/dird.c b/bacula/src/dird/dird.c index c09721b6b0..71f4bc538d 100644 --- a/bacula/src/dird/dird.c +++ b/bacula/src/dird/dird.c @@ -271,7 +271,7 @@ static void terminate_dird(int sig) term_msg(); /* terminate message handler */ stop_watchdog(); close_memory_pool(); /* release free memory in pool */ - sm_dump(False); + sm_dump(false); exit(sig); } diff --git a/bacula/src/dird/job.c b/bacula/src/dird/job.c index 6c486ae545..f26f2b369c 100644 --- a/bacula/src/dird/job.c +++ b/bacula/src/dird/job.c @@ -68,8 +68,6 @@ void init_job_server(int max_workers) wd->interval = 60; wd->data = new_control_jcr("*JobMonitor*", JT_SYSTEM); register_watchdog(wd); - - return; } /* @@ -82,7 +80,7 @@ void run_job(JCR *jcr) int stat, errstat; P(jcr->mutex); - sm_check(__FILE__, __LINE__, True); + sm_check(__FILE__, __LINE__, true); init_msg(jcr, jcr->messages); create_unique_job_name(jcr, jcr->job->hdr.name); set_jcr_job_status(jcr, JS_Created); @@ -160,8 +158,9 @@ static void *job_thread(void *arg) { JCR *jcr = (JCR *)arg; - pthread_detach(pthread_self()); - sm_check(__FILE__, __LINE__, True); + jcr->my_thread_id = pthread_self(); + pthread_detach(jcr->my_thread_id); + sm_check(__FILE__, __LINE__, true); for ( ;; ) { @@ -271,7 +270,7 @@ bail_out: } Dmsg0(50, "======== End Job ==========\n"); - sm_check(__FILE__, __LINE__, True); + sm_check(__FILE__, __LINE__, true); return NULL; } diff --git a/bacula/src/dird/ua_status.c b/bacula/src/dird/ua_status.c index ce801ee496..a65efae62d 100644 --- a/bacula/src/dird/ua_status.c +++ b/bacula/src/dird/ua_status.c @@ -414,7 +414,6 @@ static void list_running_jobs(UAContext *ua) return; } njobs = 0; - bsendmsg(ua, _("\nRunning Jobs:\n")); bsendmsg(ua, _(" JobId Level Name Status\n")); bsendmsg(ua, _("======================================================================\n")); foreach_jcr(jcr) { diff --git a/bacula/src/filed/filed.c b/bacula/src/filed/filed.c index aa536f1617..5ebf0c37ba 100644 --- a/bacula/src/filed/filed.c +++ b/bacula/src/filed/filed.c @@ -263,6 +263,6 @@ void terminate_filed(int sig) term_msg(); stop_watchdog(); close_memory_pool(); /* release free memory in pool */ - sm_dump(False); /* dump orphaned buffers */ + sm_dump(false); /* dump orphaned buffers */ exit(sig); } diff --git a/bacula/src/filed/status.c b/bacula/src/filed/status.c index 32e50a5da6..5565deeebc 100755 --- a/bacula/src/filed/status.c +++ b/bacula/src/filed/status.c @@ -354,6 +354,9 @@ char *bac_status(int stat) struct s_last_job *job; bacstat = 0; + if (!last_jobs) { + return _("Bacula Terminated"); + } if (last_jobs->size() > 0) { job = (struct s_last_job *)last_jobs->first(); switch (job->JobStatus) { diff --git a/bacula/src/lib/alist.c b/bacula/src/lib/alist.c index ea60835b0d..9d90a97f84 100644 --- a/bacula/src/lib/alist.c +++ b/bacula/src/lib/alist.c @@ -194,7 +194,7 @@ int main() delete mlist; - sm_dump(False); + sm_dump(false); } #endif diff --git a/bacula/src/lib/bnet.c b/bacula/src/lib/bnet.c index bef757e231..a9a339b102 100644 --- a/bacula/src/lib/bnet.c +++ b/bacula/src/lib/bnet.c @@ -245,7 +245,7 @@ int32_t bnet_recv(BSOCK *bsock) * buffer is at least one byte longer than the message length. */ mp_chr(bsock->msg)[nbytes] = 0; /* terminate in case it is a string */ - sm_check(__FILE__, __LINE__, False); + sm_check(__FILE__, __LINE__, false); return nbytes; /* return actual length of message */ } diff --git a/bacula/src/lib/dlist.c b/bacula/src/lib/dlist.c index c0d1242638..b82c8bd0dd 100644 --- a/bacula/src/lib/dlist.c +++ b/bacula/src/lib/dlist.c @@ -127,6 +127,9 @@ void dlist::remove(void *item) ((dlink *)(((char *)xitem)+loffset))->next = ilink->next; } num_items--; + if (num_items == 0) { + head = tail = NULL; + } } void * dlist::next(void *item) @@ -235,7 +238,7 @@ int main() delete jcr_chain; - sm_dump(False); + sm_dump(false); } #endif diff --git a/bacula/src/lib/htable.c b/bacula/src/lib/htable.c index 1ea0f15388..088b8c96a7 100644 --- a/bacula/src/lib/htable.c +++ b/bacula/src/lib/htable.c @@ -187,7 +187,7 @@ bool htable::insert(char *key, void *item) if (lookup(key)) { return false; /* already exists */ } - sm_check(__FILE__, __LINE__, False); + sm_check(__FILE__, __LINE__, false); ASSERT(index < buckets); Dmsg2(100, "Insert: hash=0x%x index=%d\n", (unsigned)hash, index); hp = (hlink *)(((char *)item)+loffset); @@ -204,7 +204,7 @@ bool htable::insert(char *key, void *item) Dmsg2(100, "num_items=%d max_items=%d\n", num_items, max_items); grow_table(); } - sm_check(__FILE__, __LINE__, False); + sm_check(__FILE__, __LINE__, false); Dmsg3(100, "Leave insert index=%d num_items=%d key=%s\n", index, num_items, key); return true; } @@ -334,7 +334,7 @@ int main() free(jcrtbl); printf("Freed jcrtbl\n"); - sm_dump(False); + sm_dump(false); } #endif diff --git a/bacula/src/lib/jcr.c b/bacula/src/lib/jcr.c index 8f7d60bd1b..00a7254689 100755 --- a/bacula/src/lib/jcr.c +++ b/bacula/src/lib/jcr.c @@ -50,7 +50,7 @@ void init_last_jobs_list() int errstat; struct s_last_job *job_entry = NULL; if (!last_jobs) { - last_jobs = new dlist(job_entry, &job_entry->link); + last_jobs = new dlist(job_entry, &job_entry->link); if ((errstat=rwl_init(&lock)) != 0) { Emsg1(M_ABORT, 0, _("Unable to initialize jcr_chain lock. ERR=%s\n"), strerror(errstat)); @@ -61,11 +61,7 @@ void init_last_jobs_list() void term_last_jobs_list() { - struct s_last_job *je; if (last_jobs) { - foreach_dlist(je, last_jobs) { - free(je); - } delete last_jobs; last_jobs = NULL; rwl_destroy(&lock); @@ -186,7 +182,6 @@ JCR *new_jcr(int size, JCR_free_HANDLER *daemon_free_jcr) memset(jcr, 0, size); jcr->msg_queue = new dlist(item, &item->link); jcr->job_end_push.init(1, false); - jcr->my_thread_id = pthread_self(); jcr->sched_time = time(NULL); jcr->daemon_free_jcr = daemon_free_jcr; /* plug daemon free routine */ jcr->use_count = 1; diff --git a/bacula/src/lib/mem_pool.c b/bacula/src/lib/mem_pool.c index 55240b1512..229868bc09 100644 --- a/bacula/src/lib/mem_pool.c +++ b/bacula/src/lib/mem_pool.c @@ -360,7 +360,7 @@ void close_memory_pool() { struct abufhead *buf, *next; - sm_check(__FILE__, __LINE__, False); + sm_check(__FILE__, __LINE__, false); P(mutex); for (int i=1; i<=PM_MAX; i++) { buf = pool_ctl[i].free_buf; diff --git a/bacula/src/lib/smartall.c b/bacula/src/lib/smartall.c index 3a5a679ee7..fe8093facb 100644 --- a/bacula/src/lib/smartall.c +++ b/bacula/src/lib/smartall.c @@ -19,7 +19,7 @@ */ /* - Copyright (C) 2000-2003 Kern Sibbald and John Walker + Copyright (C) 2000-2004 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 @@ -44,6 +44,19 @@ #undef calloc #undef malloc #undef free + +/* We normally turn off debugging here. + * If you want it, simply #ifdef all the + * following off. + */ +#undef Dmsg1 +#undef Dmsg2 +#undef Dmsg3 +#undef Dmsg4 +#define Dmsg1(l,f,a1) +#define Dmsg2(l,f,a1,a2) +#define Dmsg3(l,f,a1,a2,a3) +#define Dmsg4(l,f,a1,a2,a3,a4) @@ -73,7 +86,7 @@ static struct b_queue abqueue = { /* Allocated buffer queue */ &abqueue, &abqueue }; -static Boolean bufimode = False; /* Buffers not tracked when True */ +static bool bufimode = false; /* Buffers not tracked when True */ #define HEAD_SIZE BALIGN(sizeof(struct abufhead)) @@ -320,7 +333,7 @@ void actuallyfree(void *cp) * N.B. DO NOT USE any Bacula print routines (Dmsg, Jmsg, Emsg, ...) * as they have all been shut down at this point. */ -void sm_dump(Boolean bufdump) +void sm_dump(bool bufdump) { struct abufhead *ap; @@ -344,27 +357,29 @@ void sm_dump(Boolean bufdump) if (ap->abfname != NULL) { unsigned memsize = ap->ablen - (HEAD_SIZE + 1); - char errmsg[80]; + char errmsg[500]; - sprintf(errmsg, + bsnprintf(errmsg, sizeof(errmsg), "Orphaned buffer: %6u bytes allocated at line %d of %s %s\n", memsize, ap->ablineno, my_name, ap->abfname ); fprintf(stderr, "%s", errmsg); if (bufdump) { + char buf[20]; unsigned llen = 0; char *cp = ((char *) ap) + HEAD_SIZE; errmsg[0] = EOS; while (memsize) { if (llen >= 16) { - strcat(errmsg, "\n"); + bstrncat(errmsg, "\n", sizeof(errmsg)); llen = 0; fprintf(stderr, "%s", errmsg); errmsg[0] = EOS; } - sprintf(errmsg + strlen(errmsg), " %02X", + bsnprintf(buf, sizeof(buf), " %02X", (*cp++) & 0xFF); + bstrncat(errmsg, buf, sizeof(errmsg)); llen++; memsize--; } @@ -378,7 +393,7 @@ void sm_dump(Boolean bufdump) #undef sm_check /* SM_CHECK -- Check the buffers and dump if any damage exists. */ -void sm_check(const char *fname, int lineno, Boolean bufdump) +void sm_check(const char *fname, int lineno, bool bufdump) { if (!sm_check_rtn(fname, lineno, bufdump)) { Emsg2(M_ABORT, 0, "Damaged buffer found. Called from %s:%d\n", @@ -388,7 +403,7 @@ void sm_check(const char *fname, int lineno, Boolean bufdump) #undef sm_check_rtn /* SM_CHECK_RTN -- Check the buffers and return 1 if OK otherwise 0 */ -int sm_check_rtn(const char *fname, int lineno, Boolean bufdump) +int sm_check_rtn(const char *fname, int lineno, bool bufdump) { struct abufhead *ap; int bad, badbuf = 0; @@ -475,7 +490,7 @@ int sm_check_rtn(const char *fname, int lineno, Boolean bufdump) void sm_static(int mode) { - bufimode = (Boolean) (mode != 0); + bufimode = (bool) (mode != 0); } /* diff --git a/bacula/src/lib/smartall.h b/bacula/src/lib/smartall.h index ad72bcedd6..26062e371c 100644 --- a/bacula/src/lib/smartall.h +++ b/bacula/src/lib/smartall.h @@ -1,6 +1,6 @@ /* - Definitions for the smart memory allocator + Definitions for the smart memory allocator Version $Id$ @@ -29,23 +29,21 @@ #ifdef SMARTALLOC -typedef enum {False = 0, True = 1} Boolean; - extern void *sm_malloc(const char *fname, int lineno, unsigned int nbytes), - *sm_calloc(const char *fname, int lineno, - unsigned int nelem, unsigned int elsize), - *sm_realloc(const char *fname, int lineno, void *ptr, unsigned int size), - *actuallymalloc(unsigned int size), - *actuallycalloc(unsigned int nelem, unsigned int elsize), - *actuallyrealloc(void *ptr, unsigned int size); + *sm_calloc(const char *fname, int lineno, + unsigned int nelem, unsigned int elsize), + *sm_realloc(const char *fname, int lineno, void *ptr, unsigned int size), + *actuallymalloc(unsigned int size), + *actuallycalloc(unsigned int nelem, unsigned int elsize), + *actuallyrealloc(void *ptr, unsigned int size); extern void sm_free(const char *fname, int lineno, void *fp); extern void actuallyfree(void *cp), - sm_dump(Boolean bufdump), sm_static(int mode); + sm_dump(bool bufdump), sm_static(int mode); extern void sm_new_owner(const char *fname, int lineno, char *buf); #ifdef SMCHECK -extern void sm_check(const char *fname, int lineno, Boolean bufdump); -extern int sm_check_rtn(const char *fname, int lineno, Boolean bufdump); +extern void sm_check(const char *fname, int lineno, bool bufdump); +extern int sm_check_rtn(const char *fname, int lineno, bool bufdump); #else #define sm_check(f, l, fl) #define sm_check_rtn(f, l, fl) 1 @@ -79,7 +77,7 @@ extern int sm_check_rtn(const char *fname, int lineno, Boolean bufdump); #define sm_check_rtn(f, l, fl) 1 extern void *b_malloc(); -#define malloc(x) b_malloc(__FILE__, __LINE__, (x)) +#define malloc(x) b_malloc(__FILE__, __LINE__, (x)) #endif diff --git a/bacula/src/lib/watchdog.c b/bacula/src/lib/watchdog.c index 05e59dfe01..13d3375847 100755 --- a/bacula/src/lib/watchdog.c +++ b/bacula/src/lib/watchdog.c @@ -101,7 +101,10 @@ int stop_watchdog(void) stat = pthread_join(wd_tid, NULL); - foreach_dlist(p, wd_queue) { + while (!wd_queue->empty()) { + void *item = wd_queue->first(); + wd_queue->remove(item); + p = (watchdog_t *)item; if (p->destructor != NULL) { p->destructor(p); } @@ -110,13 +113,15 @@ int stop_watchdog(void) delete wd_queue; wd_queue = NULL; - foreach_dlist(p, wd_inactive) { + while (!wd_inactive->empty()) { + void *item = wd_inactive->first(); + wd_inactive->remove(item); + p = (watchdog_t *)item; if (p->destructor != NULL) { p->destructor(p); } free(p); } - delete wd_inactive; wd_inactive = NULL; rwl_destroy(&lock); @@ -214,14 +219,14 @@ static void *watchdog_thread(void *arg) Dmsg0(400, "NicB-reworked watchdog thread entered\n"); while (!quit) { - watchdog_t *p; + watchdog_t *p, *q; /* * We lock the jcr chain here because a good number of the * callback routines lock the jcr chain. We need to lock * it here *before* the watchdog lock because the SD message * thread first locks the jcr chain, then when closing the - * job locks the watchdog chain. If the two thread do not + * job locks the watchdog chain. If the two threads do not * lock in the same order, we get a deadlock -- each holds * the other's needed lock. */ @@ -236,8 +241,17 @@ static void *watchdog_thread(void *arg) /* Reschedule (or move to inactive list if it's a one-shot timer) */ if (p->one_shot) { + /* + * Note, when removing an item while walking the list + * we must get the previous pointer (q) and set the + * current pointer (p) to this previous pointer after + * removing the current pointer, otherwise, we won't + * walk the rest of the list. + */ + q = (watchdog_t *)wd_queue->prev(p); wd_queue->remove(p); wd_inactive->append(p); + p = q; } else { p->next_fire = watchdog_time + p->interval; } diff --git a/bacula/src/stored/btape.c b/bacula/src/stored/btape.c index c4984a6081..8c815cc8e5 100644 --- a/bacula/src/stored/btape.c +++ b/bacula/src/stored/btape.c @@ -189,7 +189,7 @@ int main(int margc, char *margv[]) break; case 's': - signals = FALSE; + signals = false; break; case 'v': @@ -253,7 +253,7 @@ terminate: static void terminate_btape(int stat) { - sm_check(__FILE__, __LINE__, False); + sm_check(__FILE__, __LINE__, false); if (configfile) { free(configfile); } @@ -288,7 +288,7 @@ static void terminate_btape(int stat) term_msg(); close_memory_pool(); /* free memory in pool */ - sm_dump(False); + sm_dump(false); exit(stat); } @@ -576,7 +576,7 @@ static void rectestcmd() return; } - sm_check(__FILE__, __LINE__, False); + sm_check(__FILE__, __LINE__, false); block = new_block(dev); rec = new_record(); @@ -584,7 +584,7 @@ static void rectestcmd() rec->data = check_pool_memory_size(rec->data, i); memset(rec->data, i & 0xFF, i); rec->data_len = i; - sm_check(__FILE__, __LINE__, False); + sm_check(__FILE__, __LINE__, false); if (write_record_to_block(block, rec)) { empty_block(block); blkno++; @@ -592,11 +592,11 @@ static void rectestcmd() } else { break; } - sm_check(__FILE__, __LINE__, False); + sm_check(__FILE__, __LINE__, false); } free_record(rec); free_block(block); - sm_check(__FILE__, __LINE__, False); + sm_check(__FILE__, __LINE__, false); } /* @@ -1412,7 +1412,7 @@ static void wrcmd() DEV_RECORD *rec; int i; - sm_check(__FILE__, __LINE__, False); + sm_check(__FILE__, __LINE__, false); block = new_block(dev); rec = new_record(); dump_block(block, "test"); @@ -1422,7 +1422,7 @@ static void wrcmd() rec->data = check_pool_memory_size(rec->data, i); memset(rec->data, i & 0xFF, i); rec->data_len = i; - sm_check(__FILE__, __LINE__, False); + sm_check(__FILE__, __LINE__, false); if (!write_record_to_block(block, rec)) { Pmsg0(0, _("Error writing record to block.\n")); goto bail_out; @@ -1436,10 +1436,10 @@ static void wrcmd() Pmsg0(0, _("Wrote block to device.\n")); bail_out: - sm_check(__FILE__, __LINE__, False); + sm_check(__FILE__, __LINE__, false); free_record(rec); free_block(block); - sm_check(__FILE__, __LINE__, False); + sm_check(__FILE__, __LINE__, false); } /* @@ -1834,12 +1834,12 @@ This may take a long time -- hours! ...\n\n"); } if (!write_session_label(jcr, block, EOS_LABEL)) { Pmsg1(000, _("Error writting end session label. ERR=%s\n"), strerror_dev(dev)); - ok = FALSE; + ok = false; } /* Write out final block of this session */ if (!write_block_to_device(jcr->dcr, block)) { - Pmsg0(-1, _("Set ok=FALSE after write_block_to_device.\n")); - ok = FALSE; + Pmsg0(-1, _("Set ok=false after write_block_to_device.\n")); + ok = false; } Pmsg0(-1, _("Wrote End Of Session label.\n")); @@ -1875,7 +1875,7 @@ This may take a long time -- hours! ...\n\n"); /* Release the device */ if (!release_device(jcr)) { Pmsg0(-1, _("Error in release_device\n")); - ok = FALSE; + ok = false; } @@ -2185,7 +2185,7 @@ static int flush_block(DEV_BLOCK *block, int dump) /* Full test in progress */ if (!fixup_device_block_write_error(jcr, dev, block)) { Pmsg1(000, _("Cannot fixup device error. %s\n"), strerror_dev(dev)); - ok = FALSE; + ok = false; unlock_device(dev); return 0; } @@ -2233,7 +2233,7 @@ static void qfillcmd() count = 1000; } - sm_check(__FILE__, __LINE__, False); + sm_check(__FILE__, __LINE__, false); block = new_block(dev); rec = new_record(); @@ -2267,10 +2267,10 @@ static void qfillcmd() scan_blocks(); bail_out: - sm_check(__FILE__, __LINE__, False); + sm_check(__FILE__, __LINE__, false); free_record(rec); free_block(block); - sm_check(__FILE__, __LINE__, False); + sm_check(__FILE__, __LINE__, false); } @@ -2416,7 +2416,7 @@ do_tape_cmds() bool found; while (get_cmd("*")) { - sm_check(__FILE__, __LINE__, False); + sm_check(__FILE__, __LINE__, false); found = false; parse_args(cmd, &args, &argc, argk, argv, MAX_CMD_ARGS); for (i=0; i 1) { + printf("%s\n", buf); + } if (!make_id_list(buf, &id_list)) { exit(1); } @@ -476,9 +479,15 @@ static void eliminate_duplicate_filenames() for (int j=1; j 1) { + printf("%s\n", buf); + } db_sql_query(db, buf, NULL, NULL); sprintf(buf, "DELETE FROM Filename WHERE FilenameId=%u", id_list.Id[j]); + if (verbose > 2) { + printf("%s\n", buf); + } db_sql_query(db, buf, NULL, NULL); } } @@ -511,7 +520,9 @@ static void eliminate_duplicate_paths() /* Get all the Ids of each name */ db_escape_string(esc_name, name_list.name[i], strlen(name_list.name[i])); sprintf(buf, "SELECT PathId FROM Path WHERE Path='%s'", esc_name); - id_list.num_ids = 0; + if (verbose > 1) { + printf("%s\n", buf); + } if (!make_id_list(buf, &id_list)) { exit(1); } @@ -522,9 +533,15 @@ static void eliminate_duplicate_paths() for (int j=1; j 1) { + printf("%s\n", buf); + } db_sql_query(db, buf, NULL, NULL); sprintf(buf, "DELETE FROM Path WHERE PathId=%u", id_list.Id[j]); + if (verbose > 2) { + printf("%s\n", buf); + } db_sql_query(db, buf, NULL, NULL); } } @@ -569,6 +586,9 @@ static void eliminate_orphaned_file_records() query = "SELECT File.FileId,Job.JobId FROM File " "LEFT OUTER JOIN Job ON (File.JobId=Job.JobId) " "WHERE Job.JobId IS NULL"; + if (verbose > 1) { + printf("%s\n", query); + } if (!make_id_list(query, &id_list)) { exit(1); } @@ -598,6 +618,9 @@ static void eliminate_orphaned_path_records() query = "SELECT Path.PathId,File.PathId FROM Path " "LEFT OUTER JOIN File ON (Path.PathId=File.PathId) " "GROUP BY Path.PathId HAVING File.PathId IS NULL"; + if (verbose > 1) { + printf("%s\n", query); + } if (!make_id_list(query, &id_list)) { exit(1); } @@ -623,7 +646,9 @@ static void eliminate_orphaned_filename_records() query = "SELECT Filename.FilenameId,File.FilenameId FROM Filename " "LEFT OUTER JOIN File ON (Filename.FilenameId=File.FilenameId) " "WHERE File.FilenameId IS NULL"; - + if (verbose > 1) { + printf("%s\n", query); + } if (!make_id_list(query, &id_list)) { exit(1); } @@ -649,6 +674,9 @@ static void eliminate_orphaned_fileset_records() query = "SELECT FileSet.FileSetId,Job.FileSetId FROM FileSet " "LEFT OUTER JOIN Job ON (FileSet.FileSetId=Job.FileSetId) " "WHERE Job.FileSetId IS NULL"; + if (verbose > 1) { + printf("%s\n", query); + } if (!make_id_list(query, &id_list)) { exit(1); } @@ -677,6 +705,9 @@ static void repair_bad_filenames() printf("Checking for Filenames with a trailing slash\n"); query = "SELECT FilenameId,Name from Filename " "WHERE Name LIKE '%/'"; + if (verbose > 1) { + printf("%s\n", query); + } if (!make_id_list(query, &id_list)) { exit(1); } @@ -716,6 +747,9 @@ static void repair_bad_filenames() bsnprintf(buf, sizeof(buf), "UPDATE Filename SET Name='%s' WHERE FilenameId=%u", esc_name, id_list.Id[i]); + if (verbose > 1) { + printf("%s\n", buf); + } db_sql_query(db, buf, NULL, NULL); } } @@ -729,6 +763,9 @@ static void repair_bad_paths() printf("Checking for Paths without a trailing slash\n"); query = "SELECT PathId,Path from Path " "WHERE Path NOT LIKE '%/'"; + if (verbose > 1) { + printf("%s\n", query); + } if (!make_id_list(query, &id_list)) { exit(1); } @@ -763,6 +800,9 @@ static void repair_bad_paths() db_escape_string(esc_name, name, len); bsnprintf(buf, sizeof(buf), "UPDATE Path SET Path='%s' WHERE PathId=%u", esc_name, id_list.Id[i]); + if (verbose > 1) { + printf("%s\n", buf); + } db_sql_query(db, buf, NULL, NULL); } } diff --git a/bacula/src/tools/testfind.c b/bacula/src/tools/testfind.c index fca5d95a27..a9f9afa231 100644 --- a/bacula/src/tools/testfind.c +++ b/bacula/src/tools/testfind.c @@ -167,7 +167,7 @@ Hard links : %d\n"), free_jcr(jcr); close_memory_pool(); - sm_dump(False); + sm_dump(false); exit(0); } diff --git a/bacula/src/tools/testls.c b/bacula/src/tools/testls.c index ccd0577646..7ecd5fb9bc 100755 --- a/bacula/src/tools/testls.c +++ b/bacula/src/tools/testls.c @@ -152,7 +152,7 @@ main (int argc, char *const *argv) free_jcr(jcr); close_memory_pool(); - sm_dump(False); + sm_dump(false); exit(0); } diff --git a/bacula/src/version.h b/bacula/src/version.h index dda5cf07fc..cbf2da5184 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -2,8 +2,8 @@ #undef VERSION #define VERSION "1.33.6" #define VSTRING "1" -#define BDATE "30 Mar 2004" -#define LSMDATE "30Mar04" +#define BDATE "01 Apr 2004" +#define LSMDATE "01Apr04" /* Debug flags */ #undef DEBUG -- 2.39.5