Imported Upstream version 3.3.3
[debian/amanda] / server-src / logfile.c
index c8ea268aa3fe74fdb5e34006aaa687125aff40f5..8bab3cfdf91a536aa8d8f897760db22b4bf74f9e 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Amanda, The Advanced Maryland Automatic Network Disk Archiver
  * Copyright (c) 1991-1998 University of Maryland at College Park
+ * Copyright (c) 2007-2012 Zmanda, Inc.  All Rights Reserved.
  * All Rights Reserved.
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
@@ -218,9 +219,8 @@ log_rename(
     }
 
     if(rename(logfile, fname) == -1) {
-       error(_("could not rename \"%s\" to \"%s\": %s"),
+       g_debug(_("could not rename \"%s\" to \"%s\": %s"),
              logfile, fname, strerror(errno));
-       /*NOTREACHED*/
     }
 
     amfree(fname);
@@ -276,17 +276,44 @@ get_logline(
     FILE *     logf)
 {
     static char *logline = NULL;
+    static size_t line_size = 0;
+    char *lline;
+    size_t loffset = 0;
     char *logstr, *progstr;
     char *s;
     int ch;
+    int n;
 
-    amfree(logline);
-    while ((logline = agets(logf)) != NULL) {
-       if (logline[0] != '\0')
-           break;
-       amfree(logline);
+    if (!logline) {
+       line_size = 256;
+       logline = g_malloc(line_size);
+    }
+
+    logline[0] = '\0';
+    while(1) {
+       lline = fgets(logline + loffset, line_size - loffset, logf);
+       if (lline == NULL) {
+           break; /* EOF */
+       }
+       if (strlen(logline) == line_size -1 &&
+                  logline[strlen(logline)-1] != '\n') {
+           line_size *= 2;
+           logline = g_realloc(logline, line_size);
+           loffset = strlen(logline);
+       } else if (strlen(logline) == 0 ||
+                  (strlen(logline) == 1 && logline[0] == '\n')) {
+       } else {
+           break; /* good line */
+       }
+       logline[loffset] = '\0';
     }
-    if (logline == NULL) return 0;
+    if (logline[0] == '\0')
+       return 0;
+
+    /* remove \n */
+    n = strlen(logline);
+    if (logline[n-1] == '\n') logline[n-1] = '\0';
+
     curlinenum++;
     s = logline;
     ch = *s++;