commit-inetutils
[Top][All Lists]
Advanced

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

[SCM] GNU Inetutils branch, master, updated. inetutils-1_9_1-299-ga3508


From: Mats Erik Andersson
Subject: [SCM] GNU Inetutils branch, master, updated. inetutils-1_9_1-299-ga3508ed
Date: Wed, 29 May 2013 20:50:03 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Inetutils ".

The branch, master has been updated
       via  a3508ed9308e61b5998af03b40183725d66fe9b1 (commit)
      from  ae30a115919812538838839f6cb2ecdf59017c3e (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/inetutils.git/commit/?id=a3508ed9308e61b5998af03b40183725d66fe9b1


commit a3508ed9308e61b5998af03b40183725d66fe9b1
Author: Mats Erik Andersson <address@hidden>
Date:   Wed May 29 19:49:52 2013 +0200

    syslogd: Refactor configuration loading.
    
    Based on a patch suggested by Guillem Jover.
    Added a change to legacy code on linked lists.

diff --git a/ChangeLog b/ChangeLog
index 125b6aa..0d83bea 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2013-05-29  Mats Erik Andersson  <address@hidden>
+
+       syslogd: Refactor loading of configuration file.
+       Code outlined by Guillem Jover <address@hidden>
+       <http://lists.gnu.org/archive/html/bug-inetutils/2009-12/msg00053.html>.
+       Added an important correction to the legacy code
+       for building linked lists of logging files.
+
+       * src/syslogd.c (load_conffile): New function.
+       First build a new structure `struct filed' from
+       input line, then incorporate it into `*nextp'.
+       (init): Refactor code for loading a configuration
+       file, moving it to load_conffile().
+       New variable RC.  Remove CF, P, LINE_MAX, CBUF,
+       CLINE, and CONT_LINE.
+       Register an additional error message, should loading
+       have been incomplete.
+
 2013-05-27  Mats Erik Andersson  <address@hidden>
 
        rshd: Check account locking and expiration.
diff --git a/src/syslogd.c b/src/syslogd.c
index bbdca48..18a3e41 100644
--- a/src/syslogd.c
+++ b/src/syslogd.c
@@ -258,6 +258,7 @@ void doexit (int);
 void domark (int);
 void find_inet_port (const char *);
 void fprintlog (struct filed *, const char *, int, const char *);
+static int load_conffile (const char *, struct filed **);
 void init (int);
 void logerror (const char *);
 void logmsg (int, const char *, const char *, int);
@@ -1796,12 +1797,11 @@ die (int signo)
   exit (EXIT_SUCCESS);
 }
 
-/* INIT -- Initialize syslogd from configuration table.  */
-void
-init (int signo _GL_UNUSED_PARAMETER)
+static int
+load_conffile (const char *filename, struct filed **nextp)
 {
   FILE *cf;
-  struct filed *f, *next, **nextp;
+  struct filed *f;
   char *p;
 #ifndef LINE_MAX
 # define LINE_MAX 2048
@@ -1811,64 +1811,32 @@ init (int signo _GL_UNUSED_PARAMETER)
   char *cline;
   int cont_line = 0;
 
-  dbg_printf ("init\n");
+  /* Beware: Do not assume *nextp to be NULL.  */
 
-  /* Close all open log files.  */
-  Initialized = 0;
-  for (f = Files; f != NULL; f = next)
+  /* Open the configuration file.  */
+  cf = fopen (filename, "r");
+  if (cf == NULL)
     {
-      int j;
+      dbg_printf ("cannot open %s\n", filename);
 
-      /* Flush any pending output.  */
-      if (f->f_prevcount)
-       fprintlog (f, LocalHostName, 0, (char *) NULL);
-
-      switch (f->f_type)
+      /* Add emergency logging if everything else was missing.  */
+      if (*nextp == NULL)
        {
-       case F_FILE:
-       case F_TTY:
-       case F_CONSOLE:
-       case F_PIPE:
-         free (f->f_un.f_fname);
-         close (f->f_file);
-         break;
-       case F_FORW:
-       case F_FORW_SUSP:
-       case F_FORW_UNKN:
-         free (f->f_un.f_forw.f_hname);
-         break;
-       case F_USERS:
-         for (j = 0; j < f->f_un.f_user.f_nusers; ++j)
-           free (f->f_un.f_user.f_unames[j]);
-         free (f->f_un.f_user.f_unames);
-         break;
-       }
-      free (f->f_progname);
-      free (f->f_prevhost);
-      next = f->f_next;
-      free (f);
-    }
-  Files = NULL;
-  nextp = &Files;
+         /* Send LOG_ERR to the system console.  */
+         f = (struct filed *) calloc (1, sizeof (*f));
+         cfline ("*.ERR\t" PATH_CONSOLE, f);           /* Erases *f!  */
 
-  facilities_seen = 0;
+         /* Below that, send LOG_EMERG to all users.  */
+         f->f_next = (struct filed *) calloc (1, sizeof (*f));
+         cfline ("*.PANIC\t*", f->f_next);     /* Erases *(f->f_next)!  */
+
+         *nextp = f;   /* Return this minimal table to the caller.  */
+       }
 
