bug-inetutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-inetutils] [PATCH 2/2] Add support for syslogd configuration files


From: Guillem Jover
Subject: [bug-inetutils] [PATCH 2/2] Add support for syslogd configuration files directory
Date: Sun, 6 Dec 2009 06:46:18 +0100
User-agent: Mutt/1.5.20 (2009-06-14)

This allows external programs to drop a configuration file in the
directory and avoid the need to edit the main configuraion file.

        * doc/inetutils.texi: Document new -D and --rcdir syslogd
        options.
        * paths (PATH_LOGCONFD): New variable.
        * syslogd/Makefile.am (AM_CPPFLAGS): Add PATHDEF_LOGCONFD.
        * syslogd/syslogd.c: Include <dirent.h>.
        (ConfDir): New variable.
        (load_confdir): New function declaration.
        (argp_options): Add rcdir entry.
        (parse_opt): Handle 'D' option.
        (load_confdir): New function definition.
        (init): Call load_confdir instead of load_conffile.
---
 doc/inetutils.texi  |    6 +++++
 paths               |    1 +
 syslogd/Makefile.am |    3 +-
 syslogd/syslogd.c   |   53 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 61 insertions(+), 2 deletions(-)

diff --git a/doc/inetutils.texi b/doc/inetutils.texi
index 0cc0d98..5f85063 100644
--- a/doc/inetutils.texi
+++ b/doc/inetutils.texi
@@ -2288,6 +2288,12 @@ syslogd address@hidden@dots{}
 @opindex --rcfile
 Override configuration (the default file is @file{/etc/syslog.conf}).
 
address@hidden -D @var{dir}
address@hidden address@hidden
address@hidden -D
address@hidden --rcdir
+Override configuration directory (the default is @file{/etc/syslog.d}).
+
 @item address@hidden
 @opindex --pidfile
 Override pidfile (the default file is @file{/var/run/syslogd.pid}).
diff --git a/paths b/paths
index a0117f2..8ef5430 100644
--- a/paths
+++ b/paths
@@ -90,6 +90,7 @@ PATH_LASTLOG  <utmp.h> $(localstatedir)/log/lastlog 
search:lastlog:/var/log:/var/
 PATH_LOG       <syslog.h> /dev/log
 PATH_KLOG      <syslog.h> /dev/klog no
 PATH_LOGCONF   $(sysconfdir)/syslog.conf
+PATH_LOGCONFD  $(sysconfdir)/syslog.d
 PATH_LOGIN     x $(bindir)/login search:login
 PATH_LOGPID    $(localstatedir)/run/syslog.pid
 PATH_NOLOGIN   $(sysconfdir)/nologin
diff --git a/syslogd/Makefile.am b/syslogd/Makefile.am
index 889810f..dc607b6 100644
--- a/syslogd/Makefile.am
+++ b/syslogd/Makefile.am
@@ -28,7 +28,8 @@ syslogd_SOURCES = syslogd.c
 @PATHDEFS_MAKE@
 
 AM_CPPFLAGS = $(PATHDEF_LOG) $(PATHDEF_KLOG) $(PATHDEF_LOGCONF) \
-              $(PATHDEF_LOGPID) $(PATHDEF_CONSOLE) $(PATHDEF_UTMP)
+              $(PATHDEF_LOGCONFD) $(PATHDEF_LOGPID) $(PATHDEF_CONSOLE) \
+              $(PATHDEF_UTMP)
 
 INCLUDES = -I$(top_srcdir)/libinetutils -I$(top_srcdir)/lib -I../lib 
 
diff --git a/syslogd/syslogd.c b/syslogd/syslogd.c
index edde0c2..e2c83fb 100644
--- a/syslogd/syslogd.c
+++ b/syslogd/syslogd.c
@@ -116,6 +116,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <dirent.h>
 #include <unistd.h>
 
 #ifdef HAVE_STDARG_H
@@ -144,6 +145,7 @@
 int facilities_seen;
 
 const char *ConfFile = PATH_LOGCONF;   /* Default Configuration file.  */
+const char *ConfDir = PATH_LOGCONFD;   /* Default Configuration directory.  */
 const char *PidFile = PATH_LOGPID;     /* Default path to tuck pid.  */
 char ctty[] = PATH_CONSOLE;    /* Default console to send message info.  */
 
@@ -262,6 +264,7 @@ void doexit (int);
 void domark (int);
 void fprintlog (struct filed *, const char *, int, const char *);
 static int load_conffile (const char *, struct filed **);
+static void load_confdir (struct filed **);
 void init (int);
 void logerror (const char *);
 void logmsg (int, const char *, const char *, int);
@@ -340,6 +343,8 @@ static struct argp_option argp_options[] = {
   {"rcfile", 'f', "FILE", 0, "override configuration file (default: "
    PATH_LOGCONF ")",
    GRP+1},
+  {"rcdir", 'D', "DIR", 0, "override configuration directory (default: "
+   PATH_LOGCONFD ")", GRP+1},
   {"socket", 'p', "FILE", 0, "override default unix domain socket " PATH_LOG,
    GRP+1},
   {"sync", 'S', NULL, 0, "force a file sync on every line", GRP+1},
@@ -411,6 +416,10 @@ parse_opt (int key, char *arg, struct argp_state *state)
       ConfFile = arg;
       break;
 
+    case 'D':
+      ConfDir = arg;
+      break;
+
     case 'p':
       funix[0].name = arg;
       funix[0].fd = -1;
@@ -1679,6 +1688,48 @@ load_conffile (const char *filename, struct filed 
**nextp)
   return 1;
 }
 
+static void
+load_confdir (struct filed **nextp)
+{
+  struct dirent *dent;
+  DIR *dir;
+
+  if (!load_conffile (ConfFile, nextp))
+    return;
+
+  dir = opendir (ConfDir);
+  if (dir == NULL)
+    {
+      dbg_printf ("cannot open %s\n", ConfDir);
+      return;
+    }
+
+  while ((dent = readdir (dir)) != NULL)
+    {
+      struct stat st;
+      char *file;
+
+      if (asprintf (&file, "%s/%s", ConfDir, dent->d_name) < 0)
+        {
+          dbg_printf ("cannot allocate space for configuration filename\n");
+          return;
+        }
+
+      if (stat (file, &st) != 0)
+        {
+          dbg_printf ("cannot stat file configuration file\n");
+          continue;
+        }
+
+      if (S_ISREG (st.st_mode))
+        load_conffile (file, nextp);
+
+      free (file);
+    }
+
+  closedir (dir);
+}
+
 /* INIT -- Initialize syslogd from configuration table.  */
 RETSIGTYPE
 init (int signo ARG_UNUSED)
@@ -1726,7 +1777,7 @@ init (int signo ARG_UNUSED)
   /* Foreach line in the conf table, open that file.  */
   f = NULL;
 
-  load_conffile (ConfFile, nextp);
+  load_confdir (nextp);
 
   Initialized = 1;
 
-- 
1.6.5.4





reply via email to

[Prev in Thread] Current Thread [Next in Thread]