From nobody Thu Sep 28 15:52:22 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 4RxHzq3P97z4ty9G; Thu, 28 Sep 2023 15:52:23 +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 4RxHzp59zYz4KFV; Thu, 28 Sep 2023 15:52:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1695916342; 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=WP/DpYXbVXI10LpROMWKh5oNCAluHtQtueo+1u9LW90=; b=q2tTpbGCqmyHi4E9S1IVBDP1Xiz+aT8HgbCSC67+KPF4iyUjV9eT8DUAL/k8g/GxYY6lFB 4hXVXu0hBZLXy1m4FpkR9jTcR872iZrOnf0Z617qedz93xSDYoU982x6Bh9fccHygQgnj8 BgtaZbtm7ruf1NtscqoF4PS0jmuQy4C3v4ZsV6ZY78TYqDPPsXCmM8fLlq8gjYzvztNWcK ZRGdvtV989GVDjnZKdrzQYSMJWbeogfupvfUsS91x7TGxX5dhOtMHb/Gs+3InNTR0sw+7n X4r9LParF1xTGsJEpbqY/p1uR50L/P7EOC9vSI370guL4YiIR0jS6HkmYZPZDA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1695916342; a=rsa-sha256; cv=none; b=qctr7+OOQ8lEFikfJvqapafwQzO9s74Jo7ESB1E3nG4a8nTRbjBPrq3Nmkvo0w7GOrQ7OG ZzFAatPBMmX9S90HdH6PtTLz1dW3K5+lOt2TdhG/YQf2TW4nxspiKMIU8T201VQhMDRdGj c64LkQdd3/VwbdVe0xraHkTAMNnxglik48RbHGc+D/q6REnbKTbuSiIwe9PhZoS6crYqnZ X6dtIm85NqDXYeowYGVxkubyxJIBoiNGllP85sqJEla510guUu9prrN7zxlFQJlqQYJLql c7g8HJd8rwBhY2+mtHO0O5zGzxHSULLjM/hPOzYgQ33eWNPB6fptAwJWwRPe+Q== 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=1695916342; 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=WP/DpYXbVXI10LpROMWKh5oNCAluHtQtueo+1u9LW90=; b=nZPTbk9bgRYJYfw5Fa+Xgytj9/693XQ1HJmTAF2XqGxDOkm3sQeBaudOya4HANq9yYTIOX ZlrbHx/d2HWYp/l+scRijlApsOBK2nu/02NXB5wamsb1vQIVw+3aI2DrxwXgr1rdfdJ80w k+JVAZ8+hdrbmt8bU4GgqVJbMgEHLWgHxPKIDZkbm38dUSvBiABj9Ny4st1IfHoWoBj9AH hi1BpzGnKoGk1jfH8b8zBD9Bi3sAkbYkzsPr740wN/ebl4+8Ol6HvmW7gSjMeO22wr7iHm wgsKYpvVPb95FHH9XohsaPjW2FI2aStL924R7GjeIIEcfKMvB9tdmio1k1bUdA== 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 4RxHzp3wt6zD65; Thu, 28 Sep 2023 15:52:22 +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 38SFqMah021523; Thu, 28 Sep 2023 15:52:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 38SFqMf8021520; Thu, 28 Sep 2023 15:52:22 GMT (envelope-from git) Date: Thu, 28 Sep 2023 15:52:22 GMT Message-Id: <202309281552.38SFqMf8021520@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: 2d69e4c37332 - main - syslogd: Remove addfile() and free up some memory 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: 2d69e4c37332c396582ac93ead289d5212ce5c23 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=2d69e4c37332c396582ac93ead289d5212ce5c23 commit 2d69e4c37332c396582ac93ead289d5212ce5c23 Author: Jake Freeland AuthorDate: 2023-09-01 02:49:00 +0000 Commit: Mark Johnston CommitDate: 2023-09-28 15:51:52 +0000 syslogd: Remove addfile() and free up some memory cfline() already allocates a filed structure on the heap, so we can avoid redundant memory allocations by skipping a second calloc() inside addfile(). addfile() can be removed altogether since a simple STAILQ_INSERT_TAIL() will add the filed to the global filed list. Reviewed by: markj, emaste MFC after: 3 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D41359 --- usr.sbin/syslogd/syslogd.c | 43 ++++++++----------------------------------- 1 file changed, 8 insertions(+), 35 deletions(-) diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index bf00f4ae4cef..3e4dc25603b0 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -412,11 +412,9 @@ static volatile sig_atomic_t MarkSet, WantDie, WantInitialize, WantReapchild; struct iovlist; static int allowaddr(char *); -static int addfile(struct filed *); static int addpeer(struct peer *); static int addsock(struct addrinfo *, struct socklist *); -static struct filed *cfline(const char *, const char *, const char *, - const char *); +static void cfline(const char *, const char *, const char *, const char *); static const char *cvthname(struct sockaddr *); static void deadq_enter(pid_t, const char *); static int deadq_remove(struct deadq_entry *); @@ -488,20 +486,6 @@ close_filed(struct filed *f) f->f_file = -1; } -static int -addfile(struct filed *f0) -{ - struct filed *f; - - f = calloc(1, sizeof(*f)); - if (f == NULL) - err(1, "malloc failed"); - *f = *f0; - STAILQ_INSERT_TAIL(&fhead, f, next); - - return (0); -} - static int addpeer(struct peer *pe0) { @@ -2406,7 +2390,6 @@ static void parseconfigfile(FILE *cf, bool allow_includes) { FILE *cf2; - struct filed *f; struct dirent **ent; char cline[LINE_MAX]; char host[MAXHOSTNAMELEN]; @@ -2533,10 +2516,7 @@ parseconfigfile(FILE *cf, bool allow_includes) } for (i = strlen(cline) - 1; i >= 0 && isspace(cline[i]); i--) cline[i] = '\0'; - f = cfline(cline, prog, host, pfilter); - if (f != NULL) - addfile(f); - free(f); + cfline(cline, prog, host, pfilter); } } @@ -2544,21 +2524,14 @@ 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); + cfline("*.ERR\t/dev/console", "*", "*", "*"); + cfline("*.PANIC\t*", "*", "*", "*"); } } @@ -2903,7 +2876,7 @@ prop_filter_compile(struct prop_filter *pfilter, char *filter) /* * Crack a configuration file line */ -static struct filed * +static void cfline(const char *line, const char *prog, const char *host, const char *pfilter) { @@ -3041,7 +3014,7 @@ cfline(const char *line, const char *prog, const char *host, "unknown priority name \"%s\"", buf); logerror(ebuf); free(f); - return (NULL); + return; } } if (!pri_cmp) @@ -3072,7 +3045,7 @@ cfline(const char *line, const char *prog, const char *host, buf); logerror(ebuf); free(f); - return (NULL); + return; } f->f_pmask[i >> 3] = pri; f->f_pcmp[i >> 3] = pri_cmp; @@ -3190,7 +3163,7 @@ cfline(const char *line, const char *prog, const char *host, f->f_type = F_USERS; break; } - return (f); + STAILQ_INSERT_TAIL(&fhead, f, next); }