X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=server-src%2Flogfile.c;fp=server-src%2Flogfile.c;h=8bab3cfdf91a536aa8d8f897760db22b4bf74f9e;hb=691567b16c13087b31ee4c2b6d038e57872fae82;hp=c8ea268aa3fe74fdb5e34006aaa687125aff40f5;hpb=cc7d7b45afc706099acf7ff2490ec5667d370651;p=debian%2Famanda diff --git a/server-src/logfile.c b/server-src/logfile.c index c8ea268..8bab3cf 100644 --- a/server-src/logfile.c +++ b/server-src/logfile.c @@ -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++;