From patchwork Sun Dec 21 15:53:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ondrej Bilka X-Patchwork-Id: 4391 Received: (qmail 10946 invoked by alias); 21 Dec 2014 15:53:32 -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 10936 invoked by uid 89); 21 Dec 2014 15:53:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.7 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, SPF_NEUTRAL autolearn=no version=3.3.2 X-HELO: popelka.ms.mff.cuni.cz Date: Sun, 21 Dec 2014 16:53:21 +0100 From: =?utf-8?B?T25kxZllaiBCw61sa2E=?= To: Andreas Schwab Cc: libc-alpha@sourceware.org Subject: Re: [PING][PATCH v2][BZ #14799] Allow to disable options in RES_OPTIONS Message-ID: <20141221155320.GA32563@domone> References: <20141126001713.GA27914@domone> <87a93eqns0.fsf@igel.home> <20141127153740.GA10402@domone> <20141206203813.GA19633@domone> <87fvcs33o6.fsf@igel.home> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <87fvcs33o6.fsf@igel.home> User-Agent: Mutt/1.5.20 (2009-06-14) On Sat, Dec 06, 2014 at 09:48:41PM +0100, Andreas Schwab wrote: > That doesn't work. > Do you have testcase that shows that? It sets appropriate flags as shown in this simple testcase, where I for simplicity just print them instead digging from behaviour. diff --git a/resolv/Makefile b/resolv/Makefile index 22575e5..8efd4e6 100644 --- a/resolv/Makefile +++ b/resolv/Makefile @@ -30,7 +30,7 @@ headers := resolv.h \ routines := herror inet_addr inet_ntop inet_pton nsap_addr res_init \ res_hconf res_libc res-state -tests = tst-aton tst-leaks tst-inet_ntop +tests = tst-aton tst-leaks tst-inet_ntop tst xtests = tst-leaks2 generate := mtrace-tst-leaks.out tst-leaks.mtrace tst-leaks2.mtrace @@ -99,6 +99,8 @@ $(objpfx)libanl.so: $(shared-thread-library) $(objpfx)ga_test: $(objpfx)libanl.so $(shared-thread-library) $(objpfx)tst-leaks: $(objpfx)libresolv.so +$(objpfx)tst: $(objpfx)libresolv.so + tst-leaks-ENV = MALLOC_TRACE=$(objpfx)tst-leaks.mtrace $(objpfx)mtrace-tst-leaks.out: $(objpfx)tst-leaks.out $(common-objpfx)malloc/mtrace $(objpfx)tst-leaks.mtrace > $@; \ diff --git a/resolv/res_init.c b/resolv/res_init.c index d492a08..13ee429 100644 --- a/resolv/res_init.c +++ b/resolv/res_init.c @@ -533,26 +533,32 @@ res_setoptions(res_state statp, const char *options, const char *source) { #define STRnLEN(str) str, sizeof (str) - 1 { STRnLEN ("inet6"), 0, RES_USE_INET6 }, { STRnLEN ("ip6-bytestring"), 0, RES_USEBSTRING }, - { STRnLEN ("no-ip6-dotint"), 0, RES_NOIP6DOTINT }, { STRnLEN ("ip6-dotint"), 1, ~RES_NOIP6DOTINT }, { STRnLEN ("rotate"), 0, RES_ROTATE }, - { STRnLEN ("no-check-names"), 0, RES_NOCHECKNAME }, + { STRnLEN ("check-names"), 1, ~RES_NOCHECKNAME }, { STRnLEN ("edns0"), 0, RES_USE_EDNS0 }, { STRnLEN ("single-request-reopen"), 0, RES_SNGLKUPREOP }, { STRnLEN ("single-request"), 0, RES_SNGLKUP }, { STRnLEN ("no_tld_query"), 0, RES_NOTLDQUERY }, - { STRnLEN ("no-tld-query"), 0, RES_NOTLDQUERY }, + { STRnLEN ("tld-query"), 1, ~RES_NOTLDQUERY }, { STRnLEN ("use-vc"), 0, RES_USEVC } }; #define noptions (sizeof (options) / sizeof (options[0])) int i; + unsigned long int invert = 0; + if (strncmp (cp, "no-", 3) == 0) + { + cp += 3; + invert = ~0; + } + for (i = 0; i < noptions; ++i) if (strncmp (cp, options[i].str, options[i].len) == 0) { - if (options[i].clear) - statp->options &= options[i].flag; + if (options[i].clear ^ invert) + statp->options &= options[i].flag ^ invert; else - statp->options |= options[i].flag; + statp->options |= options[i].flag ^ invert; break; } if (i == noptions) { @@ -563,6 +569,8 @@ res_setoptions(res_state statp, const char *options, const char *source) { while (*cp && *cp != ' ' && *cp != '\t') cp++; } + + printf ("%lx\n", statp->options); } #ifdef RESOLVSORT diff --git a/resolv/tst.c b/resolv/tst.c new file mode 100644 index 0000000..4f629d6 --- /dev/null +++ b/resolv/tst.c @@ -0,0 +1,44 @@ +/* Tests for res_query in libresolv + Copyright (C) 2003-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include + +/* Prototype for our test function. */ +extern int do_test (int argc, char *argv[]); + +/* This defines the `main' function and some more. */ +#define TIMEOUT 40 +#include + +int +do_test (int argc, char *argv[]) +{ + unsigned char buf[256]; + + setenv ("RES_OPTIONS","no-inet6 inet6 no-inet6", 1); + _res.options |= RES_DEBUG; + res_init (); + + /* This will allocate some memory, which should be automatically + freed at exit. */ + res_query ("1.0.0.127.in-addr.arpa.", C_ANY, T_ANY, buf, 256); + return 0; +}