[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-inetutils] [PATCH 1/2] Split syslogd configuration file loading int
From: |
Guillem Jover |
Subject: |
[bug-inetutils] [PATCH 1/2] Split syslogd configuration file loading into a new function |
Date: |
Sun, 6 Dec 2009 06:43:41 +0100 |
User-agent: |
Mutt/1.5.20 (2009-06-14) |
* syslogd/syslogd.c (load_conffile): New function declaration.
(init): Move configuration file loading into ...
(load_conffile): ... here. New function definition.
---
syslogd/syslogd.c | 111 +++++++++++++++++++++++++++++------------------------
1 files changed, 61 insertions(+), 50 deletions(-)
diff --git a/syslogd/syslogd.c b/syslogd/syslogd.c
index de530d2..edde0c2 100644
--- a/syslogd/syslogd.c
+++ b/syslogd/syslogd.c
@@ -261,6 +261,7 @@ void die (int);
void doexit (int);
void domark (int);
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);
@@ -1553,12 +1554,11 @@ die (int signo)
exit (0);
}
-/* INIT -- Initialize syslogd from configuration table. */
-RETSIGTYPE
-init (int signo ARG_UNUSED)
+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
@@ -1567,61 +1567,20 @@ init (int signo ARG_UNUSED)
char *cbuf;
char *cline;
int cont_line = 0;
- struct servent *sp;
-
- dbg_printf ("init\n");
- sp = getservbyname ("syslog", "udp");
- if (sp == NULL)
- {
- errno = 0;
- logerror ("network logging disabled (syslog/udp service unknown).");
- logerror
- ("see syslogd(8) for details of whether and how to enable it.");
- return;
- }
- LogPort = sp->s_port;
-
- /* Close all open log files. */
- Initialized = 0;
- for (f = Files; f != NULL; f = next)
- {
- /* 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:
- close (f->f_file);
- break;
- }
- next = f->f_next;
- free (f);
- }
- Files = NULL;
- nextp = &Files;
-
- facilities_seen = 0;
/* Open the configuration file. */
- cf = fopen (ConfFile, "r");
+ cf = fopen (filename, "r");
if (cf == NULL)
{
- dbg_printf ("cannot open %s\n", ConfFile);
+ dbg_printf ("cannot open %s\n", filename);
*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)
@@ -1629,7 +1588,7 @@ init (int signo ARG_UNUSED)
/* There is no graceful recovery here. */
dbg_printf ("cannot allocate space for configuration\n");
fclose (cf);
- return;
+ return 0;
}
cline = cbuf;
@@ -1670,7 +1629,7 @@ init (int signo ARG_UNUSED)
dbg_printf ("cannot allocate space configuration\n");
fclose (cf);
free (cbuf);
- return;
+ return 0;
}
else
cbuf = tmp;
@@ -1717,6 +1676,58 @@ init (int signo ARG_UNUSED)
fclose (cf);
free (cbuf);
+ return 1;
+}
+
+/* INIT -- Initialize syslogd from configuration table. */
+RETSIGTYPE
+init (int signo ARG_UNUSED)
+{
+ struct filed *f, *next, **nextp;
+ struct servent *sp;
+
+ dbg_printf ("init\n");
+ sp = getservbyname ("syslog", "udp");
+ if (sp == NULL)
+ {
+ errno = 0;
+ logerror ("network logging disabled (syslog/udp service unknown).");
+ logerror
+ ("see syslogd(8) for details of whether and how to enable it.");
+ return;
+ }
+ LogPort = sp->s_port;
+
+ /* Close all open log files. */
+ Initialized = 0;
+ for (f = Files; f != NULL; f = next)
+ {
+ /* 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:
+ close (f->f_file);
+ break;
+ }
+ next = f->f_next;
+ free (f);
+ }
+ Files = NULL;
+ nextp = &Files;
+
+ facilities_seen = 0;
+
+ /* Foreach line in the conf table, open that file. */
+ f = NULL;
+
+ load_conffile (ConfFile, nextp);
+
Initialized = 1;
if (Debug)
--
1.6.5.4
- [bug-inetutils] [PATCH 1/2] Split syslogd configuration file loading into a new function,
Guillem Jover <=