From 9507ae8867b135fa85703eebe5e0311491319f5f Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Wed, 7 Aug 2002 11:09:12 +0000 Subject: [PATCH] Fix console race, base64 -- kes07Aug02 git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@80 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/baconfig.h | 14 +++++++++++++ bacula/src/cats/mysql.c | 7 ------- bacula/src/dird/ua_cmds.c | 1 - bacula/src/dird/ua_dotcmds.c | 1 - bacula/src/dird/ua_output.c | 13 +++++++++--- bacula/src/lib/base64.c | 38 +++++++++++++++++++++++++++++++++--- bacula/src/lib/message.c | 14 ++++++++----- bacula/src/lib/signal.c | 2 +- bacula/src/version.h | 4 ++-- 9 files changed, 71 insertions(+), 23 deletions(-) diff --git a/bacula/src/baconfig.h b/bacula/src/baconfig.h index fe8f4395ce..37164ff39c 100644 --- a/bacula/src/baconfig.h +++ b/bacula/src/baconfig.h @@ -170,6 +170,20 @@ extern void _v(char *file, int line, pthread_mutex_t *m); #endif /* DEBUG_MUTEX */ +/* These probably should be subroutines */ +#define Pw(x) \ + do { int errstat; if ((errstat=rwl_writelock(&(x)))) \ + e_msg(__FILE__, __LINE__, M_ABORT, 0, "Write lock lock failure. ERR=%s\n",\ + strerror(errstat)); \ + } while(0) + +#define Vw(x) \ + do { int errstat; if ((errstat=rwl_writeunlock(&(x)))) \ + e_msg(__FILE__, __LINE__, M_ABORT, 0, "Write lock unlock failure. ERR=%s\n",\ + strerror(errstat)); \ + } while(0) + + /* * The digit following Dmsg and Emsg indicates the number of substitutions in * the message string. We need to do this kludge because non-GNU compilers diff --git a/bacula/src/cats/mysql.c b/bacula/src/cats/mysql.c index ff10b158d7..5ad818e7b0 100644 --- a/bacula/src/cats/mysql.c +++ b/bacula/src/cats/mysql.c @@ -101,13 +101,6 @@ db_open_database(B_DB *mdb) return 1; } mdb->connected = FALSE; -#ifdef needed - if (pthread_mutex_init(&mdb->mutex, NULL) != 0) { - Mmsg1(&mdb->errmsg, "Unable to initialize DB mutex. ERR=%s\n", strerror(errno)); - V(mutex); - return 0; - } -#endif if (rwl_init(&mdb->lock) != 0) { Mmsg1(&mdb->errmsg, "Unable to initialize DB lock. ERR=%s\n", strerror(errno)); diff --git a/bacula/src/dird/ua_cmds.c b/bacula/src/dird/ua_cmds.c index 5c45db6997..05079f4ac9 100644 --- a/bacula/src/dird/ua_cmds.c +++ b/bacula/src/dird/ua_cmds.c @@ -38,7 +38,6 @@ extern void run_job(JCR *jcr); extern int r_first; extern int r_last; extern struct s_res resources[]; -extern int console_msg_pending; extern char my_name[]; /* Imported functions */ diff --git a/bacula/src/dird/ua_dotcmds.c b/bacula/src/dird/ua_dotcmds.c index da22767ad3..3d46085e4c 100644 --- a/bacula/src/dird/ua_dotcmds.c +++ b/bacula/src/dird/ua_dotcmds.c @@ -39,7 +39,6 @@ extern int r_first; extern int r_last; extern struct s_res resources[]; -extern int console_msg_pending; extern char my_name[]; /* Imported functions */ diff --git a/bacula/src/dird/ua_output.c b/bacula/src/dird/ua_output.c index 2f1365e741..e62295aae6 100644 --- a/bacula/src/dird/ua_output.c +++ b/bacula/src/dird/ua_output.c @@ -41,7 +41,7 @@ extern int r_last; extern struct s_res resources[]; extern int console_msg_pending; extern FILE *con_fd; -extern pthread_mutex_t con_mutex; +extern brwlock_t con_lock; /* Imported functions */ @@ -321,13 +321,19 @@ int listcmd(UAContext *ua, char *cmd) return 1; } +static void con_lock_release(void *arg) +{ + Vw(con_lock); +} + void do_messages(UAContext *ua, char *cmd) { char msg[2000]; int mlen; int do_truncate = FALSE; - P(con_mutex); + Pw(con_lock); + pthread_cleanup_push(con_lock_release, (void *)NULL); rewind(con_fd); while (fgets(msg, sizeof(msg), con_fd)) { mlen = strlen(msg); @@ -342,7 +348,8 @@ void do_messages(UAContext *ua, char *cmd) } console_msg_pending = FALSE; ua->user_notified_msg_pending = FALSE; - V(con_mutex); + pthread_cleanup_pop(0); + Vw(con_lock); } diff --git a/bacula/src/lib/base64.c b/bacula/src/lib/base64.c index 80209919c4..b4459f5cbf 100644 --- a/bacula/src/lib/base64.c +++ b/bacula/src/lib/base64.c @@ -236,7 +236,7 @@ bin_to_base64(char *buf, char *bin, int len) for (i=0; i 1 && strcmp(argv[1], "-v") == 0) debug_level++; @@ -304,7 +312,7 @@ int main(int argc, char *argv[]) base64_init(); my_glob.gl_offs = 0; - glob("/etc/*", GLOB_MARK, errfunc, &my_glob); + glob("/etc/grub.conf", GLOB_MARK, errfunc, &my_glob); for (i=0; my_glob.gl_pathv[i]; i++) { fname = my_glob.gl_pathv[i]; @@ -313,12 +321,35 @@ int main(int argc, char *argv[]) continue; } encode_stat(where, &statp); + p = where; + p += to_base64((intmax_t)(statp.st_atime), p); + *p++ = ' '; + p += to_base64((intmax_t)t, p); + printf("%s %s\n", fname, where); + +#ifdef xxxx + printf("%s %lld\n", "st_dev", (intmax_t)statp.st_dev); + printf("%s %lld\n", "st_ino", (intmax_t)statp.st_ino); + printf("%s %lld\n", "st_mode", (intmax_t)statp.st_mode); + printf("%s %lld\n", "st_nlink", (intmax_t)statp.st_nlink); + printf("%s %lld\n", "st_uid", (intmax_t)statp.st_uid); + printf("%s %lld\n", "st_gid", (intmax_t)statp.st_gid); + printf("%s %lld\n", "st_rdev", (intmax_t)statp.st_rdev); + printf("%s %lld\n", "st_size", (intmax_t)statp.st_size); + printf("%s %lld\n", "st_blksize", (intmax_t)statp.st_blksize); + printf("%s %lld\n", "st_blocks", (intmax_t)statp.st_blocks); + printf("%s %lld\n", "st_atime", (intmax_t)statp.st_atime); + printf("%s %lld\n", "st_mtime", (intmax_t)statp.st_mtime); + printf("%s %lld\n", "st_ctime", (intmax_t)statp.st_ctime); +#endif + if (debug_level) printf("%s: len=%d val=%s\n", fname, strlen(where), where); decode_stat(where, &statn); +#ifdef xxx if (statp.st_dev != statn.st_dev || statp.st_ino != statn.st_ino || statp.st_mode != statn.st_mode || @@ -338,6 +369,7 @@ int main(int argc, char *argv[]) printf("%s: %s\n", fname, where); printf("NOT EQAL\n"); } +#endif } globfree(&my_glob); diff --git a/bacula/src/lib/message.c b/bacula/src/lib/message.c index cd9abfcbb7..66a89eaef4 100755 --- a/bacula/src/lib/message.c +++ b/bacula/src/lib/message.c @@ -43,7 +43,7 @@ char *exename = (char *)NULL; int console_msg_pending = 0; char con_fname[1000]; FILE *con_fd = NULL; -pthread_mutex_t con_mutex = PTHREAD_MUTEX_INITIALIZER; +brwlock_t con_lock; /* Forward referenced functions */ @@ -197,7 +197,7 @@ void init_console_msg(char *wd) sprintf(con_fname, "%s/%s.conmsg", wd, my_name); fd = open(con_fname, O_CREAT|O_RDWR|O_BINARY, 0600); if (fd == -1) { - Emsg2(M_ERROR_TERM, 0, "Could not open console message file %s: ERR=%s\n", + Emsg2(M_ERROR_TERM, 0, _("Could not open console message file %s: ERR=%s\n"), con_fname, strerror(errno)); } if (lseek(fd, 0, SEEK_END) > 0) { @@ -206,9 +206,13 @@ void init_console_msg(char *wd) close(fd); con_fd = fopen(con_fname, "a+"); if (!con_fd) { - Emsg2(M_ERROR, 0, "Could not open console message file %s: ERR=%s\n", + Emsg2(M_ERROR, 0, _("Could not open console message file %s: ERR=%s\n"), con_fname, strerror(errno)); } + if (rwl_init(&con_lock) != 0) { + Emsg1(M_ERROR_TERM, 0, _("Could not get con mutex: ERR=%s\n"), + strerror(errno)); + } } /* @@ -608,7 +612,7 @@ void dispatch_message(void *vjcr, int type, int level, char *msg) Dmsg0(200, "Console file not open.\n"); } if (con_fd) { - P(con_mutex); + Pw(con_lock); /* get write lock on console message file */ errno = 0; bstrftime(cmd, sizeof(cmd), time(NULL)); len = strlen(cmd); @@ -622,7 +626,7 @@ void dispatch_message(void *vjcr, int type, int level, char *msg) fwrite(msg, len, 1, con_fd); fflush(con_fd); console_msg_pending = TRUE; - V(con_mutex); + Vw(con_lock); } break; case MD_SYSLOG: diff --git a/bacula/src/lib/signal.c b/bacula/src/lib/signal.c index 153269cf81..50a0a46f6e 100644 --- a/bacula/src/lib/signal.c +++ b/bacula/src/lib/signal.c @@ -81,7 +81,7 @@ static void signal_handler(int sig) pid_t pid; fprintf(stderr, "Kaboom! %s, %s got signal %d. Attempting traceback.\n", - NPRT(exename), NPRT(my_name), sig); + exename, my_name, sig); if (strlen(exepath) + 12 > (int)sizeof(btpath)) { strcpy(btpath, "btraceback"); diff --git a/bacula/src/version.h b/bacula/src/version.h index 3a19e4931a..1c587928b5 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -1,8 +1,8 @@ /* */ #define VERSION "1.24" #define VSTRING "1" -#define DATE "06 August 2002" -#define LSMDATE "06Aug02" +#define DATE "07 August 2002" +#define LSMDATE "07Aug02" /* Debug flags */ #define DEBUG 1 -- 2.39.5