ldap/servers/slapd/log.c | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
New commits:
commit 3bcba2416c21f2c297ade289f17549ae2bc6b4e9
Author: Noriko Hosoi <nhosoi(a)redhat.com>
Date: Wed Jan 12 11:27:35 2011 -0800
Bug 615100 - log rotationinfo always recreated at startup,
and corrupted on some platforms
https://bugzilla.redhat.com/show_bug.cgi?id=615100
Description:
1) At startup log__check_prevlogs() verifies that all logs are
referenced in the rotationinfo file. If the rotationinfo file
doesn't reference all the present log files, it will recreate
the rotationinfo file based on the log files that are present.
However, the logic to break out of the loop that performs the
verification is incorrect so it always considers the rotationinfo
file to be bogus and recreates it. I've corrected the logic.
2) Recreating the rotationinfo file isn't bad per se, but the
code that recreates the rotationinfo file is also broken on HP-UX
(and probably Solaris). It tries to use the libc function strptime()
to format a date such as "20100128-153532" into a struct tm, so that
it can create an epoch date from there. The format string being
used for strptime() is "%Y%m%d-%H%M%S", which works on Linux, but
the strptime() function requires whitespace or alpha-numeric
separators between format specifiers on HP-UX (and Solaris according
to their man page), so strptime() fails. My fix here was to convert
the compact date string into a string in ISO8601-like format with
separators so strptime() can parse it.
This patch was provided by Ulf Weltman (ulf.weltman(a)hp.com).
diff --git a/ldap/servers/slapd/log.c b/ldap/servers/slapd/log.c
index e4e98ce..98090e8 100644
--- a/ldap/servers/slapd/log.c
+++ b/ldap/servers/slapd/log.c
@@ -33,6 +33,7 @@
*
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
* Copyright (C) 2005 Red Hat, Inc.
+ * Copyright (C) 2010 Hewlett-Packard Development Company, L.P.
* All rights reserved.
* END COPYRIGHT BLOCK **/
@@ -2804,14 +2805,16 @@ log__check_prevlogs (FILE *fp, char *pathname)
fseek(fp, 0 ,SEEK_SET);
buf[BUFSIZ-1] = '\0';
+ rval = LOG_ERROR; /* pessmistic default */
while (fgets(buf, BUFSIZ - 1, fp)) {
if (strstr(buf, dirent->name)) {
rval = LOG_CONTINUE; /* found in .rotationinfo */
- continue;
- }
+ break;
+ }
+ }
+ if(LOG_ERROR == rval) {
+ goto done;
}
- rval = LOG_ERROR; /* not found in .rotationinfo */
- break;
}
}
done:
@@ -4101,8 +4104,18 @@ log_reverse_convert_time(char *tbuf)
{
struct tm tm = {0};
- if (strchr(tbuf, '-')) { /* short format */
- strptime(tbuf, "%Y%m%d-%H%M%S", &tm);
+ if (strchr(tbuf, '-') && strlen(tbuf) >= 15) {
+ /* short format: YYYYmmdd-HHMMSS
+ strptime requires whitespace or non-alpha characters between format
+ specifiers on some platforms, so convert to an ISO8601-like format
+ with separators */
+ char tbuf_with_sep[] = "yyyy-mm-dd HH:MM:SS";
+ if( sscanf(tbuf, "%4c%2c%2c-%2c%2c%2c", tbuf_with_sep,
+ tbuf_with_sep+5, tbuf_with_sep+8, tbuf_with_sep+11,
+ tbuf_with_sep+14, tbuf_with_sep+17) != 6 ) {
+ return 0;
+ }
+ strptime(tbuf_with_sep, "%Y-%m-%d %H:%M:%S", &tm);
} else if (strchr(tbuf, '/') && strchr(tbuf, ':')) { /* long
format */
strptime(tbuf, "%d/%b/%Y:%H:%M:%S", &tm);
} else {