From 71c2315b76ef0d5408bfa37c31ad1b5a27e2b3e7 Mon Sep 17 00:00:00 2001
From: Kamil Dudka <kdudka@redhat.com>
Date: Wed, 7 Dec 2016 10:39:55 +0100
Subject: [PATCH 1/4] config.c: skip a duplicated log entry but continue
reading
... other entries which are not duplicated.
Closes #81
Upstream-commit: 06ede862d319efc98942536cba11bdfdbdc9cc72
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
config.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/config.c b/config.c
index 2a610de..aaf4fbb 100644
--- a/config.c
+++ b/config.c
@@ -1389,7 +1389,7 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig)
newlog->files = NULL;
newlog->numFiles = 0;
- for (argNum = 0; argNum < argc && logerror != 1; argNum++) {
+ for (argNum = 0; argNum < argc; argNum++) {
if (globerr_msg) {
free(globerr_msg);
globerr_msg = NULL;
@@ -1672,7 +1672,7 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig)
munmap(buf, (size_t) length);
close(fd);
- return 0;
+ return logerror;
error:
if (key)
free(key);
--
2.20.1
From 9915dc4c4bf84b1ff16f34d7d34178098a03cf7c Mon Sep 17 00:00:00 2001
From: Kamil Dudka <kdudka@redhat.com>
Date: Mon, 2 Jan 2017 20:35:17 +0100
Subject: [PATCH 2/4] config.c: recover from failures of readConfigFile()
Closes #81
Upstream-commit: 56598fd1e9338b45ba3e1bda1b91522e75b40e06
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
config.c | 30 ++++++++++++++----------------
1 file changed, 14 insertions(+), 16 deletions(-)
diff --git a/config.c b/config.c
index aaf4fbb..203b3e3 100644
--- a/config.c
+++ b/config.c
@@ -510,8 +510,8 @@ static void freeTailLogs(int num)
static int readConfigPath(const char *path, struct logInfo *defConfig)
{
struct stat sb;
- int here, oldnumlogs, result = 1;
- struct logInfo defConfigBackup;
+ int here, result = 1;
+ struct logInfo defConfigBackup;
if (stat(path, &sb)) {
message(MESS_ERROR, "cannot stat %s: %s\n", path, strerror(errno));
@@ -588,11 +588,9 @@ static int readConfigPath(const char *path, struct logInfo *defConfig)
for (i = 0; i < files_count; ++i) {
assert(namelist[i] != NULL);
- oldnumlogs = numLogs;
copyLogInfo(&defConfigBackup, defConfig);
if (readConfigFile(namelist[i], defConfig)) {
message(MESS_ERROR, "found error in file %s, skipping\n", namelist[i]);
- freeTailLogs(numLogs - oldnumlogs);
freeLogInfo(defConfig);
copyLogInfo(defConfig, &defConfigBackup);
freeLogInfo(&defConfigBackup);
@@ -609,10 +607,8 @@ static int readConfigPath(const char *path, struct logInfo *defConfig)
close(here);
free_2d_array(namelist, files_count);
} else {
- oldnumlogs = numLogs;
copyLogInfo(&defConfigBackup, defConfig);
if (readConfigFile(path, defConfig)) {
- freeTailLogs(numLogs - oldnumlogs);
freeLogInfo(defConfig);
copyLogInfo(defConfig, &defConfigBackup);
} else {
@@ -678,10 +674,8 @@ int readAllConfigPaths(const char **paths)
}
for (file = paths; *file; file++) {
- if (readConfigPath(*file, &defConfig)) {
+ if (readConfigPath(*file, &defConfig))
result = 1;
- break;
- }
}
free_2d_array(tabooExts, tabooCount);
freeLogInfo(&defConfig);
@@ -1207,17 +1201,21 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig)
&buf, length)) != NULL) {
message(MESS_DEBUG, "including %s\n", key);
- if (++recursion_depth > MAX_NESTING) {
+ if (recursion_depth >= MAX_NESTING) {
message(MESS_ERROR, "%s:%d include nesting too deep\n",
configFile, lineNum);
- --recursion_depth;
- goto error;
- }
- if (readConfigPath(key, newlog)) {
- --recursion_depth;
- goto error;
+ logerror = 1;
+ continue;
}
+
+ ++recursion_depth;
+ rv = readConfigPath(key, newlog);
--recursion_depth;
+
+ if (rv) {
+ logerror = 1;
+ continue;
+ }
}
else continue;
} else if (!strcmp(key, "olddir")) {
--
2.20.1
From ed099a0321e799d4be72f9096532bb976680aad8 Mon Sep 17 00:00:00 2001
From: Kamil Dudka <kdudka@redhat.com>
Date: Thu, 12 Jan 2017 08:44:39 +0100
Subject: [PATCH 3/4] config.c: propagate errors from readConfigFile() properly
Closes #81
Upstream-commit: 6a75cdeab61a29ea99d49a85461f597c1d8d055c
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
config.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/config.c b/config.c
index 203b3e3..72981b0 100644
--- a/config.c
+++ b/config.c
@@ -510,7 +510,7 @@ static void freeTailLogs(int num)
static int readConfigPath(const char *path, struct logInfo *defConfig)
{
struct stat sb;
- int here, result = 1;
+ int here, result = 0;
struct logInfo defConfigBackup;
if (stat(path, &sb)) {
@@ -594,9 +594,8 @@ static int readConfigPath(const char *path, struct logInfo *defConfig)
freeLogInfo(defConfig);
copyLogInfo(defConfig, &defConfigBackup);
freeLogInfo(&defConfigBackup);
+ result = 1;
continue;
- } else {
- result = 0;
}
freeLogInfo(&defConfigBackup);
}
@@ -611,8 +610,7 @@ static int readConfigPath(const char *path, struct logInfo *defConfig)
if (readConfigFile(path, defConfig)) {
freeLogInfo(defConfig);
copyLogInfo(defConfig, &defConfigBackup);
- } else {
- result = 0;
+ result = 1;
}
freeLogInfo(&defConfigBackup);
}
--
2.20.1
From 58f8efbfde9d0ff2d8fbb0cef30ed842928835cd Mon Sep 17 00:00:00 2001
From: Kamil Dudka <kdudka@redhat.com>
Date: Thu, 12 Jan 2017 08:50:55 +0100
Subject: [PATCH 4/4] do not treat errors in reading configuration as fatal
Closes #81
Upstream-commit: 74b788f790990d5958314df5f908a6fc5eaeccdd
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
logrotate.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/logrotate.c b/logrotate.c
index 976210e..459e01e 100644
--- a/logrotate.c
+++ b/logrotate.c
@@ -2417,12 +2417,10 @@ int main(int argc, const char **argv)
selinux_enforce = security_getenforce();
#endif
- TAILQ_INIT(&logs);
+ TAILQ_INIT(&logs);
- if (readAllConfigPaths(files)) {
- poptFreeContext(optCon);
- exit(1);
- }
+ if (readAllConfigPaths(files))
+ rc = 1;
poptFreeContext(optCon);
nowSecs = time(NULL);
--
2.20.1