Imported Debian patch 2.5.0-1
[debian/amanda] / server-src / amlabel.c
index 4e0ae46b26a6ab8a76c553ee8bf4c1e3dd771a1d..b7bdc4ca04bfd00f805a306c409418ff385f1af6 100644 (file)
@@ -24,7 +24,7 @@
  * file named AUTHORS, in the root directory of this distribution.
  */
 /*
- * $Id: amlabel.c,v 1.18.2.15.4.3.2.4 2003/01/01 23:28:53 martinea Exp $
+ * $Id: amlabel.c,v 1.43 2006/01/14 04:37:19 paddy_s Exp $
  *
  * write an Amanda label on a tape
  */
@@ -40,6 +40,7 @@
 
 /* local functions */
 
+int main P((int, char **));
 void usage P((char *argv0));
 
 void usage(argv0)
@@ -63,7 +64,10 @@ int main(argc, argv)
     char *conf_tapelist_old;
     unsigned long malloc_hist_1, malloc_size_1;
     unsigned long malloc_hist_2, malloc_size_2;
-    int fd;
+#ifdef HAVE_LINUX_ZFTAPE_H
+    int fd = -1;
+    int isa_zftape;
+#endif /* HAVE_LINUX_ZFTAPE_H */
     int have_changer;
     int force, tape_ok;
     tape_t *tp;
@@ -82,20 +86,13 @@ int main(argc, argv)
     int first_seg, last_seg;
 #endif /* HAVE_LIBVTBLC */
 
-    for(fd = 3; fd < FD_SETSIZE; fd++) {
-       /*
-        * Make sure nobody spoofs us with a lot of extra open files
-        * that would cause an open we do to get a very high file
-        * descriptor, which in turn might be used as an index into
-        * an array (e.g. an fd_set).
-        */
-       close(fd);
-    }
-
+    safe_fd(-1, 0);
     safe_cd();
 
     set_pname("amlabel");
-    dbopen();
+
+    /* Don't die when child closes pipe */
+    signal(SIGPIPE, SIG_IGN);
 
     malloc_size_1 = malloc_inuse(&malloc_hist_1);
 
@@ -126,6 +123,7 @@ int main(argc, argv)
     if (read_conffile(conffile)) {
        error("errors processing config file \"%s\"", conffile);
     }
+
     conf_tapelist = getconf_str(CNF_TAPELIST);
     if (*conf_tapelist == '/') {
        conf_tapelist = stralloc(conf_tapelist);
@@ -189,7 +187,8 @@ int main(argc, argv)
     }
 
 #ifdef HAVE_LINUX_ZFTAPE_H
-    if (is_zftape(tapename) == 1){
+    isa_zftape = is_zftape(tapename);
+    if (isa_zftape) {
        if((fd = tape_open(tapename, O_WRONLY)) == -1) {
            errstr = newstralloc2(errstr, "amlabel: ",
                                  (errno == EACCES) ? "tape is write-protected"
@@ -202,7 +201,7 @@ int main(argc, argv)
     printf("rewinding"); fflush(stdout);
 
 #ifdef HAVE_LINUX_ZFTAPE_H
-    if (is_zftape(tapename) == 1){
+    if (isa_zftape) {
        if(tapefd_rewind(fd) == -1) {
            putchar('\n');
            error(strerror(errno));
@@ -245,7 +244,7 @@ int main(argc, argv)
     printf("rewinding"); fflush(stdout);
 
 #ifdef HAVE_LINUX_ZFTAPE_H
-    if (is_zftape(tapename) == 1){
+    if (isa_zftape) {
        if(tapefd_rewind(fd) == -1) {
            putchar('\n');
            error(strerror(errno));
@@ -262,7 +261,7 @@ int main(argc, argv)
        printf(", writing label %s", label); fflush(stdout);
 
 #ifdef HAVE_LINUX_ZFTAPE_H
-       if (is_zftape(tapename) == 1){
+       if (isa_zftape) {
            errstr = tapefd_wrlabel(fd, "X", label, tt_blocksize_kb * 1024);
            if(errstr != NULL) {
                putchar('\n');
@@ -278,13 +277,13 @@ int main(argc, argv)
        }
 
 #ifdef HAVE_LINUX_ZFTAPE_H
-       if (is_zftape(tapename) == 1){
+       if (isa_zftape) {
            tapefd_weof(fd, 1);
        }
 #endif /* HAVE_LINUX_ZFTAPE_H */
 
 #ifdef HAVE_LINUX_ZFTAPE_H
-       if (is_zftape(tapename) == 1){
+       if (isa_zftape) {
            errstr = tapefd_wrendmark(fd, "X", tt_blocksize_kb * 1024);
            if(errstr != NULL) {
                putchar('\n');
@@ -300,7 +299,7 @@ int main(argc, argv)
        }
 
 #ifdef HAVE_LINUX_ZFTAPE_H
-       if (is_zftape(tapename) == 1){
+       if (isa_zftape) {
            tapefd_weof(fd, 1);
 
            printf(",\nrewinding"); fflush(stdout); 
@@ -415,8 +414,8 @@ int main(argc, argv)
        } /* write tape list */
 
         if(have_changer) {
-           /* Now we try to inform the changer, about the new label */
-           changer_label(outslot,label); 
+           /*  Now we try to inform the changer, about the new label */
+           /* changer_label(outslot,label); */
        }
        printf(", done.\n");
     } else {
@@ -436,6 +435,5 @@ int main(argc, argv)
        malloc_list(fileno(stderr), malloc_hist_1, malloc_hist_2);
     }
 
-    dbclose();
     return 0;
 }