From nobody Thu Sep 28 15:52:21 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4RxHzn4vQJz4tyLY; Thu, 28 Sep 2023 15:52:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RxHzn4KYkz4K8P; Thu, 28 Sep 2023 15:52:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1695916341; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=FzSD69flA1nyZjmyKjLQDWIVTnFY6cD7BkdVSJsBPy8=; b=cdCQtVGQ3w3dzP/WPrPrzfOeWTnffq0Kqi5knGyjkYv9H+3KKR93Av1aXH9bnHh3h1h07u A3NwnvO3KYevM2fZln5/4P7CZgZttV7NAF8kTl2Z+TFahvdw+jVatKd9r7JSlMC6hnaFN0 GL0SvBzf4diDryEf7R0RawW9qba3eTi0G++KoNmgQ64MhClbUy1txCEYDjkFljV0V5jbtx nLahAnFHWczvNCVzu1S8ZkKb4S54tmgMXvSOqWijsdLS/nSFBWmn7AQZtuQ3FjlJ8tPqJm XDKBJXiTQq5OAF6bMllpb0WcJ7IJQblsdB18pjDEcu//yylw8VmB/thchGHYiA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1695916341; a=rsa-sha256; cv=none; b=yFDJeq3/3y4rIIWVNfWPEFmwPkpjGNTn5tN31NAmIN9/Kyw+H6ZKouBAmzx8+3m8z1bVPQ OY2rDZjRy5lv1LmerjLINOsTINrXwoe3dsWyfnFEOUEWFwDbEv3YI80bQrEIYga1ANIrIp xmnutLFrg8YUR4x3rDUp1WzM0mbeXyCOEAKn+Z6bs+Z6xi0Er8h0+PqLFfjP0z2ppJDjhB gz+yg/0ljRGxleTj8+G8wJMBQAQU2Au2oL26gq2Di9bpgrT+J/zPnWZSN4Kjt+NmY9M3bU FaFDlaRfkbYbVpnEA8Jh+rCEEPw4ceIfx0FXWHEf0aAt8oevNeOnFbtGaaS3Lw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1695916341; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=FzSD69flA1nyZjmyKjLQDWIVTnFY6cD7BkdVSJsBPy8=; b=NtONC6xsi0DhejMB4NcL8L15OpOjTGy0l6G/AuBE4fVZilbaEKXcbIrZnX6WNRxIBc+ys3 pxreVrO7n8jIyJARVOseMfX8EED4CD0jS4Vn948+iHCf88G1uH3SgIyJlJx3dcHEFPBhYO q/gHEPYGfGdCTUwndm39RgUU8PRokUYogvNsvhzc0ckcn06jJkmSgtbTFjcV+N874t56Lt v2WHlWmymtWMuNuHMlYjZE+5QSDLXzrVX56qeY1ZJsARH1YPDxtEqkC/UitSqRXlqxA2NF vCswdMF3ZJtTvy9EufbMg9y0sBiCtFP6t1QFQZP1eL+0xrlQWsgBTyL8+kThww== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4RxHzn2pw9zDHy; Thu, 28 Sep 2023 15:52:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 38SFqLrJ021472; Thu, 28 Sep 2023 15:52:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 38SFqLca021469; Thu, 28 Sep 2023 15:52:21 GMT (envelope-from git) Date: Thu, 28 Sep 2023 15:52:21 GMT Message-Id: <202309281552.38SFqLca021469@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 931d05fc088b - main - syslogd: Read configuration outside of init loop List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 931d05fc088bb83a9d0b1aacbf09590b22422351 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=931d05fc088bb83a9d0b1aacbf09590b22422351 commit 931d05fc088bb83a9d0b1aacbf09590b22422351 Author: Jake Freeland AuthorDate: 2023-09-01 02:48:53 +0000 Commit: Mark Johnston 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) {