Signed-off-by: Alexander Vickberg <[email protected]>
---
 sysklogd/syslogd.c | 42 ++++++++++++++++++++++++++++++++++--------
 1 file changed, 34 insertions(+), 8 deletions(-)

diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c
index d1ecf5e5e..6698f4c13 100644
--- a/sysklogd/syslogd.c
+++ b/sysklogd/syslogd.c
@@ -227,6 +227,8 @@ typedef struct logFile_t {
 } logFile_t;
 
 #if ENABLE_FEATURE_SYSLOGD_CFG
+static void read_config(const char *path);
+
 typedef struct stringMatch_t {
        char *str;
        int len;
@@ -399,7 +401,8 @@ static const CODE* find_by_val(int val, const CODE* c_set)
 }
 
 #if ENABLE_FEATURE_SYSLOGD_CFG
-static void parse_syslogdcfg(const char *file)
+static int FAST_FUNC parse_syslogdcfg(struct recursive_state *state,
+               const char *file, struct stat *statbuf UNUSED_PARAM)
 {
        char *t;
        /* tok[0] set of selectors */
@@ -407,13 +410,25 @@ static void parse_syslogdcfg(const char *file)
        /* tok[2] has to be NULL */
        char *tok[3];
        parser_t *parser;
+       const char *base;
+
+       /* Skip files that begin with a "." */
+       base = bb_basename(file);
+       if (base[0] == '.')
+               return TRUE;
+
+       /* only recurse one level */
+       if (state->depth > 1)
+               return SKIP; /* stop recursing */
 
-       parser = config_open2(file ? file : "/etc/syslog.conf",
-                               file ? xfopen_for_read : fopen_for_read);
+       if (state->depth != 0) {
+               if (!is_suffixed_with(base, ".conf"))
+                       return TRUE;
+       }
+
+       parser = config_open2(file, fopen_for_read);
        if (!parser)
-               /* didn't find default /etc/syslog.conf */
-               /* proceed as if we built busybox without config support */
-               return;
+               return FALSE;
 
        /* iterate through lines of config, skipping comments */
        while (config_read(parser, tok, 3, 2, "# \t", PARSE_NORMAL | 
PARSE_MIN_DIE)) {
@@ -424,6 +439,11 @@ static void parse_syslogdcfg(const char *file)
                if (tok[2])
                        goto cfgerr;
 
+               if (strcmp(tok[0], "include") == 0) {
+                       read_config(tok[1]);
+                       continue;
+               }
+
                cur_rule = xzalloc(sizeof(*cur_rule));
                cur_rule->prev = G.log_rules;
                G.log_rules = cur_rule;
@@ -557,13 +577,19 @@ static void parse_syslogdcfg(const char *file)
                cur_rule->file->path = xstrdup(tok[1]);
        }
        config_close(parser);
-       return;
+       return TRUE;
 
  cfgerr:
        bb_error_msg_and_die("error in '%s' at line %d",
                        file ? file : "/etc/syslog.conf",
                        parser->lineno);
 }
+
+static void read_config(const char *path)
+{
+       recursive_action(path, ACTION_RECURSE | ACTION_QUIET,
+                               parse_syslogdcfg, NULL, NULL);
+}
 #endif
 
 /* circular buffer variables/structures */
@@ -1198,7 +1224,7 @@ int syslogd_main(int argc UNUSED_PARAM, char **argv)
        if (ENABLE_FEATURE_REMOTE_LOG && !(opts & OPT_remotelog)) // -R
                option_mask32 |= OPT_locallog;
 #if ENABLE_FEATURE_SYSLOGD_CFG
-       parse_syslogdcfg(opt_f);
+       read_config(opt_f ? opt_f : "/etc/syslog.conf");
 #endif
 
        /* Store away localhost's name before the fork */
-- 
2.25.1

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to