From owner-freebsd-stable@FreeBSD.ORG Thu Feb 28 09:41:16 2013 Return-Path: Delivered-To: freebsd-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id E5949C1A; Thu, 28 Feb 2013 09:41:16 +0000 (UTC) (envelope-from andrnils@gmail.com) Received: from mail-oa0-f45.google.com (mail-oa0-f45.google.com [209.85.219.45]) by mx1.freebsd.org (Postfix) with ESMTP id 76B2D17C7; Thu, 28 Feb 2013 09:41:16 +0000 (UTC) Received: by mail-oa0-f45.google.com with SMTP id o6so3123722oag.4 for ; Thu, 28 Feb 2013 01:41:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=yqv97o3poysEMIkgiI514EEkgGFYI1IrRqN6BVv7fsw=; b=sy1/WEBAmcviyDmkk8ZZRS6K/eCAIT8kZ5vmSZdK51Sz53ZawnGczmJVcVger+XekT hTA3JseudgQT+qnuCwbPp0tNF4jNlBb1NGdIfRyFz+Ojcj+lTrpz6K4E87eOqdjdAyLU AzE2T6Tev1kxmOsfPbTP03tB9nmaf8gtVjGNZyt6mmu7sNfC8bzD+Hhk9s1WdSObnXeN C3o3AUPrNSbQD337uiu7lrant/awQgvtAluqvJBCLJ+IrBNpCTZ1jTdQ3W4UDao0rht7 dWFFOLnP6jWw1TGbDMLBXaGZeBgSSP7VOPe907hPdRMqoRdzU8j85i8fWZLgy+AQAMpi Al8g== MIME-Version: 1.0 X-Received: by 10.182.197.6 with SMTP id iq6mr4955363obc.76.1362044147460; Thu, 28 Feb 2013 01:35:47 -0800 (PST) Received: by 10.76.94.12 with HTTP; Thu, 28 Feb 2013 01:35:47 -0800 (PST) In-Reply-To: <20130228081329.GA6194@icarus.home.lan> References: <20130228081329.GA6194@icarus.home.lan> Date: Thu, 28 Feb 2013 10:35:47 +0100 Message-ID: Subject: Re: rc.d/sysctl fails to parse sysctl.conf From: Andreas Nilsson To: Jeremy Chadwick Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 Cc: Chris Rees , FreeBSD Stable Mailing List X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Feb 2013 09:41:17 -0000 On Thu, Feb 28, 2013 at 9:13 AM, Jeremy Chadwick wrote: > On Thu, Feb 28, 2013 at 08:45:11AM +0100, Andreas Nilsson wrote: > > On Wed, Feb 27, 2013 at 10:39 PM, Chris Rees wrote: > > > > > On 27 February 2013 21:19, Andreas Nilsson wrote: > > > > Hello, > > > > > > > > I tried to get my sound working, and long story short: rc.d/sysctl > parses > > > > sysctl.conf wrongly if there are sysctls of the form > > > > > > > > mib=val1=val2 > > > > > > > > which is what you need for sound. For reference I needed/wanted > > > > > > > > dev.hdaa.4.nid25_config=as=1,seq=15 > > > > dev.hdaa.4.nid31_config=as=1 > > > > > > > > I believe the following patch would address the incorrect parsing: > > > > > > > > --- /etc/rc.d/sysctl.old 2013-02-27 22:00:00.000000000 +0100 > > > > +++ /etc/rc.d/sysctl 2013-02-27 22:05:24.000000000 +0100 > > > > @@ -26,7 +26,7 @@ > > > > \#*|'') > > > > ;; > > > > *) > > > > - mib=${var%=*} > > > > + mib=${var%%=*} > > > > val=${var#*=} > > > > > > > > if current_value=`${SYSCTL} -n ${mib} > > > > 2>/dev/null`; then > > > > > > I think that this is the right thing to do here. > > > > > > Chris > > > > As a follow-up question: is sysctl.conf supposed to handle all valid > input > > one can give sysctl on the command line? Using the above example would > > normally be typed: > > sysctl dev.hdaa.4.nid25_config="as=1 seq=15" > > which works, but fails to work from sysctl.conf > > This has to do with how your shell parses things (quotes, etc.) versus > how shell scripts like /etc/rc.d/sysctl do. > > Assuming you read/speak sh: read /etc/rc.d/sysctl. It's not very long, > and fairly easy to follow, barring the %, %%, and # pattern modifier > parts (read sh man page for how those work). /etc/rc.d/sysctl is not a > "file parser" -- instead it relies on sh to do the work. > > Once you read the script, you'll understand how/why apostrophes, double > quotes, and spaces in /etc/sysctl.conf are a problem. "Solving" this > dilemma in sh is a pain in the ass and often involves utter nonsense > like escaping (\) every character and making exceptions; folks who have > written extensive shell scripts will know what I mean when I use the > term "quoting hell". > > That said, here's the general guideline: your /etc/sysctl.conf should > not contain quotes or double-quotes or spaces after the assignment (=), > generally speaking. If there is a sysctl MIB that actually > ***requires*** spaces in its value, then whoever coded their driver/bit > that way should be taken out back and flogged. Hard. This is why you > probably see Andreas using a comma-delimited model (and if that works, > fantastic+great!). > > That said: you can get spaces to work in /etc/sysctl.conf by escaping > them, i.e.: > > some.mib=foo\ bar > > You might be able to escape some types of quotes, but this gets into > "quoting hell" like I said above. Don't bother. As I said, apostrophes > (') and double-quotes (") and spaces (" "), will cause problems, and if > you read the script it'll become apparent why. > > -- > | Jeremy Chadwick jdc@koitsu.org | > | UNIX Systems Administrator http://jdc.koitsu.org/ | > | Mountain View, CA, US | > | Making life hard for others since 1977. PGP 4BD6C0CB | > Yes, the parsing hell is not a nice place to be in. I found that easiest solution was to split the config into separate lines like dev.hdaa.4.nid25_config=as=1 dev.hdaa.4.nid25_config=seq=15 dev.hdaa.4.nid31_config=as=1 Best regards Andreas