Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 28 Sep 2023 15:52:22 GMT
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 2d69e4c37332 - main - syslogd: Remove addfile() and free up some memory
Message-ID:  <202309281552.38SFqMf8021520@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=2d69e4c37332c396582ac93ead289d5212ce5c23

commit 2d69e4c37332c396582ac93ead289d5212ce5c23
Author:     Jake Freeland <jfree@FreeBSD.org>
AuthorDate: 2023-09-01 02:49:00 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
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);
 }
 
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202309281552.38SFqMf8021520>