On Sat, 22 Jul 2006, Geert Uytterhoeven wrote:
> ---------- Forwarded message ----------
> Date: Fri, 14 Jul 2006 09:38:56 -0400
> From: Jean-Louis Martineau <[EMAIL PROTECTED]>
> To: amanda-users <amanda-users@amanda.org>,
>     Amanda Hackers <[EMAIL PROTECTED]>
> Subject: Release of amanda-2.5.1b1

> * work with tar-1.15.91

If you don't want to upgrade to 2.5.1b1 (or b2) yet, here's a backport of the
fix (`Use read/write to copy tar snapshot file.') in CVS.

--- amanda-2.5.0p2.orig/client-src/sendbackup-gnutar.c  2006-07-22 
11:14:26.000000000 +0200
+++ amanda-2.5.0p2/client-src/sendbackup-gnutar.c       2006-07-22 
10:48:30.000000000 +0200
@@ -147,6 +147,9 @@ static void start_backup(host, disk, amd
     char *error_pn = NULL;
     char *compopt  = NULL;
     char *encryptopt = skip_argument;
+    int infd, outfd;
+    ssize_t nb;
+    char buf[32768];
 
     error_pn = stralloc2(get_pname(), "-smbclient");
 
@@ -211,10 +214,7 @@ static void start_backup(host, disk, amd
        char *s;
        int ch;
        char *inputname = NULL;
-       FILE *in = NULL;
-       FILE *out;
        int baselevel;
-       char *line = NULL;
 
        basename = vstralloc(GNUTAR_LISTED_INCREMENTAL_DIR,
                             "/",
@@ -235,12 +235,13 @@ static void start_backup(host, disk, amd
        unlink(incrname);
 
        /*
-        * Open the listed incremental file for the previous level.  Search
+        * Open the listed incremental file from the previous level.  Search
         * backward until one is found.  If none are found (which will also
         * be true for a level 0), arrange to read from /dev/null.
         */
        baselevel = level;
-       while (in == NULL) {
+       infd = -1;
+       while (infd == -1) {
            if (--baselevel >= 0) {
                snprintf(number, sizeof(number), "%d", baselevel);
                inputname = newvstralloc(inputname,
@@ -248,7 +249,7 @@ static void start_backup(host, disk, amd
            } else {
                inputname = newstralloc(inputname, "/dev/null");
            }
-           if ((in = fopen(inputname, "r")) == NULL) {
+           if ((infd = open(inputname, O_RDONLY)) == -1) {
                int save_errno = errno;
 
                dbprintf(("%s: error opening %s: %s\n",
@@ -264,28 +265,27 @@ static void start_backup(host, disk, amd
        /*
         * Copy the previous listed incremental file to the new one.
         */
-       if ((out = fopen(incrname, "w")) == NULL) {
+       if ((outfd = open(incrname, O_WRONLY|O_CREAT, 0600)) == -1) {
            error("error [opening %s: %s]", incrname, strerror(errno));
        }
 
-       for (; (line = agets(in)) != NULL; free(line)) {
-           if(fputs(line, out) == EOF || putc('\n', out) == EOF) {
-               error("error [writing to %s: %s]", incrname, strerror(errno));
+       while ((nb = read(infd, &buf, sizeof(buf))) > 0) {
+           if (fullwrite(outfd, &buf, nb) < nb) {
+               error("error [writing to '%s': %s]", incrname,
+                      strerror(errno));
            }
        }
-       amfree(line);
 
-       if (ferror(in)) {
+       if (nb < 0) {
            error("error [reading from %s: %s]", inputname, strerror(errno));
        }
-       if (fclose(in) == EOF) {
+
+       if (close(infd) != 0) {
            error("error [closing %s: %s]", inputname, strerror(errno));
        }
-       in = NULL;
-       if (fclose(out) == EOF) {
+       if (close(outfd) != 0) {
            error("error [closing %s: %s]", incrname, strerror(errno));
        }
-       out = NULL;
 
        dbprintf(("%s: doing level %d dump as listed-incremental",
                  debug_prefix_time("-gnutar"), level));
--- amanda-2.5.0p2.orig/client-src/sendsize.c   2006-07-22 11:14:26.000000000 
+0200
+++ amanda-2.5.0p2/client-src/sendsize.c        2006-07-22 10:59:36.000000000 
+0200
@@ -1454,6 +1454,9 @@ time_t dumpsince;
     char *file_exclude = NULL;
     char *file_include = NULL;
     times_t start_time;
+    int infd, outfd;
+    ssize_t nb;
+    char buf[32768];
 
     if(options->exclude_file) nb_exclude += options->exclude_file->nb_element;
     if(options->exclude_list) nb_exclude += options->exclude_list->nb_element;
@@ -1497,7 +1500,8 @@ time_t dumpsince;
         * be true for a level 0), arrange to read from /dev/null.
         */
        baselevel = level;
-       while (in == NULL) {
+       infd = -1;
+       while (infd == -1) {
            if (--baselevel >= 0) {
                snprintf(number, sizeof(number), "%d", baselevel);
                inputname = newvstralloc(inputname,
@@ -1505,7 +1509,7 @@ time_t dumpsince;
            } else {
                inputname = newstralloc(inputname, "/dev/null");
            }
-           if ((in = fopen(inputname, "r")) == NULL) {
+           if ((infd = open(inputname, O_RDONLY)) == -1) {
                int save_errno = errno;
 
                dbprintf(("%s: gnutar: error opening %s: %s\n",
@@ -1519,40 +1523,36 @@ time_t dumpsince;
        /*
         * Copy the previous listed incremental file to the new one.
         */
-       if ((out = fopen(incrname, "w")) == NULL) {
+       if ((outfd = open(incrname, O_WRONLY|O_CREAT, 0600)) == -1) {
            dbprintf(("%s: opening %s: %s\n",
                      debug_prefix(NULL), incrname, strerror(errno)));
            goto common_exit;
        }
 
-       for (; (line = agets(in)) != NULL; free(line)) {
-           if (fputs(line, out) == EOF || putc('\n', out) == EOF) {
+       while ((nb = read(infd, &buf, sizeof(buf))) > 0) {
+           if (fullwrite(outfd, &buf, nb) < nb) {
                dbprintf(("%s: writing to %s: %s\n",
                           debug_prefix(NULL), incrname, strerror(errno)));
                goto common_exit;
            }
        }
-       amfree(line);
 
-       if (ferror(in)) {
+       if (nb < 0) {
            dbprintf(("%s: reading from %s: %s\n",
                      debug_prefix(NULL), inputname, strerror(errno)));
            goto common_exit;
        }
-       if (fclose(in) == EOF) {
+
+       if (close(infd) != 0) {
            dbprintf(("%s: closing %s: %s\n",
                      debug_prefix(NULL), inputname, strerror(errno)));
-           in = NULL;
            goto common_exit;
        }
-       in = NULL;
-       if (fclose(out) == EOF) {
+       if (close(outfd) != 0) {
            dbprintf(("%s: closing %s: %s\n",
                      debug_prefix(NULL), incrname, strerror(errno)));
-           out = NULL;
            goto common_exit;
        }
-       out = NULL;
 
        amfree(inputname);
        amfree(basename);

Gr{oetje,eeting}s,

                                                Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [EMAIL PROTECTED]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                                            -- Linus Torvalds


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to