From patchwork Wed Mar 4 21:23:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roland McGrath X-Patchwork-Id: 446441 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 8FE6A140161 for ; Thu, 5 Mar 2015 08:23:34 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=sourceware.org header.i=@sourceware.org header.b=Og4zo5Y/; dkim-adsp=none (unprotected policy); dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:content-type :content-transfer-encoding:from:to:subject:message-id:date; q= dns; s=default; b=BMPLr3IlhnDenUR8gVQi4jQs+ktlJrEVjv+AxBVjn8FLSD 0eh0vZeBFjkpGu8jz+TzNzKrYxdKzu3si0GixW8a9gbFGy7AyUPxz0/dqW8ugvJt 1S6pL3DFJ5QhZRmhqk1J6XCuaIqvBaTqpjR8tRe3bK8RnRCsqSuzz5caD+2fU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:content-type :content-transfer-encoding:from:to:subject:message-id:date; s= default; bh=oJX6zex7O9KDNN9Vy/yNCHcCJ/Q=; b=Og4zo5Y/CjZ0RZncA6Hc n5Lzg9nu5S/WoC8A/9Pda7UGZPUS+x6zRMQzKSgZYBLKg8Y21bMTRya/R3Dloxna iOIv9QnS6fX/Y83CoIIsE6vJYaytU/N0iWwfOwYa5NDazzvJXswDhFgn9jF4gyiu YFy/ePxt3tkHYt0moDdK0EM= Received: (qmail 75108 invoked by alias); 4 Mar 2015 21:23:28 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 75071 invoked by uid 89); 4 Mar 2015 21:23:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: topped-with-meat.com MIME-Version: 1.0 From: Roland McGrath To: "GNU C. Library" Subject: [PATCH roland/env-only] Avoid re-exec-self in bug-setlocale1. Message-Id: <20150304212323.43B2E2C3B7B@topped-with-meat.com> Date: Wed, 4 Mar 2015 13:23:23 -0800 (PST) X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=SvUDtp+0 c=1 sm=1 tr=0 a=WkljmVdYkabdwxfqvArNOQ==:117 a=14OXPxybAAAA:8 a=kj9zAlcOel0A:10 a=hOe2yjtxAAAA:8 a=udcqiDGNoaFzUb1KPkkA:9 a=CjuIK1q_8ugA:10 This extends the makefile infrastructure for tests to use a variable -ENV-only that is like the existing -ENV but for cases where the test program should run with a completely bare environment except for the explicit assignments in the makefile. This lets us get rid of the use of execve in bug-setlocale1 (and any similar cases I have not yet noticed). Unless there are objections, I'll commit this by Thursday. Thanks, Roland 2015-03-04 Roland McGrath * Makeconfig (test-wrapper-env-only): New variable. * Rules (make-test-out): If variable $*-ENV-only is nonempty, then use that with $(test-wrapper-env-only) rather than using $(test-wrapper-env) $(run-program-env) $($*-ENV). localedata/ 2015-03-04 Roland McGrath * bug-setlocale1.c (do_test): Remove argument handling and self-exec'ing logic. Just expect to be run with the right variables (and nothing else) directly in the environment instead. (TEST_FUNCTION): Don't pass arguments to do_test. * Makefile (bug-setlocale1-ARGS, bug-setlocale1-static-ARGS): Variables removed. (bug-setlocale1-ENV-only, bug-setlocale1-static-ENV-only): New variables. --- a/Makeconfig +++ b/Makeconfig @@ -611,6 +611,11 @@ endif ifndef test-wrapper-env test-wrapper-env = $(test-wrapper) env endif +# Likewise, but the program's environment will be empty except for any +# explicit = assignments preceding the program name. +ifndef test-wrapper-env-only +test-wrapper-env-only = $(test-wrapper) env -i +endif # Whether to run test programs built for the library's host system. ifndef run-built-tests --- a/Rules +++ b/Rules @@ -186,9 +186,11 @@ ifneq "$(strip $(tests) $(xtests) $(test-srcs))" "" # These are the implicit rules for making test outputs # from the test programs and whatever input files are present. -make-test-out = $(test-wrapper-env) \ - $(run-program-env) \ - $($*-ENV) $(host-test-program-cmd) $($*-ARGS) +define make-test-out +$(if $($*-ENV-only),$(test-wrapper-env-only) $($*-ENV-only),\ + $(test-wrapper-env) $(run-program-env) $($*-ENV)) \ +$(host-test-program-cmd) $($*-ARGS) +endef $(objpfx)%.out: %.input $(objpfx)% $(make-test-out) > $@ < $(word 1,$^); \ $(evaluate-test) --- a/localedata/Makefile +++ b/localedata/Makefile @@ -237,8 +237,8 @@ $(objpfx)mtrace-tst-leaks.out: $(objpfx)tst-leaks.out $(common-objpfx)malloc/mtrace $(objpfx)tst-leaks.mtrace > $@; \ $(evaluate-test) -bug-setlocale1-ARGS = -- $(host-test-program-cmd) -bug-setlocale1-static-ARGS = $(bug-setlocale1-ARGS) +bug-setlocale1-ENV-only = LOCPATH=$(objpfx) LC_CTYPE=de_DE.UTF-8 +bug-setlocale1-static-ENV-only = $(bug-setlocale1-ENV-only) $(objdir)/iconvdata/gconv-modules: $(MAKE) -C ../iconvdata subdir=iconvdata $@ --- a/localedata/bug-setlocale1.c +++ b/localedata/bug-setlocale1.c @@ -7,44 +7,8 @@ static int -do_test (int argc, char *argv[]) +do_test (void) { - if (argc > 1) - { - char *newargv[5]; - int i; - if (argc != 2 && argc != 5) - { - printf ("wrong number of arguments (%d)\n", argc); - return 1; - } - - for (i = 0; i < (argc == 5 ? 4 : 1); i++) - newargv[i] = argv[i + 1]; - newargv[i] = NULL; - - char *env[3]; - env[0] = (char *) "LC_CTYPE=de_DE.UTF-8"; - char *loc = getenv ("LOCPATH"); - if (loc == NULL || loc[0] == '\0') - { - puts ("LOCPATH not set"); - return 1; - } - asprintf (&env[1], "LOCPATH=%s", loc); - if (env[1] == NULL) - { - puts ("asprintf failed"); - return 1; - } - env[2] = NULL; - - execve (newargv[0], newargv, env); - - puts ("execve returned"); - return 1; - } - int result = 0; char *a = setlocale (LC_ALL, ""); @@ -128,5 +92,5 @@ do_test (int argc, char *argv[]) return result; } -#define TEST_FUNCTION do_test (argc, argv) +#define TEST_FUNCTION do_test () #include "../test-skeleton.c"