This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PING][PATCH v2][BZ #14799] Allow to disable options in RES_OPTIONS


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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+#include <resolv.h>
+#include <mcheck.h>
+
+/* 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 <test-skeleton.c>
+
+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;
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]