From owner-freebsd-hackers@FreeBSD.ORG Sun Mar 22 10:27:24 2015 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id EE256533 for ; Sun, 22 Mar 2015 10:27:23 +0000 (UTC) Received: from ustc.edu.cn (email6.ustc.edu.cn [IPv6:2001:da8:d800::8]) by mx1.freebsd.org (Postfix) with ESMTP id 061FAD5D for ; Sun, 22 Mar 2015 10:27:22 +0000 (UTC) Received: from freebsd (unknown [58.211.218.74]) by newmailweb.ustc.edu.cn (Coremail) with SMTP id LkAmygBXCD38mA5VbvfCAw--.23144S2; Sun, 22 Mar 2015 18:27:13 +0800 (CST) Date: Sun, 22 Mar 2015 18:26:50 +0800 From: Tiwei Bie To: Mateusz Guzik Subject: Re: [PATCH] Finish the task 'Validate coredump format string' Message-ID: <20150322102650.GA14629@freebsd> References: <1426946345-67889-1-git-send-email-btw@mail.ustc.edu.cn> <20150321200500.GC14650@dft-labs.eu> <20150322091853.GA89976@freebsd> <20150322101401.GH14650@dft-labs.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20150322101401.GH14650@dft-labs.eu> User-Agent: Mutt/1.5.23 (2014-03-12) X-CM-TRANSID: LkAmygBXCD38mA5VbvfCAw--.23144S2 X-Coremail-Antispam: 1UD129KBjvJXoW7tF17XryDtr45Cr18tr1DZFb_yoW8tr15p3 y8Wry0yr4Dtw1Uua4xAw1UGa4rtw4ktFWjyrn8G398Zw17WryrXr4vqF1FqFZFgr4Sg3yS va18Was093yYva7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUyEb7Iv0xC_Kw4lb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rw A2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xII jxv20xvEc7CjxVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4 A2jsIEc7CjxVAFwI0_GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IE w4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_JrI_JrylYx0Ex4A2jsIE14v26r4j6F4UMc vjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvEwIxGrwCY02Avz4vE14v_Gw1l42xK82IYc2Ij 64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x 8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1Y6r17MIIYrxkI7VAKI48JMIIF0xvE 2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42 xK8VAvwI8IcIk0rVWrZr1j6s0DMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIE c7CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU5QyCtUUUUU== X-CM-SenderInfo: xewzqzxdloh3xvwfhvlgxou0/1tbiAQUQAVQhl-peFAAFsC Cc: Konstantin Belousov , freebsd-hackers@freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 22 Mar 2015 10:27:24 -0000 On Sun, Mar 22, 2015 at 11:14:01AM +0100, Mateusz Guzik wrote: > On Sun, Mar 22, 2015 at 05:19:40PM +0800, Tiwei Bie wrote: > [..] > > I was somehow convinced that tunables are dealt with other code. > > If such sysctl handler is also called for tunables, the kernel should > pass a flag or some other indicator so that the function knows it is > dealing with a tunable and that would avoid locking and thus solve the > problem. > If a sysctl is registered as a tunable (CTLFLAG_TUN), when calling sysctl_register_oid(), sysctl_load_tunable_by_oid_locked() will be called to fetch the kenv setting (i.e. tunable setting defined in loader.conf) to update the sysctl setting: void sysctl_register_oid(struct sysctl_oid *oidp) { ...... if ((oidp->oid_kind & CTLTYPE) != CTLTYPE_NODE && #ifdef VIMAGE (oidp->oid_kind & CTLFLAG_VNET) == 0 && #endif (oidp->oid_kind & CTLFLAG_TUN) != 0 && (oidp->oid_kind & CTLFLAG_NOFETCH) == 0) { sysctl_load_tunable_by_oid_locked(oidp); } } sysctl_load_tunable_by_oid_locked() will fetch the kenv setting, and call the sysctl handler, e.g. sysctl_kern_corefile() to update the sysctl setting: static void sysctl_load_tunable_by_oid_locked(struct sysctl_oid *oidp) { ...... case CTLTYPE_STRING: penv = kern_getenv(path + rem); if (penv == NULL) return; req.newlen = strlen(penv); req.newptr = penv; break; default: return; } error = sysctl_root_handler_locked(oidp, oidp->oid_arg1, oidp->oid_arg2, &req); if (error != 0) printf("Setting sysctl %s failed: %d\n", path, error); ...... } The tunable setting is just a "name"=value format in kenv. And the kenv codes have no idea of the meaning of the "name". It can also be modified later when system is up by `kenv' command. And the corresponding sysctl setting won't be affected any more. > I'm wondering if we should go a little bit further and get rid of > static char corefilename[MAXPATHLEN] > > and have a static char *corefilename instead. > > A dedicated sysinit func could fetch and validate the tunable, if any. > If no tunable was provided it would alloc memory for the default. > > -- > Mateusz Guzik Best regards, Tiwei Bie