From 7cc1fba608d2d4a9c378f90a91cbd19646a15fd7 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Wed, 20 Feb 2008 05:23:19 +0200 Subject: [PATCH] Split load_conffile --- src/syslogd.c | 111 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 61 insertions(+), 50 deletions(-) --- a/src/syslogd.c +++ b/src/syslogd.c @@ -249,6 +249,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); @@ -1541,12 +1542,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 @@ -1555,61 +1555,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) @@ -1617,7 +1576,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; @@ -1658,7 +1617,7 @@ init (int signo ARG_UNUSED) dbg_printf ("cannot allocate space configuration\n"); fclose (cf); free (cbuf); - return; + return 0; } else cbuf = tmp; @@ -1705,6 +1664,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)