]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/dev.c
Add address and socket for MySQL
[bacula/bacula] / bacula / src / stored / dev.c
index 695acd5541619008e42e8ae8d12425dbdd67ff74..e19032544d6251c6092e8edbf9a52f437bbdeef8 100644 (file)
@@ -153,6 +153,7 @@ init_dev(DEVICE *dev, DEVRES *device)
    dev->volume_capacity = device->volume_capacity;
    dev->max_rewind_wait = device->max_rewind_wait;
    dev->max_open_wait = device->max_open_wait;
+   dev->max_open_vols = device->max_open_vols;
    dev->device = device;
 
    if (tape) {
@@ -248,6 +249,10 @@ open_dev(DEVICE *dev, char *VolName, int mode)
       }
       timeout = dev->max_open_wait;
       errno = 0;
+      if (dev->state & ST_FIFO && timeout) {
+        /* Set open timer */
+        dev->tid = start_thread_timer(pthread_self(), timeout);
+      }
       /* If busy retry each second for max_open_wait seconds */
       while ((dev->fd = open(dev->dev_name, dev->mode, MODE_RW)) < 0) {
         if (errno == EAGAIN) {
@@ -261,6 +266,11 @@ open_dev(DEVICE *dev, char *VolName, int mode)
         dev->dev_errno = errno;
          Mmsg2(&dev->errmsg, _("stored: unable to open device %s: ERR=%s\n"), 
               dev->dev_name, strerror(dev->dev_errno));
+        /* Stop any open timer we set */
+        if (dev->tid) {
+           stop_thread_timer(dev->tid);
+           dev->tid = 0;
+        }
         Emsg0(M_FATAL, 0, dev->errmsg);
         break;
       }
@@ -270,6 +280,11 @@ open_dev(DEVICE *dev, char *VolName, int mode)
         dev->use_count++;
         update_pos_dev(dev);             /* update position */
       }
+      /* Stop any open() timer we started */
+      if (dev->tid) {
+        stop_thread_timer(dev->tid);
+        dev->tid = 0;
+      }
       Dmsg1(29, "open_dev: tape %d opened\n", dev->fd);
    } else {
       /*
@@ -291,7 +306,8 @@ open_dev(DEVICE *dev, char *VolName, int mode)
       } else {
          Emsg0(M_ABORT, 0, _("Illegal mode given to open_dev.\n")); 
       }
-      if ((dev->fd = open(archive_name, dev->mode, MODE_RW)) < 0) {
+      /* If creating file, give 0640 permissions */
+      if ((dev->fd = open(archive_name, dev->mode, 0640)) < 0) {
         dev->dev_errno = errno;
          Mmsg2(&dev->errmsg, _("Could not open: %s, ERR=%s\n"), archive_name, strerror(dev->dev_errno));
         Emsg0(M_FATAL, 0, dev->errmsg);
@@ -1007,6 +1023,10 @@ static void do_close(DEVICE *dev)
    memset(&dev->VolCatInfo, 0, sizeof(dev->VolCatInfo));
    memset(&dev->VolHdr, 0, sizeof(dev->VolHdr));
    dev->use_count--;
+   if (dev->tid) {
+      stop_thread_timer(dev->tid);
+      dev->tid = 0;
+   }
 }
 
 /* 
@@ -1096,7 +1116,7 @@ term_dev(DEVICE *dev)
       Emsg0(M_FATAL, 0, dev->errmsg);
       return;
    }
-   close_dev(dev);
+   do_close(dev);
    Dmsg0(29, "term_dev\n");
    if (dev->dev_name) {
       free_memory(dev->dev_name);