The branch main has been updated by markj:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=931d05fc088bb83a9d0b1aacbf09590b22422351

commit 931d05fc088bb83a9d0b1aacbf09590b22422351
Author:     Jake Freeland <[email protected]>
AuthorDate: 2023-09-01 02:48:53 +0000
Commit:     Mark Johnston <[email protected]>
CommitDate: 2023-09-28 15:51:52 +0000

    syslogd: Read configuration outside of init loop
    
    Move all configuration-file code outside of the initialization loop and
    into its own set of functions. Create a readconfigfile() to open the
    config and call parseconfigfile() to parse it.
    
    The init() function no longer returns if there was a failure to open the
    configuration file. Initialization will be finished, using the backup
    logging rules: *.ERR to /dev/console and *.PANIC to all logged in users.
    
    Reviewed by:    markj, emaste
    MFC after:      3 weeks
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D41358
---
 usr.sbin/syslogd/syslogd.c | 49 +++++++++++++++++++++++-----------------------
 1 file changed, 25 insertions(+), 24 deletions(-)

diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c
index 701b062802b0..bf00f4ae4cef 100644
--- a/usr.sbin/syslogd/syslogd.c
+++ b/usr.sbin/syslogd/syslogd.c
@@ -2403,7 +2403,7 @@ configfiles(const struct dirent *dp)
 }
 
 static void
-readconfigfile(FILE *cf, int allow_includes)
+parseconfigfile(FILE *cf, bool allow_includes)
 {
        FILE *cf2;
        struct filed *f;
@@ -2464,7 +2464,7 @@ readconfigfile(FILE *cf, int allow_includes)
                                if (cf2 == NULL)
                                        continue;
                                dprintf("reading %s\n", file);
-                               readconfigfile(cf2, 0);
+                               parseconfigfile(cf2, false);
                                fclose(cf2);
                        }
                        free(ent);
@@ -2540,6 +2540,28 @@ readconfigfile(FILE *cf, int allow_includes)
        }
 }
 
+static void
+readconfigfile(const char *path)
+{
+       FILE *cf;
+       struct filed *f;
+
+       if ((cf = fopen(path, "r")) != NULL) {
+               parseconfigfile(cf, true);
+               (void)fclose(cf);
+       } else {
+               dprintf("cannot open %s\n", ConfFile);
+               f = cfline("*.ERR\t/dev/console", "*", "*", "*");
+               if (f != NULL)
+                       addfile(f);
+               free(f);
+               f = cfline("*.PANIC\t*", "*", "*", "*");
+               if (f != NULL)
+                       addfile(f);
+               free(f);
+       }
+}
+
 static void
 sighandler(int signo)
 {
@@ -2555,7 +2577,6 @@ static void
 init(int signo)
 {
        int i;
-       FILE *cf;
        struct filed *f;
        char *p;
        char oldLocalHostName[MAXHOSTNAMELEN];
@@ -2646,27 +2667,7 @@ init(int signo)
                free(f);
        }
 
-       /* open the configuration file */
-       if ((cf = fopen(ConfFile, "r")) == NULL) {
-               dprintf("cannot open %s\n", ConfFile);
-               f = cfline("*.ERR\t/dev/console", "*", "*", "*");
-               if (f != NULL)
-                       addfile(f);
-               free(f);
-               f = cfline("*.PANIC\t*", "*", "*", "*");
-               if (f != NULL)
-                       addfile(f);
-               free(f);
-               Initialized = 1;
-
-               return;
-       }
-
-       readconfigfile(cf, 1);
-
-       /* close the configuration file */
-       (void)fclose(cf);
-
+       readconfigfile(ConfFile);
        Initialized = 1;
 
        if (Debug) {

Reply via email to