]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/dircmd.c
Escape filenames in restore command
[bacula/bacula] / bacula / src / stored / dircmd.c
index 8e9e01cb64c0fc2cd10467efb77c0932f7af582a..b8327afc5d0463c172116c483fee29adb98fe4a7 100644 (file)
@@ -19,7 +19,7 @@
  *  
  */
 /*
-   Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
+   Copyright (C) 2000-2003 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
@@ -69,6 +69,7 @@ static int unmount_cmd(JCR *jcr);
 static int status_cmd(JCR *sjcr);
 static void label_volume_if_ok(JCR *jcr, DEVICE *dev, char *vname, char *poolname, 
                               int Slot);
+static void send_blocked_status(JCR *jcr, DEVICE *dev);
 
 struct s_cmds {
    char *cmd;
@@ -105,7 +106,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 *connection_request(void *arg)
 {
    BSOCK *bs = (BSOCK *)arg;
    JCR *jcr;
@@ -115,7 +116,7 @@ void connection_request(void *arg)
 
    if (bnet_recv(bs) <= 0) {
       Emsg0(M_ERROR, 0, "Connection request failed.\n");
-      return;
+      return NULL;
    }
 
    /* 
@@ -123,7 +124,7 @@ void connection_request(void *arg)
     */
    if (sscanf(bs->msg, "Hello Start Job %127s calling\n", name) == 1) {
       handle_filed_connection(bs, name);
-      return;
+      return NULL;
    }
    
    jcr = new_jcr(sizeof(JCR), stored_free_jcr);     /* create Job Control Record */
@@ -137,7 +138,7 @@ void connection_request(void *arg)
    if (!authenticate_director(jcr)) {
       Jmsg(jcr, M_FATAL, 0, _("Unable to authenticate Director\n"));
       free_jcr(jcr);
-      return;
+      return NULL;
    }
    Dmsg0(90, "Message channel init completed.\n");
 
@@ -169,7 +170,7 @@ void connection_request(void *arg)
       bnet_sig(bs, BNET_TERMINATE);
    }
    free_jcr(jcr);
-   return;
+   return NULL;
 }
 
 /*
@@ -207,16 +208,15 @@ static int cancel_cmd(JCR *cjcr)
       } else {
         P(jcr->mutex);
         oldStatus = jcr->JobStatus;
-        jcr->JobStatus = JS_Cancelled;
-        if (!jcr->authenticated && jcr->JobStatus == JS_WaitFD) {
+        set_jcr_job_status(jcr, JS_Cancelled);
+        if (!jcr->authenticated && oldStatus == JS_WaitFD) {
            pthread_cond_signal(&jcr->job_start_wait); /* wake waiting thread */
         }
         V(jcr->mutex);
         if (jcr->file_bsock) {
            bnet_sig(jcr->file_bsock, BNET_TERMINATE);
         }
-         bnet_fsend(dir, _("3000 Job %s Status=%c marked to be cancelled.\n"), 
-           jcr->Job, oldStatus);
+         bnet_fsend(dir, _("3000 Job %s marked to be cancelled.\n"), jcr->Job);
         free_jcr(jcr);
       }
    } else {
@@ -468,7 +468,8 @@ static int mount_cmd(JCR *jcr)
                   bnet_fsend(dir, _("3001 Device %s is mounted with Volume %s\n"), 
                     dev->dev_name, dev->VolHdr.VolName);
               } else {
-                  bnet_fsend(dir, _("3905 Device %s open but no Bacula volume is mounted.\n"), 
+                  bnet_fsend(dir, _("3905 Device %s open but no Bacula volume is mounted.\n"
+                                    "Try unmounting and remounting the Volume.\n"),
                             dev->dev_name);
               }
               break;
@@ -488,7 +489,8 @@ static int mount_cmd(JCR *jcr)
                      bnet_fsend(dir, _("3001 Device %s is mounted with Volume %s\n"),
                        dev->dev_name, dev->VolHdr.VolName);
                  } else {
-                     bnet_fsend(dir, _("3905 Device %s open but no Bacula volume is mounted.\n"), 
+                     bnet_fsend(dir, _("3905 Device %s open but no Bacula volume is mounted.\n"   
+                                    "Try unmounting and remounting the Volume.\n"),
                                dev->dev_name);
                  }
               } else {
@@ -506,7 +508,8 @@ static int mount_cmd(JCR *jcr)
                      bnet_fsend(dir, _("3001 Device %s is mounted with Volume %s\n"), 
                        dev->dev_name, dev->VolHdr.VolName);
                  } else {
-                     bnet_fsend(dir, _("3905 Device %s open but no Bacula volume is mounted.\n"), 
+                     bnet_fsend(dir, _("3905 Device %s open but no Bacula volume is mounted.\n"
+                                       "Try unmounting and remounting the Volume.\n"),
                                dev->dev_name);
                  }
               }
