From owner-svn-src-all@FreeBSD.ORG Wed Dec 19 22:59:08 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 49D3D252; Wed, 19 Dec 2012 22:59:08 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: from mail-ie0-f179.google.com (mail-ie0-f179.google.com [209.85.223.179]) by mx1.freebsd.org (Postfix) with ESMTP id BE0188FC12; Wed, 19 Dec 2012 22:59:07 +0000 (UTC) Received: by mail-ie0-f179.google.com with SMTP id k14so3768505iea.10 for ; Wed, 19 Dec 2012 14:59:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=WY9W9Him/eJhhD53LXC+W24+Js8Lo3ZF6cKp5tGSSX8=; b=HHxGdP1t3uHpRwlQM1R7jK0I5z9reEPvC5bil+aagymxyYSXh9rkqxxGts4jbv/eyq 1i9PV0ScrZYQi8V61HrRjUqYvp+3HmrCCGvy/jBrTVgWW7nfNO9z5YnfGGI70jDqHdsq /jGn2sOpfTNPkCY6RjjjojtklnQxxBD+Je7JqbfJ9+8YXKpodBjX0wXNZz8FGNrZZqQa uLfMU1dS/MRCqxCDLGscE0cENP2VHC7qlGzU08nrQ9naslLwik/cmkPK+HGzyg51f9Rd Vp7c9w8LdCXBpuj8rpKoqzxeRTWaqdVxXolNNNCzE8XhCi9NTtv/v7nWXhzvDj5rpLFl W8pQ== X-Received: by 10.50.151.207 with SMTP id us15mr2530507igb.10.1355957941067; Wed, 19 Dec 2012 14:59:01 -0800 (PST) Received: from oddish ([66.11.160.25]) by mx.google.com with ESMTPS id bh3sm11841495igc.0.2012.12.19.14.58.59 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 19 Dec 2012 14:59:00 -0800 (PST) Date: Wed, 19 Dec 2012 17:58:54 -0500 From: Mark Johnston To: d@delphij.net Subject: Re: svn commit: r244198 - in head: etc/rc.d sbin/sysctl Message-ID: <20121219225854.GA8399@oddish> References: <50D1D720.80206@FreeBSD.org> <1355931456.1198.203.camel@revolution.hippie.lan> <05CC5BAD-B968-4A7A-8097-A3344D970D63@mu.org> <1355932607.1198.206.camel@revolution.hippie.lan> <50D2128A.7030205@delphij.net> <20121219210418.GA83983@stack.nl> <50D23961.7090803@delphij.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <50D23961.7090803@delphij.net> User-Agent: Mutt/1.5.21 (2010-09-15) X-Mailman-Approved-At: Thu, 20 Dec 2012 00:10:04 +0000 Cc: Ian Lepore , "src-committers@freebsd.org" , Jilles Tjoelker , Garrett Cooper , "svn-src-all@freebsd.org" , Alfred Perlstein , Xin LI , "svn-src-head@freebsd.org" , Andrey Zonov X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Dec 2012 22:59:08 -0000 On Wed, Dec 19, 2012 at 02:02:09PM -0800, Xin Li wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA256 > > On 12/19/12 13:12, Garrett Cooper wrote: > > On Wed, Dec 19, 2012 at 1:10 PM, Garrett Cooper > > wrote: > > > > ... > > > >> find -exec / echo | xargs ? Seems like there's a better way to > >> solve this. > > > > Of course we also might be overengineering the problem (my > > suggestion definitely was overengineered). Why not pass in the > > appropriate arguments via sysctl_args in /etc/rc.conf ? Thanks, > > Irrelevant. Consider this (extreme) situation: someone distributes > several sets of sysctl values tuned for certain situations, like > tcp.conf, supermicro.conf, ... and wants to put them together in a > directory, it's useful to source from the directory without having to > do a generation of command line on boot, so when something goes wrong, > they just remove the pack rather than changing /etc/rc.conf. At work I've changed the -f flag of syslogd and newsyslog to accept a directory which gets non-recursively searched for input files. This way we can have a directory, say /etc/syslog.d, into which package install scripts can easily drop config files. For something like sysctl this might be a bit much, but it's just a thought. The example diff below is what I have in mind. -Mark diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c index 8fad089..c880b45 100644 --- a/sbin/sysctl/sysctl.c +++ b/sbin/sysctl/sysctl.c @@ -42,6 +42,7 @@ static const char rcsid[] = #endif /* not lint */ #include +#include #include #include #include @@ -49,6 +50,7 @@ static const char rcsid[] = #include #include +#include #include #include #include @@ -64,6 +66,7 @@ static const char *conffile; static int aflag, bflag, dflag, eflag, hflag, iflag; static int Nflag, nflag, oflag, qflag, Tflag, Wflag, xflag; +static int handlefile(const char *); static int oidfmt(int *, int, char *, u_int *); static int parsefile(const char *); static int parse(const char *, int); @@ -165,7 +168,7 @@ main(int argc, char **argv) warncount = 0; if (conffile != NULL) - warncount += parsefile(conffile); + warncount += handlefile(conffile); while (argc-- > 0) warncount += parse(*argv++, 0); @@ -402,6 +405,48 @@ parse(const char *string, int lineno) } static int +handlefile(const char *filename) +{ + DIR *dir; + struct dirent *de; + struct stat sb; + char path[MAXPATHLEN], *fname; + size_t off; + int warncount = 0; + + if (stat(filename, &sb)) + err(EX_NOINPUT, "%s", filename); + if (S_ISREG(sb.st_mode)) { + return (parsefile(filename)); + } else if (!S_ISDIR(sb.st_mode)) + errx(EX_USAGE, "invalid input file '%s'", filename); + + dir = opendir(filename); + if (dir == NULL) + err(EX_NOINPUT, "%s", filename); + off = strlcpy(path, filename, sizeof(path) - 1); + if (off >= sizeof(path) - 1) + errx(EX_NOINPUT, "input path '%s' too long", filename); + + fname = path + off; + *fname++ = '/'; + off++; + while ((de = readdir(dir)) != NULL) { + strlcpy(fname, de->d_name, sizeof(path) - off); + if (stat(path, &sb)) { + warn("%s", path); + continue; + } else if (!S_ISREG(sb.st_mode)) + continue; + + warncount += parsefile(path); + } + closedir(dir); + + return (warncount); +} + +static int parsefile(const char *filename) { FILE *file;