fix syntax error in changelog
[debian/amanda] / server-src / amtape.c
index 11d002212e7cb743443e5710e67d5c98d89a9fde..365c1af73bd0c04b9c21e205ec8ab05a4b10cae9 100644 (file)
@@ -73,16 +73,12 @@ static const struct {
        T_("slot <slot #>        load tape from slot <slot #>") },
     { "slot" , load_slot,
        T_("slot current         load tape from current slot") },
-    { "slot" , load_slot,
-       T_("slot prev            load tape from previous slot") },
     { "slot" , load_slot,
        T_("slot next            load tape from next slot") },
     { "slot" , load_slot,
        T_("slot advance         advance to next slot but do not load") },
     { "slot" , load_slot,
        T_("slot first           load tape from first slot") },
-    { "slot" , load_slot,
-       T_("slot last            load tape from last slot") },
     { "label", load_label,
        T_("label <label>        find and load labeled tape") },
     { "taper", amtape_taper_scan,
@@ -135,20 +131,24 @@ main(
 
     dbopen(DBG_SUBDIR_SERVER);
 
-    malloc_size_1 = malloc_inuse(&malloc_hist_1);
-
     erroutput_type = ERR_INTERACTIVE;
 
     cfg_ovr = extract_commandline_config_overwrites(&argc, &argv);
     if(argc < 3) usage();
 
-    config_init(CONFIG_INIT_EXPLICIT_NAME | CONFIG_INIT_FATAL,
-               argv[1]);
+    config_init(CONFIG_INIT_EXPLICIT_NAME, argv[1]);
     apply_config_overwrites(cfg_ovr);
 
+    if (config_errors(NULL) >= CFGERR_WARNINGS) {
+       config_print_errors();
+       if (config_errors(NULL) >= CFGERR_ERRORS) {
+           g_critical(_("errors processing config file"));
+       }
+    }
+
     check_running_as(RUNNING_AS_DUMPUSER);
 
-    dbrename(config_name, DBG_SUBDIR_SERVER);
+    dbrename(get_config_name(), DBG_SUBDIR_SERVER);
 
     conf_tapelist = config_dir_relative(getconf_str(CNF_TAPELIST));
     if (read_tapelist(conf_tapelist)) {
@@ -158,7 +158,7 @@ main(
     amfree(conf_tapelist);
 
     if((have_changer = changer_init()) == 0) {
-       error(_("no tpchanger specified in \"%s\""), config_filename);
+       error(_("no tpchanger specified in \"%s\""), get_config_filename());
        /*NOTREACHED*/
     } else if (have_changer != 1) {
        error(_("changer initialization failed: %s"), strerror(errno));
@@ -191,9 +191,6 @@ reset_changer(G_GNUC_UNUSED int     argc,
               G_GNUC_UNUSED char ** argv) {
     char *slotstr = NULL;
 
-    (void)argc;        /* Quiet unused parameter warning */
-    (void)argv;        /* Quiet unused parameter warning */
-
     switch(changer_reset(&slotstr)) {
     case 0:
        g_fprintf(stderr, _("%s: changer is reset, slot %s is loaded.\n"),
@@ -217,9 +214,6 @@ clean_tape(G_GNUC_UNUSED int        argc,
            G_GNUC_UNUSED char ** argv) {
     char *devstr = NULL;
 
-    (void)argc;        /* Quiet unused parameter warning */
-    (void)argv;        /* Quiet unused parameter warning */
-
     if(changer_clean(&devstr) == 0) {
        g_fprintf(stderr, _("%s: device %s is clean.\n"), get_pname(), devstr);
     } else {
@@ -236,9 +230,6 @@ eject_tape(G_GNUC_UNUSED int        argc,
            G_GNUC_UNUSED char ** argv) {
     char *slotstr = NULL;
 
-    (void)argc;        /* Quiet unused parameter warning */
-    (void)argv;        /* Quiet unused parameter warning */
-
     if(changer_eject(&slotstr) == 0) {
        g_fprintf(stderr, _("%s: slot %3s is ejected.\n"), get_pname(), slotstr);
     } else {
@@ -257,7 +248,6 @@ load_slot(
     char **    argv)
 {
     char *slotstr = NULL, *devicename = NULL;
-    int is_advance;
     Device * device;
 
     if(argc != 2)
@@ -265,28 +255,25 @@ load_slot(
 
     device_api_init();
 
-    is_advance = (strcmp(argv[1], "advance") == 0);
+    if (strcmp(argv[1], "advance") == 0) {
+       argv[1] = "next";
+    }
+
     if(changer_loadslot(argv[1], &slotstr, &devicename)) {
        error(_("could not load slot %s: %s"), slotstr, changer_resultstr);
        /*NOTREACHED*/
     }
-    
-    if (!is_advance) {
-        device = device_open(devicename);
-        if (device == NULL) {
-            g_fprintf(stderr,
-                    _("%s: could not open device %s"), get_pname(),
-                    devicename);
-        } else {
-            g_object_unref(device);
-        }
-    }
 
-    g_fprintf(stderr, _("%s: changed to slot %s"), get_pname(), slotstr);
-    if(! is_advance) {
-       g_fprintf(stderr, _(" on %s"), devicename);
+    device = device_open(devicename);
+    g_assert(device != NULL);
+    if (device->status != DEVICE_STATUS_SUCCESS) {
+       g_fprintf(stderr,
+               _("%s: could not open device %s: %s"), get_pname(),
+               devicename, device_error(device));
     }
-    fputc('\n', stderr);
+    g_object_unref(device);
+
+    g_fprintf(stderr, _("%s: changed to slot %s on %s\n"), get_pname(), slotstr, devicename);
     amfree(slotstr);
     amfree(devicename);
 }
@@ -305,9 +292,6 @@ scan_init(G_GNUC_UNUSED void * data, int rc, G_GNUC_UNUSED int numslots,
        /*NOTREACHED*/
     }
 
-    nslots = ns;
-    backwards = bk;
-
     return 0;
 }
 
@@ -335,7 +319,7 @@ loadlabel_slot(
 {
     LabelChangerStatus * status = ud;
     Device * device;
-    ReadLabelStatusFlags label_status;
+    DeviceStatusFlags device_status;
 
     if (rc > 1) {
        error(_("could not load slot %s: %s"), slotstr, changer_resultstr);
@@ -347,22 +331,23 @@ loadlabel_slot(
     }
 
     device = device_open(device_name);
-    if (device == NULL) {
-        g_fprintf(stderr, _("%s: slot %3s: Could not open device.\n"),
-                get_pname(), slotstr);
+    g_assert(device != NULL);
+    if (device->status != DEVICE_STATUS_SUCCESS) {
+        g_fprintf(stderr, _("%s: slot %3s: Could not open device: %s.\n"),
+                  get_pname(), slotstr, device_error(device));
         return 0;
     }
-    
-    device_set_startup_properties_from_config(device);
-
-    label_status = device_read_label(device);
-    if (label_status != READ_LABEL_STATUS_SUCCESS) {
-        char * errstr = 
-            g_english_strjoinv_and_free
-                (g_flags_nick_to_strv(label_status,
-                                      READ_LABEL_STATUS_FLAGS_TYPE), "or");
+
+    if (!device_configure(device, TRUE)) {
+        g_fprintf(stderr, _("%s: slot %3s: Could not configure device: %s.\n"),
+                  get_pname(), slotstr, device_error(device));
+        return 0;
+    }
+
+    device_status = device_read_label(device);
+    if (device_status != DEVICE_STATUS_SUCCESS) {
         g_fprintf(stderr, _("%s: slot %3s: %s\n"),
-                get_pname(), slotstr, errstr);
+                  get_pname(), slotstr, device_error_or_status(device));
         g_object_unref(device);
         return 0;
     }
@@ -435,21 +420,23 @@ show_slots_slot(G_GNUC_UNUSED void * data, int rc, char * slotstr,
     }
 
     device = device_open(device_name);
-    if (device == NULL) {
-        g_fprintf(stderr, _("%s: slot %3s: Could not open device.\n"),
-                get_pname(), slotstr);
+    g_assert(device != NULL);
+    if (device->status != DEVICE_STATUS_SUCCESS) {
+        g_fprintf(stderr, _("%s: slot %3s: Could not open device: %s.\n"),
+                  get_pname(), slotstr, device_error(device));
     } else {
-        ReadLabelStatusFlags label_status;
-        device_set_startup_properties_from_config(device);
-        label_status = device_read_label(device);
-
-        if (label_status != READ_LABEL_STATUS_SUCCESS) {
-            char * errstr = 
-                g_english_strjoinv_and_free
-                (g_flags_nick_to_strv(label_status,
-                                      READ_LABEL_STATUS_FLAGS_TYPE), "or");
+        DeviceStatusFlags device_status;
+
+       if (!device_configure(device, TRUE)) {
+            g_fprintf(stderr, _("%s: slot %3s: %s\n"),
+                      get_pname(), slotstr, device_error_or_status(device));
+       }
+
+       device_status = device_read_label(device);
+
+        if (device_status != DEVICE_STATUS_SUCCESS) {
             g_fprintf(stderr, _("%s: slot %3s: %s\n"),
-                    get_pname(), slotstr, errstr);
+                      get_pname(), slotstr, device_error_or_status(device));
         } else {
             g_fprintf(stderr, _("slot %3s: time %-14s label %s\n"),
                     slotstr, device->volume_time, device->volume_label);
@@ -540,7 +527,7 @@ show_device(G_GNUC_UNUSED int       argc,
     char *slot = NULL, *device = NULL;
     
     if(changer_loadslot(_("current"), &slot, &device)) {
-       error(_("Could not load current slot.\n"));
+       error(_("could not load current slot: %s\n"), changer_resultstr);
        /*NOTREACHED*/
     }
 
@@ -548,48 +535,3 @@ show_device(G_GNUC_UNUSED int      argc,
     amfree(slot);
     amfree(device);
 }
-
-/* ---------------------------- */
-
-int
-update_one_slot(
-    void *     ud,
-    int                rc,
-    char *     slotstr,
-    char *     device)
-{
-    char *errstr = NULL;
-    char *datestamp = NULL;
-    char *label = NULL;
-
-    (void)ud;  /* Quiet unused parameter warning */
-
-    if(rc > 1)
-       error("could not load slot %s: %s", slotstr, changer_resultstr);
-    else if(rc == 1)
-       fprintf(stderr, "slot %s: %s\n", slotstr, changer_resultstr);
-    else if((errstr = tape_rdlabel(device, &datestamp, &label)) != NULL)
-       fprintf(stderr, "slot %s: %s\n", slotstr, errstr);
-    else {
-       fprintf(stderr, "slot %s: date %-8s label %s\n",
-               slotstr, datestamp, label);
-       changer_label(slotstr, label);
-    }
-    amfree(errstr);
-    amfree(datestamp);
-    amfree(label);
-    return 0;
-}
-
-void
-update_labeldb(
-    int                argc,
-    char **    argv)
-{
-    (void)argv;        /* Quiet unused parameter warning */
-
-    if(argc != 1)
-       usage();
-
-    changer_find(NULL, show_init_all, update_one_slot, NULL);
-}