]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/dircmd.c
First cut SIGHUM + misc
[bacula/bacula] / bacula / src / stored / dircmd.c
index bd309d569403ae305fde2eef343b0499f5e3ac2b..9a7560f4dca8c2243f4d513a2e27ddb5152795a8 100644 (file)
@@ -79,7 +79,7 @@ static void label_volume_if_ok(JCR *jcr, DEVICE *dev, char *oldname,
                               int Slot, int relabel);
 
 struct s_cmds {
-   char *cmd;
+   const char *cmd;
    int (*func)(JCR *jcr);
 };
 
@@ -118,7 +118,7 @@ static struct s_cmds cmds[] = {
  *  - We execute the command
  *  - We continue or exit depending on the return status
  */
-void *connection_request(void *arg)
+void *handle_connection_request(void *arg)
 {
    BSOCK *bs = (BSOCK *)arg;
    JCR *jcr;
@@ -129,6 +129,7 @@ void *connection_request(void *arg)
 
    if (bnet_recv(bs) <= 0) {
       Emsg0(M_ERROR, 0, _("Connection request failed.\n"));
+      bnet_close(bs);
       return NULL;
    }
 
@@ -137,19 +138,30 @@ void *connection_request(void *arg)
     */
    if (bs->msglen < 25 || bs->msglen > (int)sizeof(name)-25) {
       Emsg1(M_ERROR, 0, _("Invalid Dir connection. Len=%d\n"), bs->msglen);
+      bnet_close(bs);
+      return NULL;
    }
    /* 
     * See if this is a File daemon connection. If so
     *  call FD handler.
     */
-   if (sscanf(bs->msg, "Hello Start Job %127s calling\n", name) == 1) {
+   Dmsg1(110, "Conn: %s", bs->msg);
+   if (sscanf(bs->msg, "Hello Start Job %127s", name) == 1) {
       handle_filed_connection(bs, name);
       return NULL;
    }
    
+   Dmsg0(110, "Start Dir Job\n");
    jcr = new_jcr(sizeof(JCR), stored_free_jcr);     /* create Job Control Record */
    jcr->dir_bsock = bs;              /* save Director bsock */
    jcr->dir_bsock->jcr = jcr;
+   /* Initialize FD start condition variable */
+   int errstat = pthread_cond_init(&jcr->job_start_wait, NULL);
+   if (errstat != 0) {
+      Jmsg1(jcr, M_FATAL, 0, _("Unable to init job cond variable: ERR=%s\n"), strerror(errstat));
+      free_jcr(jcr);
+      return NULL;
+   }
 
    Dmsg0(1000, "stored in start_job\n");
 
@@ -354,15 +366,17 @@ static void label_volume_if_ok(JCR *jcr, DEVICE *dev, char *oldname,
    bsteal_lock_t hold;
    
    steal_device_lock(dev, &hold, BST_WRITING_LABEL);
+   block = new_block(dev);
    
    pm_strcpy(&jcr->VolumeName, newname);
    jcr->VolCatInfo.Slot = slot;
-   autoload_device(jcr, dev, 0, dir);     /* autoload if possible */
-   block = new_block(dev);
+   if (autoload_device(jcr, dev, 0, dir) < 0) {    /* autoload if possible */
+      goto bail_out;
+   }
 
    /* Ensure that the device is open -- autoload_device() closes it */
    for ( ; !(dev->state & ST_OPENED); ) {
-      if (open_dev(dev, jcr->VolumeName, READ_WRITE) < 0) {
+      if (open_dev(dev, jcr->VolumeName, OPEN_READ_WRITE) < 0) {
          bnet_fsend(dir, _("3910 Unable to open device %s. ERR=%s\n"), 
            dev_name(dev), strerror_dev(dev));
         goto bail_out;
@@ -389,7 +403,7 @@ static void label_volume_if_ok(JCR *jcr, DEVICE *dev, char *oldname,
       /* Fall through wanted! */
    case VOL_IO_ERROR:
    case VOL_NO_LABEL:
-      if (!write_volume_label_to_dev(jcr, jcr->device, newname, poolname)) {
+      if (!write_new_volume_label_to_dev(jcr, jcr->device, newname, poolname)) {
          bnet_fsend(dir, _("3912 Failed to label Volume: ERR=%s\n"), strerror_dev(dev));
         break;
       }
@@ -498,7 +512,7 @@ static int mount_cmd(JCR *jcr)
         case BST_UNMOUNTED_WAITING_FOR_SYSOP:
         case BST_UNMOUNTED:
            /* We freed the device, so reopen it and wake any waiting threads */
-           if (open_dev(dev, NULL, READ_WRITE) < 0) {
+           if (open_dev(dev, NULL, OPEN_READ_WRITE) < 0) {
                bnet_fsend(dir, _("3901 open device failed: ERR=%s\n"), 
                  strerror_dev(dev));
               break;
@@ -550,14 +564,14 @@ static int mount_cmd(JCR *jcr)
                   bnet_fsend(dir, _("3906 cannot mount non-tape.\n"));
                  break;
               }
-              if (open_dev(dev, NULL, READ_WRITE) < 0) {
+              if (open_dev(dev, NULL, OPEN_READ_WRITE) < 0) {
                   bnet_fsend(dir, _("3901 open device failed: ERR=%s\n"), 
                     strerror_dev(dev));
                  break;
               }
               read_label(jcr, dev);
               if (dev_state(dev, ST_LABEL)) {
-                  bnet_fsend(dir, _("3001 Device %s is mounted with Volume \"%s\"\n"), 
+                  bnet_fsend(dir, _("3001 Device %s is already mounted with Volume \"%s\"\n"), 
                     dev_name(dev), dev->VolHdr.VolName);
               } else {
                   bnet_fsend(dir, _("3905 Device %s open but no Bacula volume is mounted.\n"
@@ -830,15 +844,17 @@ static void read_volume_label(JCR *jcr, DEVICE *dev, int Slot)
    bsteal_lock_t hold;
    
    steal_device_lock(dev, &hold, BST_WRITING_LABEL);
+   block = new_block(dev);
    
    jcr->VolumeName[0] = 0;
    jcr->VolCatInfo.Slot = Slot;
-   autoload_device(jcr, dev, 0, dir);     /* autoload if possible */
-   block = new_block(dev);
+   if (autoload_device(jcr, dev, 0, dir) < 0) {    /* autoload if possible */
+      goto bail_out;
+   }
 
    /* Ensure that the device is open -- autoload_device() closes it */
    for ( ; !dev_state(dev, ST_OPENED); ) {
-      if (open_dev(dev, jcr->VolumeName, READ_WRITE) < 0) {
+      if (open_dev(dev, jcr->VolumeName, OPEN_READ_WRITE) < 0) {
          bnet_fsend(dir, _("3910 Unable to open device \"%s\". ERR=%s\n"), 
            dev_name(dev), strerror_dev(dev));
         goto bail_out;
@@ -848,7 +864,8 @@ static void read_volume_label(JCR *jcr, DEVICE *dev, int Slot)
    dev->state &= ~ST_LABEL;          /* force read of label */
    switch (read_dev_volume_label(jcr, dev, block)) {               
    case VOL_OK:
-      bnet_fsend(dir, _("3001 Volume=\"%s\" Slot=%d\n"), dev->VolHdr.VolName, Slot);
+      /* DO NOT add quotes around the Volume name. It is scanned in the DIR */
+      bnet_fsend(dir, _("3001 Volume=%s Slot=%d\n"), dev->VolHdr.VolName, Slot);
       Dmsg1(100, "Volume: %s\n", dev->VolHdr.VolName);
       break;
    default: