tags 320742 patch stop Here's a patch that makes the "missingok" directive within a stanza apply to the glob of files it is meant to apply to.
If missingok is _not_ set and a glob fails, logrotate will still exit without processing any more stanzas & log files. If you think it should continue, just remove lines 71 and 72 of the patch. -- tp
Patch for Debian bugs #277652, #320742, #391439:
Logrotate breaks if unmatched glob pattern is found
This patch makes the "missingok" directive apply to the directory glob.
Patch by Ted Percival <[EMAIL PROTECTED]>, 2006-11-04.
--- logrotate-3.7.1/config.c 2003-08-07 21:13:14.000000000 +1000
+++ logrotate-3.7.1-new/config.c 2006-11-04 16:31:43.000000000 +1000
@@ -38,6 +38,7 @@
/* I shouldn't use globals here :-( */
static char ** tabooExts = NULL;
int tabooCount = 0;
+static int glob_errno = 0;
static int readConfigFile(const char * configFile, logInfo * defConfig,
logInfo ** logsPtr, int * numLogsPtr);
@@ -342,8 +343,7 @@
}
static int globerr(const char * pathname, int theerr) {
- message(MESS_ERROR, "error accessing %s: %s\n", pathname,
- strerror(theerr));
+ glob_errno = theerr;
/* We want the glob operation to abort on error, so return 1 */
return 1;
@@ -372,6 +372,7 @@
glob_t globResult;
const char ** argv;
int argc, argNum;
+ char *globerr_msg = NULL;
/* FIXME: createOwner and createGroup probably shouldn't be fixed
length arrays -- of course, if we aren't run setuid it doesn't
@@ -961,14 +962,21 @@
newlog->files = NULL;
newlog->numFiles = 0;
for (argNum = 0; argNum < argc; argNum++) {
+ if (globerr_msg) {
+ free(globerr_msg);
+ globerr_msg = NULL;
+ }
+
rc = glob(argv[argNum], GLOB_NOCHECK, globerr, &globResult);
if (rc == GLOB_ABORTED) {
- if(newlog->flags & LOG_FLAG_MISSINGOK)
- continue;
+ /* We don't yet know whether this stanza has "missingok"
+ * set, so store the error message for later. */
+ rc = asprintf(&globerr_msg, "%s:%d glob failed for %s: %s\n",
+ configFile, lineNum, argv[argNum], strerror(glob_errno));
+ if (rc == -1)
+ globerr_msg = NULL;
- message(MESS_ERROR, "%s:%d glob failed for %s\n",
- configFile, lineNum, argv[argNum]);
- return 1;
+ globResult.gl_pathc = 0;
}
newlog->files = realloc(newlog->files, sizeof(*newlog->files) *
@@ -1012,6 +1020,15 @@
return 1;
}
+ if (globerr_msg) {
+ if (!(newlog->flags & LOG_FLAG_MISSINGOK))
+ message(MESS_ERROR, globerr_msg);
+ free(globerr_msg);
+ globerr_msg = NULL;
+ if (!(newlog->flags & LOG_FLAG_MISSINGOK))
+ return 1;
+ }
+
if (newlog->oldDir) {
for (i = 0; i < newlog->numFiles; i++) {
char *ld;
signature.asc
Description: OpenPGP digital signature

