From nobody Thu Sep 28 15:52:40 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 4RxJ085vqSz4tyKP; Thu, 28 Sep 2023 15:52:40 +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 4RxJ085KHXz4LHP; Thu, 28 Sep 2023 15:52:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1695916360; 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=LstUF1dmLcaZ0E8sTDmZ/96tdEnLLA292yFBmmJ+Dlw=; b=DHauTtd3aRM/iQxtwZAIgpN+FgulZnLkLBcATufE7FOxJ5eCT3l1XAlPpJeGi357W1gr6p ZyljK+z1IZogI0vhLvrNO7aMK3bcm+RF5dfdSnFslHp2dFmbppu136FoVE2UNkOSeNGFD3 c452R8jJpb7wjuAFOeJSoChPKylEsoZfXIVtfWie9ZvUJYziQLvR4/Irk6E6ydkf1H9u6P SAOH9iHmCSiZebikGZQ3nRGldnnsegZf/QGjj7WKO1QWswP0Tz00/nl8jhmBR8yAY9gmM4 9dtOZIvy1dPhzVJ1M29O9x612ymrcyGT6u0fFdbuZtR8trIJ0vhp6KMKYTc6+A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1695916360; a=rsa-sha256; cv=none; b=bHi2IsEEUt7LT3mNmPKd51nFxpr69K4ja/MgU3lqEH2L0OSPZFTxF5s5u67M5BVSkqyyyO runzB1On8WAoLLVav/yrg9ydk+zZ8/as7eqnP4GU8saMPhACOLMbC3LXY7XYt9FMcOsDE0 2uGD+GEpr4EQMu2uf1J32P6eZiOXKDxdYIMYcLvNnKtQauAoXPQ6SrpC2Y7Fz9nVWnwhn9 ySJQYlEU5FD9D4hT+dbKdHDK1V0PaEhQI1A5b848bnz63MODLMq8IiT9c9/KmG4w+Vd6uB 5AhxKzUNCp9YmnWng9cuxpgOT7oZu056e/W6cXCyopqnfcQ+KJk4zuthpGGl3g== 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=1695916360; 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=LstUF1dmLcaZ0E8sTDmZ/96tdEnLLA292yFBmmJ+Dlw=; b=JfOrLA0hpHkpdQJRPKOGX6XKfr/GJktJp2G3Bc0rVtzXUQYk34q7S8QmjVYzHl0eHj+vY/ CjbqwjzckvVV2+bIMmX6MzdvESW00o71P+PIooT+3qRHTcp0i2uR7IXnuNbryIlq0f477M qkiAh6xOtJCEF5KkxZ/p00ZIvWl1dv0pSONRDQGPSgJM/sVEG67hp2CXsbO+11mXwSLEoc 6UiLp58jzrONvgoh36ehBC2NiGNqh7A2CHv8X8alkG5DZc2WyutCMHjsECaTjnr7HKrkKy Ibsos5HFBAPhZoN7Rfs6I2QqwMtxsqdQcKhlqo2xxeLfjZwvL85J94TvaFnnHA== 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 4RxJ084PNBzCTk; Thu, 28 Sep 2023 15:52:40 +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 38SFqeUo022271; Thu, 28 Sep 2023 15:52:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 38SFqeNX022268; Thu, 28 Sep 2023 15:52:40 GMT (envelope-from git) Date: Thu, 28 Sep 2023 15:52:40 GMT Message-Id: <202309281552.38SFqeNX022268@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: 8f49f83ef5f3 - main - syslogd: Move action parsing into its own 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: 8f49f83ef5f3059621365adc958eab560776a9f0 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=8f49f83ef5f3059621365adc958eab560776a9f0 commit 8f49f83ef5f3059621365adc958eab560776a9f0 Author: Jake Freeland AuthorDate: 2023-09-01 02:50:49 +0000 Commit: Mark Johnston CommitDate: 2023-09-28 15:51:53 +0000 syslogd: Move action parsing into its own function Clean up the cfline() function by moving action parsing into its own function. Reviewed by: markj MFC after: 3 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D41375 --- usr.sbin/syslogd/syslogd.c | 141 ++++++++++++++++++++++++--------------------- 1 file changed, 74 insertions(+), 67 deletions(-) diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index 6c07d60b484f..5965eb2b0252 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -2966,78 +2966,14 @@ parse_selector(const char *p, struct filed *f) return (q); } -/* - * Crack a configuration file line - */ static void -cfline(const char *line, const char *prog, const char *host, - const char *pfilter) +parse_action(const char *p, struct filed *f) { - struct filed *f; struct addrinfo hints, *res; int error, i; - const char *p, *q; + const char *q; bool syncfile; - dprintf("cfline(\"%s\", f, \"%s\", \"%s\", \"%s\")\n", line, prog, - host, pfilter); - - f = calloc(1, sizeof(*f)); - if (f == NULL) { - logerror("malloc"); - exit(1); - } - errno = 0; /* keep strerror() stuff out of logerror messages */ - - for (i = 0; i <= LOG_NFACILITIES; i++) - f->f_pmask[i] = INTERNAL_NOPRI; - - /* save hostname if any */ - if (host && *host == '*') - host = NULL; - if (host) { - int hl; - - f->f_host = strdup(host); - if (f->f_host == NULL) { - logerror("strdup"); - exit(1); - } - hl = strlen(f->f_host); - if (hl > 0 && f->f_host[hl-1] == '.') - f->f_host[--hl] = '\0'; - /* RFC 5424 prefers logging FQDNs. */ - if (RFC3164OutputFormat) - trimdomain(f->f_host, hl); - } - - /* save program name if any */ - if (prog && *prog == '*') - prog = NULL; - if (prog) { - f->f_program = strdup(prog); - if (f->f_program == NULL) { - logerror("strdup"); - exit(1); - } - } - - if (pfilter) { - f->f_prop_filter = prop_filter_compile(pfilter); - if (f->f_prop_filter == NULL) { - logerror("filter compile error"); - exit(1); - } - } - - /* scan through the list of selectors */ - for (p = line; *p != '\0' && *p != '\t' && *p != ' ';) - p = parse_selector(p, f); - - /* skip to action part */ - while (*p == '\t' || *p == ' ') - p++; - if (*p == '-') { syncfile = false; p++; @@ -3140,9 +3076,80 @@ cfline(const char *line, const char *prog, const char *host, f->f_type = F_USERS; break; } - STAILQ_INSERT_TAIL(&fhead, f, next); } +/* + * Crack a configuration file line + */ +static void +cfline(const char *line, const char *prog, const char *host, + const char *pfilter) +{ + struct filed *f; + const char *p; + + dprintf("cfline(\"%s\", f, \"%s\", \"%s\", \"%s\")\n", line, prog, + host, pfilter); + + f = calloc(1, sizeof(*f)); + if (f == NULL) { + logerror("malloc"); + exit(1); + } + errno = 0; /* keep strerror() stuff out of logerror messages */ + + for (int i = 0; i <= LOG_NFACILITIES; i++) + f->f_pmask[i] = INTERNAL_NOPRI; + + /* save hostname if any */ + if (host && *host == '*') + host = NULL; + if (host) { + int hl; + + f->f_host = strdup(host); + if (f->f_host == NULL) { + logerror("strdup"); + exit(1); + } + hl = strlen(f->f_host); + if (hl > 0 && f->f_host[hl-1] == '.') + f->f_host[--hl] = '\0'; + /* RFC 5424 prefers logging FQDNs. */ + if (RFC3164OutputFormat) + trimdomain(f->f_host, hl); + } + + /* save program name if any */ + if (prog && *prog == '*') + prog = NULL; + if (prog) { + f->f_program = strdup(prog); + if (f->f_program == NULL) { + logerror("strdup"); + exit(1); + } + } + + if (pfilter) { + f->f_prop_filter = prop_filter_compile(pfilter); + if (f->f_prop_filter == NULL) { + logerror("filter compile error"); + exit(1); + } + } + + /* scan through the list of selectors */ + for (p = line; *p != '\0' && *p != '\t' && *p != ' ';) + p = parse_selector(p, f); + + /* skip to action part */ + while (*p == '\t' || *p == ' ') + p++; + parse_action(p, f); + + STAILQ_INSERT_TAIL(&fhead, f, next); +} /* * Decode a symbolic name to a numeric value