From owner-freebsd-ports@FreeBSD.ORG Thu May 31 02:07:39 2007 Return-Path: X-Original-To: freebsd-ports@freebsd.org Delivered-To: freebsd-ports@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 5543A16A46B for ; Thu, 31 May 2007 02:07:39 +0000 (UTC) (envelope-from sean@farley.org) Received: from mail.farley.org (farley.org [67.64.95.201]) by mx1.freebsd.org (Postfix) with ESMTP id 1F4E013C45D for ; Thu, 31 May 2007 02:07:38 +0000 (UTC) (envelope-from sean@farley.org) Received: from thor.farley.org (thor.farley.org [192.168.1.5]) by mail.farley.org (8.14.1/8.14.1) with ESMTP id l4V1unIt055738 for ; Wed, 30 May 2007 20:56:49 -0500 (CDT) (envelope-from sean@farley.org) Date: Wed, 30 May 2007 20:56:21 -0500 (CDT) From: Sean Farley To: freebsd-ports@freebsd.org Message-ID: <20070530205103.P14991@thor.farley.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Subject: setenv() patch for POSIX and memory leak on CURRENT X-BeenThere: freebsd-ports@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting software to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 May 2007 02:07:39 -0000 I also posted this to current@, but I would also like some feedback from ports@ to see what problems may arise from the changes in note #2. Change 2.c is the most likely source of issues. I have completed a new version[1] of a replacement (kern/99826[1]) for getenv/setenv/putenv/unsetenv(). A patch against CURRENT that updates libc and a few base utilities can be found here[2]. I built it and ran it successfully. Notes: 1. Fixes memory leak as noted in BUGS section for setenv(3). Example of the leak: setenv("TZ", "CDT", 1); setenv("TZ", "YEKST", 1); // Leaks setenv("TZ", "CDT", 1); setenv("TZ", "YEKST", 1); // Leaks 2. Converts all calls to POSIX from historic BSD API. a. unsetenv returns an int. b. putenv takes a char * instead of const char *. c. putenv no longer makes a copy of the input string. d. errno is set appropriately for POSIX. Exceptions involve bad environ variable and internal initialization code. These both set errno to EFAULT. 3. Several patches to base utilities to handle the POSIX changes are from Andrey Chernov's previous commit. A few I re-wrote to use setenv() instead of putenv(). Yes, I dislike putenv(). :) 4. A new regression module to test these functions was written. It also can be used to test the performance. I found performance to be on-par or better. It is found in tools/regression/environment. 5. Man page could use more work to match all the changes. 6. make universe successfully completed on amd64, arm, i386 and ia64. The other targets are still going. Thank you to Andrey and others for your help in proofreading several iterations of the code. Sean 1. http://www.freebsd.org/cgi/query-pr.cgi?pr=kern/99826 2. http://www.farley.org/freebsd/tmp/setenv/setenv-9/ 3. http://www.farley.org/freebsd/tmp/setenv/setenv-9/setenv.diff -- sean-freebsd@farley.org