-  /* Open the configuration file.  */
-  cf = fopen (ConfFile, "r");
-  if (cf == NULL)
-    {
-      dbg_printf ("cannot open %s\n", ConfFile);
-      *nextp = (struct filed *) calloc (1, sizeof (*f));
-      cfline ("*.ERR\t" PATH_CONSOLE, *nextp);
-      (*nextp)->f_next = (struct filed *) calloc (1, sizeof (*f));
-      cfline ("*.PANIC\t*", (*nextp)->f_next);
       Initialized = 1;
-      return;
+      return 1;
     }
 
-  /* Foreach line in the conf table, open that file.  */
-  f = NULL;
-
   /* Allocate a buffer for line parsing.  */
   cbuf = malloc (line_max);
   if (cbuf == NULL)
@@ -1876,7 +1844,7 @@ init (int signo _GL_UNUSED_PARAMETER)
       /* There is no graceful recovery here.  */
       dbg_printf ("cannot allocate space for configuration\n");
       fclose (cf);
-      return;
+      return 0;
     }
   cline = cbuf;
 
@@ -1921,7 +1889,7 @@ init (int signo _GL_UNUSED_PARAMETER)
              dbg_printf ("cannot allocate space configuration\n");
              fclose (cf);
              free (cbuf);
-             return;
+             return 0;
            }
          else
            cbuf = tmp;
@@ -2003,17 +1971,75 @@ init (int signo _GL_UNUSED_PARAMETER)
 
       *++p = '\0';
 
-      /* Send the line for more parsing.  */
+      /* Send the line for more parsing.
+       * Then generate the new entry,
+       * inserting it at the head of
+       * the already existing table.
+       */
       f = (struct filed *) calloc (1, sizeof (*f));
+      cfline (cbuf, f);                        /* Erases *f!  */
+      f->f_next = *nextp;
       *nextp = f;
-      nextp = &f->f_next;
-      cfline (cbuf, f);
     }
 
   /* Close the configuration file.  */
   fclose (cf);
   free (cbuf);
 
+  return 1;
+}
+
+/* INIT -- Initialize syslogd from configuration table.  */
+void
+init (int signo _GL_UNUSED_PARAMETER)
+{
+  int rc;
+  struct filed *f, *next, **nextp;
+
+  dbg_printf ("init\n");
+
+  /* Close all open log files.  */
+  Initialized = 0;
+  for (f = Files; f != NULL; f = next)
+    {
+      int j;
+
+      /* Flush any pending output.  */
+      if (f->f_prevcount)
+       fprintlog (f, LocalHostName, 0, (char *) NULL);
+
+      switch (f->f_type)
+       {
+       case F_FILE:
+       case F_TTY:
+       case F_CONSOLE:
+       case F_PIPE:
+         free (f->f_un.f_fname);
+         close (f->f_file);
+         break;
+       case F_FORW:
+       case F_FORW_SUSP:
+       case F_FORW_UNKN:
+         free (f->f_un.f_forw.f_hname);
+         break;
+       case F_USERS:
+         for (j = 0; j < f->f_un.f_user.f_nusers; ++j)
+           free (f->f_un.f_user.f_unames[j]);
+         free (f->f_un.f_user.f_unames);
+         break;
+       }
+      free (f->f_progname);
+      free (f->f_prevhost);
+      next = f->f_next;
+      free (f);
+    }
+
+  Files = NULL;                /* Empty the table.  */
+  nextp = &Files;
+  facilities_seen = 0;
+
+  rc = load_conffile (ConfFile, nextp);
+
   Initialized = 1;
 
   if (Debug)
@@ -2058,6 +2084,11 @@ init (int signo _GL_UNUSED_PARAMETER)
   else
     logmsg (LOG_SYSLOG | LOG_INFO, "syslogd (" PACKAGE_NAME
            " " PACKAGE_VERSION "): restart", LocalHostName, ADDDATE);
+
+  if (!rc)
+    logmsg (LOG_SYSLOG | LOG_ERR, "syslogd: Incomplete configuration.",
+           LocalHostName, ADDDATE);
+
   dbg_printf ("syslogd: restarted\n");
 }
 

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog     |   18 +++++++
 src/syslogd.c |  147 ++++++++++++++++++++++++++++++++++----------------------
 2 files changed, 107 insertions(+), 58 deletions(-)


hooks/post-receive
-- 
GNU Inetutils 



reply via email to

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