]> git.sur5r.net Git - bacula/bacula/commitdiff
Fix console race, base64 -- kes07Aug02
authorKern Sibbald <kern@sibbald.com>
Wed, 7 Aug 2002 11:09:12 +0000 (11:09 +0000)
committerKern Sibbald <kern@sibbald.com>
Wed, 7 Aug 2002 11:09:12 +0000 (11:09 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@80 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/baconfig.h
bacula/src/cats/mysql.c
bacula/src/dird/ua_cmds.c
bacula/src/dird/ua_dotcmds.c
bacula/src/dird/ua_output.c
bacula/src/lib/base64.c
bacula/src/lib/message.c
bacula/src/lib/signal.c
bacula/src/version.h

index fe8f4395cefad44ef5a6f7ff8bd8d9b035849171..37164ff39c20bc3183ba13644c1a426753d98d34 100644 (file)
@@ -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
index ff10b158d745f1e9cb0d026e8ba08e476aa4e945..5ad818e7b06d4642c7a968d9586b1b5878380c4c 100644 (file)
@@ -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));
index 5c45db69978b3b8aabb405119d757b7a11dd889d..05079f4ac9e8bd6ae0112a057a1e320814e21998 100644 (file)
@@ -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 */
index da22767ad33f19d94880d448ec8f050d37d2ffcb..3d46085e4c22d8a590dad15c0b5251a348b1216a 100644 (file)
@@ -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 */
index 2f1365e7416f3576c1f854d28478f0feb49040bb..e62295aae6f7eb5d8940ab1bbdd1ce11edac02ad 100644 (file)
@@ -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);
 }
 
 
index 80209919c4fed7cf9f5d4c1a7f5bd00256608b26..b4459f5cbf306ed61eba17d139b4a4750f9bce1a 100644 (file)
@@ -236,7 +236,7 @@ bin_to_base64(char *buf, char *bin, int len)
    for (i=0; i<len; ) {
       if (rem < 6) {
         reg <<= 8;
-        reg |= (uint8_t)bin[i++];
+        reg |= (int8_t)bin[i++];
         rem += 8;
       }
       save = reg;
@@ -265,11 +265,17 @@ int main(int argc, char *argv[])
    char junk[100];
    int i;
 
-   for (i=0; i < 100; i++) {
+#ifdef xxxx
+   for (i=0; i < 1000; i++) {
       bin_to_base64(buf, (char *)&xx, 4);
       printf("xx=%s\n", buf);
       xx++;
    }
+#endif
+   junk[0] = 0xFF;
+   for (i=1; i<100; i++) {
+      junk[i] = junk[i-1]-1;
+   }
    len = bin_to_base64(buf, junk, 16);
    printf("len=%d junk=%s\n", len, buf);
    return 0;
@@ -297,6 +303,8 @@ int main(int argc, char *argv[])
    struct stat statp;
    struct stat statn;
    int debug_level = 0;
+   char *p;
+   time_t t = 1028712799;
 
    if (argc > 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);
index cd9abfcbb7bd48f94653af714fd696bb38334e85..66a89eaef41a85834aeb165b809648c3aa8fa31a 100755 (executable)
@@ -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:
index 153269cf81c155903864015e5ae1f6c4b1129277..50a0a46f6e6886853a3cff18008f7d3384e110c9 100644 (file)
@@ -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");
index 3a19e4931ac6c25acc0f658baccc6f8fef26a6b8..1c587928b59e1cd7224a8ad87a01f7a216d987a0 100644 (file)
@@ -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