Module Name:    src
Committed By:   christos
Date:           Fri Oct 29 15:08:18 UTC 2010

Modified Files:
        src/libexec/ld.elf_so: Makefile rtld.c rtldenv.h
Added Files:
        src/libexec/ld.elf_so: xenv.c

Log Message:
PR/44010: YAMAMOTO Takashi: sbrk: grow 0xb3ba2000 failed, error = 12"
(due to setenv changes?)
Provide a mini unsetenv that does not allocate/free memory and does not
bother about locking.


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 src/libexec/ld.elf_so/Makefile
cvs rdiff -u -r1.131 -r1.132 src/libexec/ld.elf_so/rtld.c
cvs rdiff -u -r1.9 -r1.10 src/libexec/ld.elf_so/rtldenv.h
cvs rdiff -u -r0 -r1.1 src/libexec/ld.elf_so/xenv.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/libexec/ld.elf_so/Makefile
diff -u src/libexec/ld.elf_so/Makefile:1.97 src/libexec/ld.elf_so/Makefile:1.98
--- src/libexec/ld.elf_so/Makefile:1.97	Tue Jul  6 01:59:56 2010
+++ src/libexec/ld.elf_so/Makefile	Fri Oct 29 11:08:17 2010
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.97 2010/07/06 05:59:56 mrg Exp $
+#	$NetBSD: Makefile,v 1.98 2010/10/29 15:08:17 christos Exp $
 #
 # NOTE: when changing ld.so, ensure that ldd still compiles.
 #
@@ -57,7 +57,7 @@
 
 CLIBOBJ!=	cd ${NETBSDSRCDIR}/lib/libc && ${PRINTOBJDIR}
 
-SRCS+=		rtld.c reloc.c symbol.c xmalloc.c xprintf.c debug.c \
+SRCS+=		rtld.c reloc.c symbol.c xenv.c xmalloc.c xprintf.c debug.c \
 		map_object.c load.c search.c headers.c paths.c expand.c
 
 .if ${USE_FORT} == "yes"

Index: src/libexec/ld.elf_so/rtld.c
diff -u src/libexec/ld.elf_so/rtld.c:1.131 src/libexec/ld.elf_so/rtld.c:1.132
--- src/libexec/ld.elf_so/rtld.c:1.131	Sat Oct 16 06:27:07 2010
+++ src/libexec/ld.elf_so/rtld.c	Fri Oct 29 11:08:17 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.131 2010/10/16 10:27:07 skrll Exp $	 */
+/*	$NetBSD: rtld.c,v 1.132 2010/10/29 15:08:17 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.131 2010/10/16 10:27:07 skrll Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.132 2010/10/29 15:08:17 christos Exp $");
 #endif /* not lint */
 
 #include <err.h>
@@ -444,7 +444,7 @@
 		    getenv("LD_LIBRARY_PATH"));
 	} else {
 		execname = NULL;
-		if (unsetenv("LD_DEBUG") || unsetenv("LD_LIBRARY_PATH"))
+		if (xunsetenv("LD_DEBUG") || xunsetenv("LD_LIBRARY_PATH"))
 			_rtld_die();
 	}
 	_rtld_process_hints(execname, &_rtld_paths, &_rtld_xforms,
@@ -521,7 +521,7 @@
 		if (_rtld_preload(getenv("LD_PRELOAD")) == -1)
 			_rtld_die();
 	} else
-		if (unsetenv("LD_PRELOAD"))
+		if (xunsetenv("LD_PRELOAD"))
 			_rtld_die();
 
 	dbg(("loading needed objects"));

Index: src/libexec/ld.elf_so/rtldenv.h
diff -u src/libexec/ld.elf_so/rtldenv.h:1.9 src/libexec/ld.elf_so/rtldenv.h:1.10
--- src/libexec/ld.elf_so/rtldenv.h:1.9	Fri Oct  5 18:21:07 2007
+++ src/libexec/ld.elf_so/rtldenv.h	Fri Oct 29 11:08:17 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtldenv.h,v 1.9 2007/10/05 22:21:07 ad Exp $	 */
+/*	$NetBSD: rtldenv.h,v 1.10 2010/10/29 15:08:17 christos Exp $	 */
 
 /*
  * Copyright 1996 Matt Thomas <[email protected]>
@@ -59,6 +59,7 @@
 
 void     xassert(const char *, int, const char *);
 const char *xstrerror(int);
+int	xunsetenv(const char *);
 
 # ifdef DEBUG
 #  define assert(cond)	((cond) ? (void) 0 : xassert(__FILE__, __LINE__, #cond))

Added files:

Index: src/libexec/ld.elf_so/xenv.c
diff -u /dev/null src/libexec/ld.elf_so/xenv.c:1.1
--- /dev/null	Fri Oct 29 11:08:18 2010
+++ src/libexec/ld.elf_so/xenv.c	Fri Oct 29 11:08:17 2010
@@ -0,0 +1,70 @@
+/*	$NetBSD: xenv.c,v 1.1 2010/10/29 15:08:17 christos Exp $	*/
+
+/*
+ * Copyright (c) 1987, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "from: @(#)setenv.c	8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: xenv.c,v 1.1 2010/10/29 15:08:17 christos Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <errno.h>
+#include <string.h>
+#include "rtldenv.h"
+
+extern char * __findenv(const char *, int *);
+extern char **environ;
+
+/*
+ * xunsetenv(name) --
+ *	Delete environmental variable "name".
+ */
+int
+xunsetenv(const char *name)
+{
+	int offset;
+
+	if (name == NULL || *name == '\0' || strchr(name, '=') != NULL) {
+		errno = EINVAL;
+		return -1;
+	}
+
+	while (__findenv(name, &offset) != NULL) {
+		while (environ[offset] != NULL) {
+			environ[offset] = environ[offset + 1];
+			offset++;
+		}
+	}
+
+	return 0;
+}

Reply via email to