@@ -565,7 +568,7 @@ static int unmount_cmd(JCR *jcr)
         } else if (dev->dev_blocked == BST_WAITING_FOR_SYSOP) {
             Dmsg2(90, "%d waiter dev_block=%d. doing unmount\n", dev->num_waiting,
               dev->dev_blocked);
-           if (dev->capabilities & CAP_OFFLINEUNMOUNT) {
+           if (dev_cap(dev, CAP_OFFLINEUNMOUNT)) {
               offline_dev(dev);
            }
            force_close_dev(dev);
@@ -594,7 +597,7 @@ static int unmount_cmd(JCR *jcr)
         } else {                     /* device not being used */
             Dmsg0(90, "Device not in use, unmounting\n");
            block_device(dev, BST_UNMOUNTED);
-           if (dev->capabilities & CAP_OFFLINEUNMOUNT) {
+           if (dev_cap(dev, CAP_OFFLINEUNMOUNT)) {
               offline_dev(dev);
            }
            force_close_dev(dev);
@@ -626,7 +629,7 @@ static int status_cmd(JCR *jcr)
    char dt[MAX_TIME_LENGTH];
    char b1[30], b2[30], b3[30];
 
-   bnet_fsend(user, "\n%s Version: " VERSION " (" DATE ")\n", my_name);
+   bnet_fsend(user, "\n%s Version: " VERSION " (" BDATE ")\n", my_name);
    bstrftime(dt, sizeof(dt), daemon_start_time);
    bnet_fsend(user, _("Daemon started %s, %d Job%s run.\n"), dt, last_job.NumJobs,
         last_job.NumJobs == 1 ? "" : "s");
@@ -645,8 +648,7 @@ static int status_cmd(JCR *jcr)
 
    LockRes();
    for (device=NULL;  (device=(DEVRES *)GetNextRes(R_DEVICE, (RES *)device)); ) {
-      dev = device->dev;
-      if (dev) {
+      for (dev=device->dev; dev; dev=dev->next) {
         if (dev->state & ST_OPENED) {
            if (dev->state & ST_LABEL) {
                bnet_fsend(user, _("Device %s is mounted with Volume %s\n"), 
@@ -654,29 +656,7 @@ static int status_cmd(JCR *jcr)
            } else {
                bnet_fsend(user, _("Device %s open but no Bacula volume is mounted.\n"), dev_name(dev));
            }
-           switch (dev->dev_blocked) {
-              case BST_UNMOUNTED:
-                  bnet_fsend(user, _("    Deviced is blocked. User unmounted.\n"));
-                 break;
-              case BST_UNMOUNTED_WAITING_FOR_SYSOP:
-                  bnet_fsend(user, _("    Deviced is blocked. User unmounted during wait for media/mount.\n"));
-                 break;
-              case BST_WAITING_FOR_SYSOP:
-                 if (jcr->JobStatus == JS_WaitMount) {
-                     bnet_fsend(user, _("    Device is blocked waiting for mount.\n"));
-                 } else {
-                     bnet_fsend(user, _("    Device is blocked waiting for appendable media.\n"));
-                 }
-                 break;
-              case BST_DOING_ACQUIRE:
-                  bnet_fsend(user, _("    Device is being initialized.\n"));
-                 break;
-              case BST_WRITING_LABEL:
-                  bnet_fsend(user, _("    Device is blocked labeling a Volume.\n"));
-                 break;
-              default:
-                 break;
-           }
+           send_blocked_status(jcr, dev);
            bpb = dev->VolCatInfo.VolCatBlocks;
            if (bpb <= 0) {
               bpb = 1;
@@ -692,6 +672,7 @@ static int status_cmd(JCR *jcr)
 
         } else {
             bnet_fsend(user, _("Device %s is not open.\n"), dev_name(dev));
+           send_blocked_status(jcr, dev);
         }
       }
    }
@@ -706,10 +687,11 @@ static int status_cmd(JCR *jcr)
            job_type_to_str(jcr->JobType), jcr->Job);
       }
       if (jcr->device) {
-         bnet_fsend(user, _("%s %s job %s is using device %s\n"), 
+         bnet_fsend(user, _("%s %s job %s is using device %s volume %s\n"), 
                   job_level_to_str(jcr->JobLevel),
                   job_type_to_str(jcr->JobType),
-                  jcr->Job, jcr->device->device_name);
+                  jcr->Job, jcr->device->device_name,
+                  jcr->VolumeName);
         sec = time(NULL) - jcr->run_time;
         if (sec <= 0) {
            sec = 1;
@@ -745,3 +727,32 @@ static int status_cmd(JCR *jcr)
    bnet_sig(user, BNET_EOD);
    return 1;
 }
+
+static void send_blocked_status(JCR *jcr, DEVICE *dev) 
+{
+   BSOCK *user = jcr->dir_bsock;
+
+   switch (dev->dev_blocked) {
+      case BST_UNMOUNTED:
+         bnet_fsend(user, _("    Device is BLOCKED. User unmounted.\n"));
+        break;
+      case BST_UNMOUNTED_WAITING_FOR_SYSOP:
+         bnet_fsend(user, _("    Device is BLOCKED. User unmounted during wait for media/mount.\n"));
+        break;
+      case BST_WAITING_FOR_SYSOP:
+        if (jcr->JobStatus == JS_WaitMount) {
+            bnet_fsend(user, _("    Device is BLOCKED waiting for mount.\n"));
+        } else {
+            bnet_fsend(user, _("    Device is BLOCKED waiting for appendable media.\n"));
+        }
+        break;
+      case BST_DOING_ACQUIRE:
+         bnet_fsend(user, _("    Device is being initialized.\n"));
+        break;
+      case BST_WRITING_LABEL:
+         bnet_fsend(user, _("    Device is blocked labeling a Volume.\n"));
+        break;
+      default:
+        break;
+   }
+}