Date: Tue, 16 Jun 2020 19:34:41 +0200 From: "Kristof Provost" <kp@FreeBSD.org> To: "Ed Maste" <emaste@freebsd.org> Cc: "Ian Lepore" <ian@freebsd.org>, "Toomas Soome" <tsoome@freebsd.org>, src-committers <src-committers@freebsd.org>, svn-src-all <svn-src-all@freebsd.org>, svn-src-head <svn-src-head@freebsd.org> Subject: Re: svn commit: r362217 - head/stand/common Message-ID: <E023EB92-0AC3-4AD8-A309-81AA6E07F80F@FreeBSD.org> In-Reply-To: <CAPyFy2D1mhkxR00BGB1Ufn3PLRe%2Bb-t%2Bz_bgss=7am%2Bn3inWjw@mail.gmail.com> References: <202006160705.05G753T4057972@repo.freebsd.org> <55903c38d363aef2a6f6d0075dd4526b86d51258.camel@freebsd.org> <CAPyFy2D1mhkxR00BGB1Ufn3PLRe%2Bb-t%2Bz_bgss=7am%2Bn3inWjw@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On 16 Jun 2020, at 19:11, Ed Maste wrote: > On Tue, 16 Jun 2020 at 13:01, Ian Lepore <ian@freebsd.org> wrote: >> >> As much as I prefer doing it this way, style(9) doesn't allow for >> variable declarations inside a for() statement (or even inside a >> local >> block, which is just too 1980s for me, but it is still our standard). > > Perhaps it's time to update style(9) to at least permit these uses, as > we've done with the blank line at the beginning of functions with no > local variables, and with braces around single-line bodies. We have 431 instances of `for (int i` in sys alone. It’s not so much a question of allowing it as acknowledging reality at this point. Best regards, Kristof From owner-svn-src-all@freebsd.org Tue Jun 16 17:45:24 2020 Return-Path: <owner-svn-src-all@freebsd.org> Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 80C8E345877; Tue, 16 Jun 2020 17:45:24 +0000 (UTC) (envelope-from eugen@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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49mbFc2hm2z4RtQ; Tue, 16 Jun 2020 17:45:24 +0000 (UTC) (envelope-from eugen@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5360E12F9B; Tue, 16 Jun 2020 17:45:24 +0000 (UTC) (envelope-from eugen@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 05GHjOHM053570; Tue, 16 Jun 2020 17:45:24 GMT (envelope-from eugen@FreeBSD.org) Received: (from eugen@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 05GHjOpT053569; Tue, 16 Jun 2020 17:45:24 GMT (envelope-from eugen@FreeBSD.org) Message-Id: <202006161745.05GHjOpT053569@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: eugen set sender to eugen@FreeBSD.org using -f From: Eugene Grosbein <eugen@FreeBSD.org> Date: Tue, 16 Jun 2020 17:45:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r362233 - head/usr.sbin/newsyslog X-SVN-Group: head X-SVN-Commit-Author: eugen X-SVN-Commit-Paths: head/usr.sbin/newsyslog X-SVN-Commit-Revision: 362233 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" <svn-src-all.freebsd.org> List-Unsubscribe: <https://lists.freebsd.org/mailman/options/svn-src-all>, <mailto:svn-src-all-request@freebsd.org?subject=unsubscribe> List-Archive: <http://lists.freebsd.org/pipermail/svn-src-all/> List-Post: <mailto:svn-src-all@freebsd.org> List-Help: <mailto:svn-src-all-request@freebsd.org?subject=help> List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/svn-src-all>, <mailto:svn-src-all-request@freebsd.org?subject=subscribe> X-List-Received-Date: Tue, 16 Jun 2020 17:45:24 -0000 Author: eugen Date: Tue Jun 16 17:45:23 2020 New Revision: 362233 URL: https://svnweb.freebsd.org/changeset/base/362233 Log: newsyslog(8): make configuration parser more robust. Currently newsyslog supports <include> directive that is used in our default /etc/newsyslog.conf in the following form: <include> /usr/local/etc/newsyslog.conf.d/* While this is suitable for ports installing their own rules for logs rotation, this also makes newsyslog break entire processing of all files if it encounters single line it cannot parse. This includes lines referring to nonexistent username/group for log ownership, so newsyslog stops calling errx() function in the parser. With this fix, newsyslog uses warnx() instead of errx() in such cases to print a warning, recover gracefully and continue with execution. Among other cases, this unbreaks initial creation of log files having flag "C" at boot time (newsyslog -CN). This is most important for systems having RAM-based /var file system like nanobsd(8)-based that rely on newsyslog to bring system log files into existence. MFC after: 1 month Modified: head/usr.sbin/newsyslog/newsyslog.c Modified: head/usr.sbin/newsyslog/newsyslog.c ============================================================================== --- head/usr.sbin/newsyslog/newsyslog.c Tue Jun 16 17:05:38 2020 (r362232) +++ head/usr.sbin/newsyslog/newsyslog.c Tue Jun 16 17:45:23 2020 (r362233) @@ -1078,9 +1078,11 @@ parse_file(FILE *cf, struct cflist *work_p, struct cfl q = parse = missing_field(sob(line), errline); parse = son(line); - if (!*parse) - errx(1, "malformed line (missing fields):\n%s", + if (!*parse) { + warnx("malformed line (missing fields):\n%s", errline); + continue; + } *parse = '\0'; /* @@ -1132,22 +1134,24 @@ parse_file(FILE *cf, struct cflist *work_p, struct cfl continue; } +#define badline(msg, ...) do { \ + warnx(msg, __VA_ARGS__); \ + goto cleanup; \ +} while (0) + special = 0; working = init_entry(q, NULL); if (strcasecmp(DEFAULT_MARKER, q) == 0) { special = 1; - if (*defconf_p != NULL) { - warnx("Ignoring duplicate entry for %s!", q); - free_entry(working); - continue; - } + if (*defconf_p != NULL) + badline("Ignoring duplicate entry for %s!", q); *defconf_p = working; } q = parse = missing_field(sob(parse + 1), errline); parse = son(parse); if (!*parse) - errx(1, "malformed line (missing fields):\n%s", + badline("malformed line (missing fields):\n%s", errline); *parse = '\0'; if ((group = strchr(q, ':')) != NULL || @@ -1156,7 +1160,7 @@ parse_file(FILE *cf, struct cflist *work_p, struct cfl if (*q) { if (!(isnumberstr(q))) { if ((pwd = getpwnam(q)) == NULL) - errx(1, + badline( "error in config file; unknown user:\n%s", errline); working->uid = pwd->pw_uid; @@ -1169,7 +1173,7 @@ parse_file(FILE *cf, struct cflist *work_p, struct cfl if (*q) { if (!(isnumberstr(q))) { if ((grp = getgrnam(q)) == NULL) - errx(1, + badline( "error in config file; unknown group:\n%s", errline); working->gid = grp->gr_gid; @@ -1181,7 +1185,7 @@ parse_file(FILE *cf, struct cflist *work_p, struct cfl q = parse = missing_field(sob(parse + 1), errline); parse = son(parse); if (!*parse) - errx(1, "malformed line (missing fields):\n%s", + badline("malformed line (missing fields):\n%s", errline); *parse = '\0'; } else { @@ -1190,7 +1194,7 @@ parse_file(FILE *cf, struct cflist *work_p, struct cfl } if (!sscanf(q, "%o", &working->permissions)) - errx(1, "error in config file; bad permissions:\n%s", + badline("error in config file; bad permissions:\n%s", errline); if ((working->permissions & ~DEFFILEMODE) != 0) { warnx("File mode bits 0%o changed to 0%o in line:\n%s", @@ -1202,17 +1206,17 @@ parse_file(FILE *cf, struct cflist *work_p, struct cfl q = parse = missing_field(sob(parse + 1), errline); parse = son(parse); if (!*parse) - errx(1, "malformed line (missing fields):\n%s", + badline("malformed line (missing fields):\n%s", errline); *parse = '\0'; if (!sscanf(q, "%d", &working->numlogs) || working->numlogs < 0) - errx(1, "error in config file; bad value for count of logs to save:\n%s", + badline("error in config file; bad value for count of logs to save:\n%s", errline); q = parse = missing_field(sob(parse + 1), errline); parse = son(parse); if (!*parse) - errx(1, "malformed line (missing fields):\n%s", + badline("malformed line (missing fields):\n%s", errline); *parse = '\0'; if (isdigitch(*q)) @@ -1241,14 +1245,14 @@ parse_file(FILE *cf, struct cflist *work_p, struct cfl else if (*ep == '*') working->hours = -1; else if (ul > INT_MAX) - errx(1, "interval is too large:\n%s", errline); + badline("interval is too large:\n%s", errline); else working->hours = ul; if (*ep == '\0' || strcmp(ep, "*") == 0) goto no_trimat; if (*ep != '@' && *ep != '$') - errx(1, "malformed interval/at:\n%s", errline); + badline("malformed interval/at:\n%s", errline); working->flags |= CE_TRIMAT; working->trim_at = ptime_init(NULL); @@ -1259,10 +1263,10 @@ parse_file(FILE *cf, struct cflist *work_p, struct cfl res = ptime_relparse(working->trim_at, ptm_opts, ptimeget_secs(timenow), ep + 1); if (res == -2) - errx(1, "nonexistent time for 'at' value:\n%s", + badline("nonexistent time for 'at' value:\n%s", errline); else if (res < 0) - errx(1, "malformed 'at' value:\n%s", errline); + badline("malformed 'at' value:\n%s", errline); } no_trimat: @@ -1325,7 +1329,7 @@ no_trimat: case 'f': /* Used by OpenBSD for "CE_FOLLOW" */ case 'm': /* Used by OpenBSD for "CE_MONITOR" */ default: - errx(1, "illegal flag in config file -- %c", + badline("illegal flag in config file -- %c", *q); } } @@ -1347,7 +1351,7 @@ no_trimat: else if (isalnum(*q)) goto got_sig; else { - errx(1, + badline( "illegal pid file or signal in config file:\n%s", errline); } @@ -1365,7 +1369,7 @@ no_trimat: got_sig: working->sig = parse_signal(q); if (working->sig < 1 || working->sig >= sys_nsig) { - errx(1, + badline( "illegal signal in config file:\n%s", errline); } @@ -1416,7 +1420,11 @@ got_sig: } else { STAILQ_INSERT_TAIL(work_p, working, cf_nextp); } - } + continue; +cleanup: + free_entry(working); +#undef badline + } /* while (fgets(line, BUFSIZ, cf)) */ if (errline != NULL) free(errline); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E023EB92-0AC3-4AD8-A309-81AA6E07F80F>