From owner-freebsd-hackers@FreeBSD.ORG Wed Nov 30 22:07:26 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 01F82106566C for ; Wed, 30 Nov 2011 22:07:26 +0000 (UTC) (envelope-from ml@my.gd) Received: from mail-fx0-f54.google.com (mail-fx0-f54.google.com [209.85.161.54]) by mx1.freebsd.org (Postfix) with ESMTP id 8D3518FC13 for ; Wed, 30 Nov 2011 22:07:25 +0000 (UTC) Received: by faak28 with SMTP id k28so1435248faa.13 for ; Wed, 30 Nov 2011 14:07:24 -0800 (PST) Received: by 10.180.81.73 with SMTP id y9mr3004145wix.37.1322690844484; Wed, 30 Nov 2011 14:07:24 -0800 (PST) Received: from dfleuriot.local (angel.c-mal.com. [82.241.189.111]) by mx.google.com with ESMTPS id hq5sm981454wib.7.2011.11.30.14.07.20 (version=SSLv3 cipher=OTHER); Wed, 30 Nov 2011 14:07:20 -0800 (PST) Message-ID: <4ED6A916.9030409@my.gd> Date: Wed, 30 Nov 2011 23:07:18 +0100 From: Damien Fleuriot User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:8.0) Gecko/20111105 Thunderbird/8.0 MIME-Version: 1.0 To: freebsd-hackers@freebsd.org References: <20111125073630.GC7915@DataIX.net> <201111301152.47002.jhb@freebsd.org> <20111130184815.GA70174@DataIX.net> In-Reply-To: <20111130184815.GA70174@DataIX.net> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: sysctl description spillover and also setting the sysctl ? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Nov 2011 22:07:26 -0000 On 11/30/11 7:48 PM, Jason Hellenthal wrote: > > > On Wed, Nov 30, 2011 at 11:52:46AM -0500, John Baldwin wrote: >> On Friday, November 25, 2011 2:36:30 am Jason Hellenthal wrote: >>> >>> Found a troubling result of the following and figured someone might want to >> take a look. >>> >>> Pay close attention to the output and behavior. >>> >>> sysctl net.inet.udp.blackhole=0 >>> sysctl net.inet.udp.blackhole >>> sysctl -d net.inet.udp.blackhole=1 >>> sysctl net.inet.udp.blackhole >>> >>> >>> Is this expected ? should it not just display the description instead of >> adjusting ? as well not display the description like it is adjusting the >> description too ? >> >> Hah, cute. It should probably fail with an error if you do something like >> that, yes. >> > > Yeah thats what I thought about it to but the more I thought about it, if it just displayed the values changing instead of the description when =N is supplied I think that would be acceptable to. 0 -> 1 in this case. Or possibly sys.oid: 0 -> 1 # since sysctl.conf(5) also takes comments like that. > > Not really thats something at the top of the list for fixes though. Low fruit. Food for thought. > Ok so I'm totally not a dev, don't take my findings for granted, but: (gdb) run The program being debugged has been started already. Start it from the beginning? (y or n) y Starting program: /usr/src/sbin/sysctl/sysctl -d net.inet.udp.blackhole=1 Breakpoint 5, show_var (oid=0x7fffffffe1d0, nlen=4) at /usr/src/sbin/sysctl/sysctl.c:549 549 { (gdb) s 562 bzero(buf, BUFSIZ); (gdb) s 563 bzero(name, BUFSIZ); (gdb) s 564 qoid[0] = 0; (gdb) s 565 memcpy(qoid + 2, oid, nlen * sizeof(int)); (gdb) s 567 qoid[1] = 1; (gdb) s 568 j = sizeof(name); (gdb) s 569 i = sysctl(qoid, nlen + 2, name, &j, 0, 0); (gdb) s 570 if (i || !j) (gdb) s 573 if (Nflag) { (gdb) s 578 if (eflag) (gdb) s 581 sep = ": "; (gdb) s 583 if (dflag) { /* just print description */ (gdb) s 584 qoid[1] = 5; (gdb) s 585 j = sizeof(buf); (gdb) s 586 i = sysctl(qoid, nlen + 2, buf, &j, 0, 0); (gdb) s 587 if (!nflag) (gdb) s 588 printf("%s%s", name, sep); (gdb) s net.inet.udp.blackhole: 589 printf("%s", buf); (gdb) s Do not send port unreachables for refused connects 590 return (0); (gdb) s 719 } At this point, we have shown the description and should exit. Instead, we're calling parse() again ? (gdb) s parse (string=0x7fffffffee07 "net.inet.udp.blackhole") at /usr/src/sbin/sysctl/sysctl.c:299 299 if (sysctl(mib, len, 0, 0, newval, newsize) == -1) { (gdb) s 318 if (!bflag) (gdb) s 319 printf(" -> "); (gdb) s -> 320 i = nflag; (gdb) s 321 nflag = 1; (gdb) s 322 j = show_var(mib, len); (gdb) s Breakpoint 5, show_var (oid=0x7fffffffe1d0, nlen=4) at /usr/src/sbin/sysctl/sysctl.c:549 549 { (gdb) s 562 bzero(buf, BUFSIZ); (gdb) s 563 bzero(name, BUFSIZ); (gdb) s 564 qoid[0] = 0; (gdb) s 565 memcpy(qoid + 2, oid, nlen * sizeof(int)); (gdb) s 567 qoid[1] = 1; (gdb) s 568 j = sizeof(name); (gdb) s 569 i = sysctl(qoid, nlen + 2, name, &j, 0, 0); (gdb) s 570 if (i || !j) (gdb) s 573 if (Nflag) { (gdb) s 578 if (eflag) (gdb) s 581 sep = ": "; (gdb) s 583 if (dflag) { /* just print description */ (gdb) s 584 qoid[1] = 5; (gdb) s 585 j = sizeof(buf); (gdb) s 586 i = sysctl(qoid, nlen + 2, buf, &j, 0, 0); (gdb) s 587 if (!nflag) (gdb) s 589 printf("%s", buf); (gdb) s Do not send port unreachables for refused connects 590 return (0); (gdb) s 719 } (gdb) s parse (string=0x7fffffffee07 "net.inet.udp.blackhole") at /usr/src/sbin/sysctl/sysctl.c:323 323 if (!j && !bflag) (gdb) s 324 putchar('\n'); (gdb) s __sputc (_c=10, _p=0x80085a810) at stdio.h:457 457 if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n')) (gdb) s 460 return (__swbuf(_c, _p)); (gdb) s 461 } (gdb) s parse (string=0x7fffffffee07 "net.inet.udp.blackhole") at /usr/src/sbin/sysctl/sysctl.c:325 325 nflag = i; (gdb) s 327 } (gdb) s main (argc=0, argv=0x7fffffffeb48) at /usr/src/sbin/sysctl/sysctl.c:154 154 while (argc-- > 0) (gdb) s 156 exit(warncount); (gdb) s Program exited normally. I think that the issue here is that sysctl continues being run after displaying the description at line 588. I would assume that upon reaching the closing hyphen at line 719 , sysctl would want to stop. It was asked to show a description, it has, end of the story. Instead, at line 590, we simply return 0, then continue running. Perhaps we would want sysctl to exit, instead of returning 0 ?