From nobody Thu Sep 28 15:52:42 2023 X-Original-To: dev-commits-src-main@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 4RxJ0C0gKxz4tyRB; Thu, 28 Sep 2023 15:52:43 +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 4RxJ0C0Bsqz4LJd; Thu, 28 Sep 2023 15:52:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1695916363; 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=QDgjUIMAeloC6Nhn8AC5tAmaDn//SlTOIPSlN4lOVtQ=; b=GZeHQeS2jqZuQL3EKzDW1g3rGUZV5EcR/+aZ5uUfrutNw8yNwz7naZqUiG14c8Zqe7zMg5 RYxHPtBD/5S5zYORszXKFm+YUjH2C195Ef7ziUz5oC4pPB980DJUEO3FCI03kylrud15Am wonZiiJNOhkt+FLFCpsVsNgbUTvs1dwyAnL7huFgtvNMB44VD3PrUC+GZxQwH5KQIjc1Rs qkrujB7tjUF/Idj/wNpSNUrcGEMim9Fy7DPDIvhSG0cnDEIY1gw4k398td6+6dtczXWhN5 uM4YYCbO4I+XzRUiCf9W8s4awPAB1JcZesQjMMDuPqIuZFvUa0BQL36MJempqQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1695916363; a=rsa-sha256; cv=none; b=JZdNQo9nfnTg5KvK/mXy9HFmihT+6pvjHfPOqq079z6VEpR+kIyIGjRaYq2IdUk17ooQtm sa0Uk3yHUGzxHDc70Do/Su7oSuRosKRaRCTxOdUjmibKKEnrLss2MOS1D2SxjqQd052KHC 37mG0CpzHz7ASGTltV290Pt1tRXrpc7MU/ERKQzMSYkeiRy+hed69gQbR6bRHa40+7S30E uckGOFqNnpMnbHJvQB7IyxLKdpuu3YQZKVr0Mk+wDp0peOq/pRD6pCLS4GMajKl22jSC/S WCWNqLLZ6Y5oFAgWP40XLRpPJYSrIJRNufqWjAFvnRcCWJK0+w3cQGFWvL1AYw== 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=1695916363; 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=QDgjUIMAeloC6Nhn8AC5tAmaDn//SlTOIPSlN4lOVtQ=; b=C/Lkzv4/a6nESjSKv3fmDNzKILC22ohVx9Xnee6x9lhWsdszhU0P/QlmoODw0h0A/KQyc3 1/KiJUBMQozHXktJcnB/5cGoLK/LHuJjrV/+K+9/53cfi2bdOJ8pxbGZUpEbsXFWgK9nhD U6WYVyLghk33lIJq+rxP7NM4EsosDo+rwEOccqFSSfcjzZXelGt7dCy+piZY5Dpcm5TpNB FMU6nkOqvGNulrytEnkYHQpRaFVx5ef+hb7h779t5HKPLmtNqW45uXTpnH22SXB17OF2uI kczqRcAFVJJniT9WN/EwNIZ7B63NMeKGJMEfO3Pm+UC24YjiHJppNSHOxFk2NA== 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 4RxJ0B6M8kzD8y; Thu, 28 Sep 2023 15:52:42 +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 38SFqgrL022360; Thu, 28 Sep 2023 15:52:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 38SFqgF3022357; Thu, 28 Sep 2023 15:52:42 GMT (envelope-from git) Date: Thu, 28 Sep 2023 15:52:42 GMT Message-Id: <202309281552.38SFqgF3022357@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: 3854dd52a3d3 - main - syslogd: Add closelogfiles() function List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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: 3854dd52a3d3ff4a7a298fba10c96c8988fb814d Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=3854dd52a3d3ff4a7a298fba10c96c8988fb814d commit 3854dd52a3d3ff4a7a298fba10c96c8988fb814d Author: Jake Freeland AuthorDate: 2023-09-01 02:51:00 +0000 Commit: Mark Johnston CommitDate: 2023-09-28 15:51:53 +0000 syslogd: Add closelogfiles() function The closelogfiles() function completely disassembles the global filed list by freeing all filed components and removing them from the list. Reviewed by: markj MFC after: 3 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D41388 --- usr.sbin/syslogd/syslogd.c | 96 ++++++++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 45 deletions(-) diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index 659b71385087..d317afa73844 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -2520,6 +2520,54 @@ readconfigfile(const char *path) } } +/* + * Close all open log files. + */ +static void +closelogfiles(void) +{ + struct filed *f; + + while (!STAILQ_EMPTY(&fhead)) { + f = STAILQ_FIRST(&fhead); + STAILQ_REMOVE_HEAD(&fhead, next); + + /* flush any pending output */ + if (f->f_prevcount) + fprintlog_successive(f, 0); + + switch (f->f_type) { + case F_FILE: + case F_FORW: + case F_CONSOLE: + case F_TTY: + case F_PIPE: + close_filed(f); + break; + default: + break; + } + + free(f->f_program); + free(f->f_host); + if (f->f_prop_filter) { + switch (f->f_prop_filter->cmp_type) { + case FILT_CMP_REGEX: + regfree(f->f_prop_filter->pflt_re); + free(f->f_prop_filter->pflt_re); + break; + case FILT_CMP_CONTAINS: + case FILT_CMP_EQUAL: + case FILT_CMP_STARTS: + free(f->f_prop_filter->pflt_strval); + break; + } + free(f->f_prop_filter); + } + free(f); + } +} + /* * INIT -- Initialize syslogd from configuration table */ @@ -2527,7 +2575,6 @@ static void init(bool reload) { int i; - struct filed *f; char *p; char oldLocalHostName[MAXHOSTNAMELEN]; char hostMsg[2*MAXHOSTNAMELEN+40]; @@ -2570,56 +2617,15 @@ init(bool reload) unsetenv("TZ"); } - /* - * Close all open log files. - */ Initialized = false; - while (!STAILQ_EMPTY(&fhead)) { - f = STAILQ_FIRST(&fhead); - STAILQ_REMOVE_HEAD(&fhead, next); - - /* flush any pending output */ - if (f->f_prevcount) - fprintlog_successive(f, 0); - - switch (f->f_type) { - case F_FILE: - case F_FORW: - case F_CONSOLE: - case F_TTY: - close_filed(f); - break; - case F_PIPE: - close_filed(f); - break; - default: - break; - } - - free(f->f_program); - free(f->f_host); - if (f->f_prop_filter) { - switch (f->f_prop_filter->cmp_type) { - case FILT_CMP_REGEX: - regfree(f->f_prop_filter->pflt_re); - free(f->f_prop_filter->pflt_re); - break; - case FILT_CMP_CONTAINS: - case FILT_CMP_EQUAL: - case FILT_CMP_STARTS: - free(f->f_prop_filter->pflt_strval); - break; - } - free(f->f_prop_filter); - } - free(f); - } - + closelogfiles(); readconfigfile(ConfFile); Initialized = true; if (Debug) { + struct filed *f; int port; + STAILQ_FOREACH(f, &fhead, next) { for (i = 0; i <= LOG_NFACILITIES; i++) if (f->f_pmask[i] == INTERNAL_NOPRI)