Imported Upstream version 2.4.5p1
[debian/amanda] / server-src / amlabel.c
index 4e0ae46b26a6ab8a76c553ee8bf4c1e3dd771a1d..b713fc0a384ec22d00de75639443a594a80fbec0 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.18.2.15.4.3.2.4.2.4 2005/10/02 13:48:42 martinea Exp $
  *
  * write an Amanda label on a tape
  */
@@ -63,7 +63,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,16 +85,7 @@ 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");
@@ -189,7 +183,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 +197,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 +240,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 +257,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 +273,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 +295,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);