Bug#613342: Fix logrotate FTBFS for GNU/Hurd
Package: logrotate
Version: 3.7.8-6
Severity: important
Tags: patch, upstream
User: debian-hurd@lists.debian.org
Usertags: hurd
The attached patch fixes the dependency on PATH_MAX blocking the build
for GNU/Hurd. Should be applied last after the other patches in the
quilt series. Build tested on both GNU/Linux and GNU/Hurd. Also, all 14
checks in the test directory pass successfully after the build. Might be
applicable also for upstream?
diff -ur logrotate-3.7.8.orig//config.c ./logrotate-3.7.8/config.c
--- logrotate-3.7.8.orig//config.c 2011-02-12 18:00:44.000000000 +0100
+++ logrotate-3.7.8/config.c 2011-02-13 16:08:56.000000000 +0100
@@ -160,7 +160,7 @@
static int checkFile(const char *fname)
{
int i;
- char pattern[PATH_MAX];
+ char *pattern;
/* Check if fname is '.' or '..'; if so, return false */
if (fname[0] == '.' && (!fname[1] || (fname[1] == '.' && !fname[2])))
@@ -168,7 +168,7 @@
/* Check if fname is ending in a taboo-extension; if so, return false */
for (i = 0; i < tabooCount; i++) {
- snprintf(pattern, sizeof(pattern), "*%s", tabooExts[i]);
+ asprintf(&pattern, "*%s", tabooExts[i]);
if (!fnmatch(pattern, fname, 0))
{
message(MESS_DEBUG, "Ignoring %s, because of %s ending\n",
@@ -176,7 +176,7 @@
return 0;
}
}
-
+ free(pattern);
/* All checks have been passed; return true */
return 1;
}
diff -ur logrotate-3.7.8.orig//logrotate.c ./logrotate-3.7.8/logrotate.c
--- logrotate-3.7.8.orig//logrotate.c 2011-02-12 18:00:44.000000000 +0100
+++ logrotate-3.7.8/logrotate.c 2011-02-13 15:56:15.000000000 +0100
@@ -720,10 +720,6 @@
rotNames->baseName = strdup(ourBaseName(log->files[logNum]));
- oldName = alloca(PATH_MAX);
- newName = alloca(PATH_MAX);
- rotNames->disposeName = malloc(PATH_MAX);
-
if (log->extension &&
strncmp(&
(rotNames->
@@ -834,7 +830,7 @@
for (i = 0; i < globResult.gl_pathc && !hasErrors; i++) {
struct stat sbprev;
- snprintf(oldName, PATH_MAX, "%s", (globResult.gl_pathv)[i]);
+ asprintf(&oldName, "%s", (globResult.gl_pathv)[i]);
if (stat(oldName, &sbprev)) {
message(MESS_DEBUG,
"previous log %s does not exist\n",
@@ -847,15 +843,14 @@
message(MESS_DEBUG,
"glob finding logs to compress failed\n");
/* fallback to old behaviour */
- snprintf(oldName, PATH_MAX, "%s/%s.%d%s", rotNames->dirName,
+ asprintf(&oldName, "%s/%s.%d%s", rotNames->dirName,
rotNames->baseName, logStart, fileext);
}
globfree(&globResult);
free(glob_pattern);
} else {
struct stat sbprev;
-
- snprintf(oldName, PATH_MAX, "%s/%s.%d%s", rotNames->dirName,
+ asprintf(&oldName, "%s/%s.%d%s", rotNames->dirName,
rotNames->baseName, logStart, fileext);
if (stat(oldName, &sbprev)) {
message(MESS_DEBUG, "previous log %s does not exist\n",
@@ -912,7 +907,8 @@
}
if (mail_out != -1) {
/* oldName is oldest Backup found (for unlink later) */
- snprintf(oldName, PATH_MAX, "%s", (globResult.gl_pathv)[mail_out]);
+ asprintf(&oldName, "%s", (globResult.gl_pathv)[mail_out]);
+ rotNames->disposeName = malloc(strlen(oldName)+1);
strcpy(rotNames->disposeName, oldName);
} else {
free(rotNames->disposeName);
@@ -933,7 +929,7 @@
if (log->rotateAge) {
struct stat fst_buf;
for (i = 1; i <= rotateCount + 1; i++) {
- snprintf(oldName, PATH_MAX, "%s/%s.%d%s%s", rotNames->dirName,
+ asprintf(&oldName, "%s/%s.%d%s%s", rotNames->dirName,
rotNames->baseName, i, fileext, compext);
if (!stat(oldName, &fst_buf)
&& (((nowSecs - fst_buf.st_mtime) / 60 / 60 / 24)
@@ -949,11 +945,13 @@
}
}
- snprintf(oldName, PATH_MAX, "%s/%s.%d%s%s", rotNames->dirName,
+ asprintf(&oldName, "%s/%s.%d%s%s", rotNames->dirName,
rotNames->baseName, logStart + rotateCount, fileext,
compext);
+ newName = alloca(strlen(oldName)+1);
strcpy(newName, oldName);
+ rotNames->disposeName = malloc(strlen(oldName)+1);
strcpy(rotNames->disposeName, oldName);
sprintf(rotNames->firstRotated, "%s/%s.%d%s%s", rotNames->dirName,
@@ -996,10 +994,13 @@
}
#endif
for (i = rotateCount + logStart - 1; (i >= 0) && !hasErrors; i--) {
+ tmp = alloca(strlen(newName)+1);
tmp = newName;
+ newName = alloca(strlen(oldName)+1);
newName = oldName;
+ oldName = alloca(strlen(tmp)+1);
oldName = tmp;
- snprintf(oldName, PATH_MAX, "%s/%s.%d%s%s", rotNames->dirName,
+ asprintf(&oldName, "%s/%s.%d%s%s", rotNames->dirName,
rotNames->baseName, i, fileext, compext);
message(MESS_DEBUG,
@@ -1020,20 +1021,21 @@
} /* !LOG_FLAG_DATEEXT */
if (log->flags & LOG_FLAG_DATEEXT) {
- char *destFile = alloca(PATH_MAX);
+ char *destFile;
struct stat fst_buf;
if (asprintf(&(rotNames->finalName), "%s/%s%s%s", rotNames->dirName,
rotNames->baseName, dext_str, fileext) < 0) {
message(MESS_ERROR, "could not allocate finalName memory\n");
}
- snprintf(destFile, PATH_MAX, "%s%s", rotNames->finalName, compext);
+ asprintf(&destFile, "%s%s", rotNames->finalName, compext);
if (!stat(destFile, &fst_buf)) {
message(MESS_DEBUG,
"destination %s already exists, skipping rotation\n",
rotNames->firstRotated);
hasErrors = 1;
}
+ free(destFile);
} else {
/* note: the gzip extension is *not* used here! */
if (asprintf(&(rotNames->finalName), "%s/%s.%d%s", rotNames->dirName,
Reply to: