From owner-svn-src-all@FreeBSD.ORG Mon Sep 3 16:09:14 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7DD68106566C; Mon, 3 Sep 2012 16:09:14 +0000 (UTC) (envelope-from mdf356@gmail.com) Received: from mail-pz0-f54.google.com (mail-pz0-f54.google.com [209.85.210.54]) by mx1.freebsd.org (Postfix) with ESMTP id 3B2C88FC1F; Mon, 3 Sep 2012 16:09:14 +0000 (UTC) Received: by dadr6 with SMTP id r6so3600389dad.13 for ; Mon, 03 Sep 2012 09:09:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=3caLdzpx6pRAHe34ZsIYxBPNiBwIUcVQ36gZ58UG1kI=; b=d2F0zBD0+vGln+vPrbp68fshsQhmTZYbxWetRLjEaNBJDGrwdKOY78D/tCeu9O2Exp 5rm4DLIwwKl7Bee6xr+zoraFSlkBVI1aKDiyFgzd/CNXKtFv3mtYkLXR3845D1SMDIGe 8wUtIwn3gBVfCvQloNnrqVnXt7QyM1YgZthBjucb4rCLaOaikT81b9sr5lsXyKrfcoEZ bTL3DKm1d1g/zUMvY0DkgnBebVDlz5D8CA1V/wqIO682UG6fHEaFLZKItW7NkTX0c//u VHwCpS6ZCotGSrjMiuSsRywTfJxekjZIsGo/PBiW/EvSswng+tyysTtItnTyrVNmc3TH 4z4g== MIME-Version: 1.0 Received: by 10.66.76.135 with SMTP id k7mr35101594paw.2.1346688548199; Mon, 03 Sep 2012 09:09:08 -0700 (PDT) Sender: mdf356@gmail.com Received: by 10.68.13.170 with HTTP; Mon, 3 Sep 2012 09:09:08 -0700 (PDT) In-Reply-To: <201209030852.q838q6lC053405@svn.freebsd.org> References: <201209030852.q838q6lC053405@svn.freebsd.org> Date: Mon, 3 Sep 2012 09:09:08 -0700 X-Google-Sender-Auth: LOZjx1uEPjZJyO_eZVBeneSJwlA Message-ID: From: mdf@FreeBSD.org To: Aleksandr Rybalko Content-Type: text/plain; charset=ISO-8859-1 Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r240067 - head/sys/kern X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 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: Mon, 03 Sep 2012 16:09:14 -0000 On Mon, Sep 3, 2012 at 1:52 AM, Aleksandr Rybalko wrote: > Author: ray > Date: Mon Sep 3 08:52:05 2012 > New Revision: 240067 > URL: http://svn.freebsd.org/changeset/base/240067 > > Log: > Add kern.hintmode sysctl variable to show current state of hints: > 0 - loader hints in environment only; > 1 - static hints only > 2 - fallback mode (Dynamic KENV with fallback to kernel environment) > Add kern.hintmode write handler, accept only value 2. That will switch > static KENV to dynamic. So it will be possible to change device hints. > > Approved by: adrian (mentor) > > Modified: > head/sys/kern/subr_hints.c > > Modified: head/sys/kern/subr_hints.c > ============================================================================== > --- head/sys/kern/subr_hints.c Mon Sep 3 07:18:24 2012 (r240066) > +++ head/sys/kern/subr_hints.c Mon Sep 3 08:52:05 2012 (r240067) > @@ -29,8 +29,10 @@ __FBSDID("$FreeBSD$"); > > #include > #include > +#include > #include > #include > +#include Putting on my style-nazi hat. sysctl comes before systm alphabetically. > #include > > /* > @@ -42,6 +44,81 @@ static int use_kenv; > static char *hintp; > > /* > + * Define kern.hintmode sysctl, which only accept value 2, that cause to > + * switch from Static KENV mode to Dynamic KENV. So systems that have hints > + * compiled into kernel will be able to see/modify KENV (and hints too). > + */ > + > +static int > +sysctl_hintmode(SYSCTL_HANDLER_ARGS) > +{ > + int error, i, from_kenv, value, eqidx; > + const char *cp; > + char *line, *eq; These are not sorted properly; pointers come before scalars, and within the group they should be sorted alphabetically; e.g. "eqidx" comes before all the other ints. > + > + from_kenv = 0; > + cp = kern_envp; > + value = hintmode; > + > + /* Fetch candidate for new hintmode value */ > + error = sysctl_handle_int(oidp, &value, 0, req); > + if (error || !req->newptr) This may be copying existing code, but style(9) explicitly forbids using '!' except on boolean expressions. Since req->newptr is a pointer, an explicit comparison to NULL should be made. This error is repeated later. Thanks, matthew > + return (error); > + > + if (value != 2) > + /* Only accept swithing to hintmode 2 */ > + return (EINVAL); > + > + /* Migrate from static to dynamic hints */ > + switch (hintmode) { > + case 0: > + if (dynamic_kenv) > + /* Already here */ > + hintmode = value; /* XXX: Need we switch or not ? */ > + return (0); > + from_kenv = 1; > + cp = kern_envp; > + break; > + case 1: > + cp = static_hints; > + break; > + case 2: > + /* Nothing to do, hintmode already 2 */ > + return (0); > + } > + > + while (cp) { > + i = strlen(cp); > + if (i == 0) > + break; > + if (from_kenv) { > + if (strncmp(cp, "hint.", 5) != 0) > + /* kenv can have not only hints */ > + continue; > + } > + eq = strchr(cp, '='); > + if (!eq) > + /* Bad hint value */ > + continue; > + eqidx = eq - cp; > + > + line = malloc(i+1, M_TEMP, M_WAITOK); > + strcpy(line, cp); > + line[eqidx] = '\0'; > + setenv(line, line + eqidx + 1); > + free(line, M_TEMP); > + cp += i + 1; > + } > + > + hintmode = value; > + use_kenv = 1; > + return (0); > +} > + > +SYSCTL_PROC(_kern, OID_AUTO, hintmode, CTLTYPE_INT|CTLFLAG_RW, > + &hintmode, 0, sysctl_hintmode, "I", "Get/set current hintmode"); > + > +/* > * Evil wildcarding resource string lookup. > * This walks the supplied env string table and returns a match. > * The start point can be remembered for incremental searches.