From owner-p4-projects@FreeBSD.ORG Thu Jul 6 11:47:40 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 4F47516A576; Thu, 6 Jul 2006 11:47:40 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2BAA516A572; Thu, 6 Jul 2006 11:47:40 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from server.baldwin.cx (66-23-211-162.clients.speedfactory.net [66.23.211.162]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2E9DB43D53; Thu, 6 Jul 2006 11:47:38 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from zion.baldwin.cx (zion.baldwin.cx [192.168.0.7]) (authenticated bits=0) by server.baldwin.cx (8.13.4/8.13.4) with ESMTP id k66BlZ8r008534; Thu, 6 Jul 2006 07:47:38 -0400 (EDT) (envelope-from jhb@freebsd.org) From: John Baldwin To: Scott Long Date: Thu, 6 Jul 2006 07:37:00 -0400 User-Agent: KMail/1.9.1 References: <200607060348.k663mTHW007992@repoman.freebsd.org> In-Reply-To: <200607060348.k663mTHW007992@repoman.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200607060737.01194.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH authentication, not delayed by milter-greylist-2.0.2 (server.baldwin.cx [192.168.0.1]); Thu, 06 Jul 2006 07:47:38 -0400 (EDT) X-Virus-Scanned: ClamAV 0.87.1/1586/Wed Jul 5 15:22:07 2006 on server.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-4.4 required=4.2 tests=ALL_TRUSTED,BAYES_00 autolearn=ham version=3.1.0 X-Spam-Checker-Version: SpamAssassin 3.1.0 (2005-09-13) on server.baldwin.cx Cc: Perforce Change Reviews Subject: Re: PERFORCE change 100686 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 Jul 2006 11:47:40 -0000 On Wednesday 05 July 2006 23:48, Scott Long wrote: > http://perforce.freebsd.org/chv.cgi?CH=100686 > > Change 100686 by scottl@scottl-wv1u on 2006/07/06 03:47:59 > > Use a sleep mutex to protect kernel environment handling instead of > an sx lock. The sx lock seemed to only be used to get around the > copyout case in kenv(KENV_DUMP) path. Fix that path to safely use a > sleep lock instead. > > Affected files ... > > .. //depot/projects/scottl-camlock/src/sys/kern/kern_environment.c#7 edit > .. //depot/projects/scottl-camlock/src/sys/kern/subr_hints.c#3 edit > .. //depot/projects/scottl-camlock/src/sys/sys/systm.h#7 edit > > Differences ... > > ==== //depot/projects/scottl-camlock/src/sys/kern/kern_environment.c#7 (text+ko) ==== > > @@ -100,7 +99,8 @@ > return (error); > #endif > done = needed = 0; > - sx_slock(&kenv_lock); > + buffer = malloc(uap->len, M_TEMP, M_WAITOK|M_ZERO); > + mtx_lock(&kenv_lock); > for (i = 0; kenvp[i] != NULL; i++) { > len = strlen(kenvp[i]) + 1; > needed += len; > @@ -110,14 +110,15 @@ > * buffer, just keep computing the required size. > */ > if (uap->value != NULL && len > 0) { > - error = copyout(kenvp[i], uap->value + done, > - len); > - if (error) > + if (done + len > uap->len) > break; > + bcopy(kenvp[i], buffer + done, len); > done += len; > } > } > - sx_sunlock(&kenv_lock); > + mtx_unlock(&kenv_lock); > + error = copyout(buffer, uap->value, done); > + free(buffer, M_TEMP); > td->td_retval[0] = ((done == needed) ? 0 : needed); > return (error); > } Minor nit here is that you probably can avoid the malloc() and skip the copyout() and free() if uap->value == NULL. In that case the caller is just asking for the length to know how big of a buffer to malloc. -- John Baldwin