Imported Upstream version 2.4.5p1
[debian/amanda] / server-src / dumper.c
index 48b8d1087aa8fae0ce222f567f4b65a4fb76d8a8..6afc7c052b0f6b10025c166aefce79b5e193572f 100644 (file)
@@ -23,7 +23,7 @@
  * Authors: the Amanda Development Team.  Its members are listed in a
  * file named AUTHORS, in the root directory of this distribution.
  */
-/* $Id: dumper.c,v 1.75.2.14.2.7.2.17 2003/10/30 18:09:27 martinea Exp $
+/* $Id: dumper.c,v 1.75.2.14.2.7.2.17.2.4 2005/09/20 21:31:52 jrjackson Exp $
  *
  * requests remote amandad processes to dump filesystems
  */
@@ -179,19 +179,10 @@ char **main_argv;
     unsigned long malloc_hist_2, malloc_size_2;
     char *conffile;
     char *q = NULL;
-    int fd;
     char *tmp_filename = NULL, *pc;
     int a;
 
-    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);
 
     set_pname("dumper");
 
@@ -668,7 +659,12 @@ int *p_outfd, size;
 
        NAUGHTY_BITS;
 
-       while(size > 0 && split_size > 0 && dumpsize >= split_size) {
+       /* We open a new chunkfile if                                    */
+       /*   We have something to write (dataout < datain)               */
+       /*   We have a split_size defined (split_size > 0)               */
+       /*   The current file is already filled (dumpsize >= split_size) */
+
+       while(dataout < datain && split_size > 0 && dumpsize >= split_size) {
            amfree(new_filename);
            if(use == 0) {
                /*
@@ -679,12 +675,13 @@ int *p_outfd, size;
                 if(cmd == CONTINUE) {
                    /*
                     * CONTINUE
+                    *   serial
                     *   filename
                     *   chunksize
                     *   use
                     */
                    cmdargs.argc++;             /* true count of args */
-                   a = 2;
+                   a = 3;
 
                    if(a >= cmdargs.argc) {
                        error("error [dumper CONTINUE: not enough args: filename]");
@@ -955,6 +952,12 @@ char *str;
            break;
        }
 #undef sc
+#define sc "sendbackup: warning"
+       if(strncmp(str, sc, sizeof(sc)-1) == 0) {
+           dump_result = max(dump_result, 1);
+           break;
+       }
+#undef sc
 #define sc "sendbackup: error"
        if(strncmp(str, sc, sizeof(sc)-1) == 0) {
            s += sizeof(sc)-1;
@@ -1214,9 +1217,7 @@ int mesgfd, datafd, indexfd, outfd;
                fprintf(stderr, "err dup2 out: %s\n", strerror(errno));
            if (dup2(tmpfd, 0) == -1)
                fprintf(stderr, "err dup2 in: %s\n", strerror(errno));
-           for(tmpfd = 3; tmpfd <= FD_SETSIZE; ++tmpfd) {
-               close(tmpfd);
-           }
+           safe_fd(-1, 0);
            /* now spawn gzip -1 to take care of the rest */
            execlp(COMPRESS_PATH, COMPRESS_PATH,
                   (srvcompress == srvcomp_best ? COMPRESS_BEST_OPT
@@ -1229,8 +1230,6 @@ int mesgfd, datafd, indexfd, outfd;
 
     indexpid = -1;
     if (indexfd != -1) {
-       int tmpfd;
-
        indexfile_real = getindexfname(hostname, diskname, datestamp, level),
        indexfile_tmp = stralloc2(indexfile_real, ".tmp");
 
@@ -1265,9 +1264,7 @@ int mesgfd, datafd, indexfd, outfd;
                error("err open %s: %s", indexfile_tmp, strerror(errno));
            if (dup2(indexfd,1) == -1)
                error("err dup2 out: %s", strerror(errno));
-           for(tmpfd = 3; tmpfd <= FD_SETSIZE; ++tmpfd) {
-               close(tmpfd);
-           }
+           safe_fd(-1, 0);
            execlp(COMPRESS_PATH, COMPRESS_PATH, COMPRESS_BEST_OPT, (char *)0);
            error("error: couldn't exec %s.", COMPRESS_PATH);
        }