From owner-svn-src-all@FreeBSD.ORG Wed Dec 19 19:16:33 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 B4948852; Wed, 19 Dec 2012 19:16:33 +0000 (UTC) (envelope-from delphij@delphij.net) Received: from anubis.delphij.net (anubis.delphij.net [64.62.153.212]) by mx1.freebsd.org (Postfix) with ESMTP id 893AA8FC0A; Wed, 19 Dec 2012 19:16:33 +0000 (UTC) Received: from epsilon.delphij.net (drawbridge.ixsystems.com [206.40.55.65]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by anubis.delphij.net (Postfix) with ESMTPSA id 9A8EF22C32; Wed, 19 Dec 2012 11:16:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=delphij.net; s=anubis; t=1355944587; bh=IWxvwyCU5MVZgMl1sgOq3sAVx55rTKqt6QLBSa0Xpww=; h=Date:From:Reply-To:To:CC:Subject:References:In-Reply-To; b=02Hiam4Ebthai11TeBb6cGSIS+VJc9pGmFn48axd4CKd7lbMdJhLkgocG+6yahnWh t5yf+/jiFajERo/ohjaDOWfVyC+Ow4BENXldJH+Nqf7UcdFRniJVFxIbovKkOMp0m8 wTULAsWRm2rz/3GjmgMlUg7u+skgWErSnvBffZH8= Message-ID: <50D2128A.7030205@delphij.net> Date: Wed, 19 Dec 2012 11:16:26 -0800 From: Xin Li Organization: The FreeBSD Project MIME-Version: 1.0 To: Alfred Perlstein Subject: Re: svn commit: r244198 - in head: etc/rc.d sbin/sysctl References: <201212132332.qBDNWmK4037503@svn.freebsd.org> <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> In-Reply-To: X-Enigmail-Version: 1.4.6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: Ian Lepore , "src-committers@freebsd.org" , "svn-src-all@freebsd.org" , Xin LI , "svn-src-head@freebsd.org" , Andrey Zonov X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: d@delphij.net 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 19:16:33 -0000 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 On 12/19/12 09:37, Alfred Perlstein wrote: > I think that it's a good idea. Maybe there's some way to give > sysctl.conf the equivalent of #file preprocessor directives? /me seeing sysctl(8) expanding to grow e-mail reading capability in the future? :) It may be worthy to make sysctl(8) to accept mutiple -f's, but it seems to be hard to write shell scripts that utilizes this feature in a elegant manner. It shouldn't be hard to add -f - capability as well, which will be useful for applications like FreeNAS. Jilles also have some comments that I wanted to address as well. > Sent from my iPhone > > On Dec 19, 2012, at 7:56 AM, Ian Lepore > wrote: > >> Hrm. Yeah, it would. Or at least, it might. If the error >> message cites the text of the line it chokes on, maybe that's not >> a problem. >> >> Running sysctl once passing it a list of files would fix that, >> but would probably be more complexity than it's worth. I just >> always try to find ways to reduce rc processing time on wimpy >> platforms, so these wild ideas pop into my head. >> >> -- Ian >> >> On Wed, 2012-12-19 at 07:52 -0800, Alfred Perlstein wrote: >>> Wouldn't this obfuscate any errors in files? >>> >>> Sent from my iPhone >>> >>> On Dec 19, 2012, at 7:37 AM, Ian Lepore >>> wrote: >>> >>>> On Wed, 2012-12-19 at 19:02 +0400, Andrey Zonov wrote: >>>>> On 12/14/12 3:32 AM, Xin LI wrote: >>>>>> Author: delphij Date: Thu Dec 13 23:32:47 2012 New >>>>>> Revision: 244198 URL: >>>>>> http://svnweb.freebsd.org/changeset/base/244198 >>>>>> >>>>>> Log: Teach sysctl(8) about parsing a file (while I'm >>>>>> there also give it capability of parsing both = and : >>>>>> formats). >>>>>> >>>>>> Submitted by: hrs (initial version, bugs are mine) MFC >>>>>> after: 3 months >>>>>> >>>>>> Modified: head/etc/rc.d/sysctl head/sbin/sysctl/sysctl.8 >>>>>> head/sbin/sysctl/sysctl.c >>>>>> >>>>>> Modified: head/etc/rc.d/sysctl >>>>>> ============================================================================== >>>>>> >>>>>> - --- head/etc/rc.d/sysctl Thu Dec 13 23:19:13 2012 (r244197) >>>>>> +++ head/etc/rc.d/sysctl Thu Dec 13 23:32:47 2012 >>>>>> (r244198) @@ -8,51 +8,27 @@ . /etc/rc.subr >>>>>> >>>>>> name="sysctl" +command="/sbin/sysctl" stop_cmd=":" >>>>>> start_cmd="sysctl_start" reload_cmd="sysctl_start" >>>>>> lastload_cmd="sysctl_start last" extra_commands="reload >>>>>> lastload" >>>>>> >>>>>> -# -# Read in a file containing sysctl settings and set >>>>>> things accordingly. -# -parse_file() -{ - if [ -f $1 >>>>>> ]; then - while read var comments - do - >>>>>> case ${var} in - \#*|'') - ;; - >>>>>> *) - mib=${var%=*} - >>>>>> val=${var#*=} - - if >>>>>> current_value=`${SYSCTL} -n ${mib} 2>/dev/null`; then - >>>>>> case ${current_value} in - ${val}) - >>>>>> ;; - *) - if ! >>>>>> sysctl "${var}" >/dev/null 2>&1; then - >>>>>> warn "unable to set ${var}" - fi - >>>>>> ;; - esac - elif [ "$2" >>>>>> = "last" ]; then - warn "sysctl ${mib} >>>>>> does not exist." - fi - ;; >>>>>> - esac - done < $1 - fi -} - >>>>>> sysctl_start() { - - parse_file /etc/sysctl.conf $1 - >>>>>> parse_file /etc/sysctl.conf.local $1 + case $1 in + >>>>>> last) + command_args="-i -f" + ;; + *) + >>>>>> command_args="-f" + ;; + esac + + for _f in >>>>>> /etc/sysctl.conf /etc/sysctl.conf.local; do + [ -r >>>>>> ${_f} ] && ${command} ${command_args} ${_f} > /dev/null + >>>>>> done } >>>>>> >>>>>> load_rc_config $name >>>>> >>>>> Hi, >>>>> >>>>> I'd really like to see something like the patch bellow in >>>>> the tree. I found it very useful with cfengine >>>>> configuration (as like as cron.d). >>>>> >>>>> What do think? >>>>> >>>>> diff --git a/etc/rc.d/sysctl b/etc/rc.d/sysctl index >>>>> 36f1414..014e4c5 100755 --- a/etc/rc.d/sysctl +++ >>>>> b/etc/rc.d/sysctl @@ -26,7 +26,7 @@ sysctl_start() ;; esac >>>>> >>>>> - for _f in /etc/sysctl.conf /etc/sysctl.conf.local; >>>>> do + for _f in `ls /etc/sysctl.d/* 2> /dev/null` >>>>> /etc/sysctl.conf /etc/sysctl.conf.local; do [ -r ${_f} ] && >>>>> ${command} ${command_args} ${_f} > /dev/null done } >>>> >>>> Instead of running sysctl a bunch of times, how about >>>> something conceptually similar to >>>> >>>> cat /etc/sysctl.d/* /etc/sysctl.conf | sysctl -f - >>>> >>>> Along with this (untested) patch to make sysctl understand >>>> "-f -". >>>> >>>> Hmmm, is /dev/stdin available as early as sysctl.conf runs? >>>> If not, the attached patch isn't going to work. >>>> >>>> -- Ian >>>> >>>> diff -r cc5bd6d80aa1 sbin/sysctl/sysctl.c --- >>>> sbin/sysctl/sysctl.c Sun Aug 19 11:01:08 2012 -0600 +++ >>>> sbin/sysctl/sysctl.c Wed Dec 19 08:31:14 2012 -0700 @@ >>>> -112,7 +112,10 @@ main(int argc, char **argv) eflag = 1; >>>> break; case 'f': - conffile = optarg; + if >>>> (strcmp(optarg, "-") == 0) + conffile = "/dev/stdin"; + >>>> else + conffile = optarg; break; case 'h': hflag = 1; >>> _______________________________________________ >>> svn-src-all@freebsd.org mailing list >>> http://lists.freebsd.org/mailman/listinfo/svn-src-all To >>> unsubscribe, send any mail to >>> "svn-src-all-unsubscribe@freebsd.org" >> >> - -- Xin LI https://www.delphij.net/ FreeBSD - The Power to Serve! Live free or die -----BEGIN PGP SIGNATURE----- iQEcBAEBCAAGBQJQ0hKKAAoJEG80Jeu8UPuzBGUIAMZHbBqBtWCKeAd1+q8rSGqp 5BkFrKAHHgFbYEA2N9KwMZLqv9iQuBCpdXclUrhivT29A+FtdpUDgDO/LmDPsU71 Xj3hr+VpS47YCeW0jZqbJqpr8QiYdpduJ/MuaykI8QHo8+OPsjupzaQhclKrqcD1 1hVVUnolKXw5X2tIVjDBSpM7NYjtGCk0N3Xca49CJOZ+2aPv8oNHImasxQejT2t5 34OThhWSP+Ir4GNbsPVt/K+qtGiKY8Ugwm3O4M4ssS7hys/orkCFUhBd94Ty7XDD 8nxcbHA5uX5fVkxJ9aKo6VEfeyjP+Dw3CnKdSgoNVDKlAagr+hsHK6B7m0Lgk7s= =F93W -----END PGP SIGNATURE-----