public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH][BZ #14799] Allow to disable options in RES_OPTIONS
@ 2014-11-26  0:17 Ondřej Bílka
  2014-11-26 10:06 ` Andreas Schwab
  0 siblings, 1 reply; 9+ messages in thread
From: Ondřej Bílka @ 2014-11-26  0:17 UTC (permalink / raw)
  To: libc-alpha

Hi, this bug ticket ask to make posible to disable ip6 and other options
by RES_OPTIONS environment variable. Rather to add them manually I added
a check so no-option will do opposite of option.

OK to commit?

	[BZ #14799]
	* resolv/res_init.c (res_setoptions): Detect no- prefix to
	disable option.


diff --git a/resolv/res_init.c b/resolv/res_init.c
index ea133f8..9ea43e9 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;
+		  int invert = 0;
+		  if (strncmp (cp, "no-", 3))
+		    {
+		      cp += 3;
+		      invert = 1;
+		    }
+
 		  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) {

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH][BZ #14799] Allow to disable options in RES_OPTIONS
  2014-11-26  0:17 [PATCH][BZ #14799] Allow to disable options in RES_OPTIONS Ondřej Bílka
@ 2014-11-26 10:06 ` Andreas Schwab
  2014-11-27 15:37   ` [PATCH v2][BZ " wizard
  0 siblings, 1 reply; 9+ messages in thread
From: Andreas Schwab @ 2014-11-26 10:06 UTC (permalink / raw)
  To: Ondřej Bílka; +Cc: libc-alpha

Ondřej Bílka <neleai@seznam.cz> writes:

> +		  int invert = 0;
> +		  if (strncmp (cp, "no-", 3))
> +		    {
> +		      cp += 3;
> +		      invert = 1;
> +		    }
> +
>  		  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;

That doesn't work.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2][BZ #14799] Allow to disable options in RES_OPTIONS
  2014-11-26 10:06 ` Andreas Schwab
@ 2014-11-27 15:37   ` wizard
  2014-12-06 20:38     ` [PING][PATCH " Ondřej Bílka
  0 siblings, 1 reply; 9+ messages in thread
From: wizard @ 2014-11-27 15:37 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: libc-alpha

On Wed, Nov 26, 2014 at 11:06:23AM +0100, Andreas Schwab wrote:
> Ondřej Bílka <neleai@seznam.cz> writes:
> 
> > +		  int invert = 0;
> > +		  if (strncmp (cp, "no-", 3))
> > +		    {
> > +		      cp += 3;
> > +		      invert = 1;
> > +		    }
> > +
> >  		  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;
> 
> That doesn't work.
> 
Oops, somewhat included older patch. I meant to send this.

	[BZ #14799]
	* resolv/res_init.c (res_setoptions): Detect no- prefix to
	disable option.

diff --git a/resolv/res_init.c b/resolv/res_init.c
index ea133f8..9ea43e9 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) {

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PING][PATCH v2][BZ #14799] Allow to disable options in RES_OPTIONS
  2014-11-27 15:37   ` [PATCH v2][BZ " wizard
@ 2014-12-06 20:38     ` Ondřej Bílka
  2014-12-06 20:48       ` Andreas Schwab
  0 siblings, 1 reply; 9+ messages in thread
From: Ondřej Bílka @ 2014-12-06 20:38 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: libc-alpha

ping.
On Thu, Nov 27, 2014 at 04:37:40PM +0100, wizard wrote:
> On Wed, Nov 26, 2014 at 11:06:23AM +0100, Andreas Schwab wrote:
> > Ondřej Bílka <neleai@seznam.cz> writes:
> > 
> > > +		  int invert = 0;
> > > +		  if (strncmp (cp, "no-", 3))
> > > +		    {
> > > +		      cp += 3;
> > > +		      invert = 1;
> > > +		    }
> > > +
> > >  		  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;
> > 
> > That doesn't work.
> > 
> Oops, somewhat included older patch. I meant to send this.
> 
> 	[BZ #14799]
> 	* resolv/res_init.c (res_setoptions): Detect no- prefix to
> 	disable option.
> 
> diff --git a/resolv/res_init.c b/resolv/res_init.c
> index ea133f8..9ea43e9 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) {

-- 

..disk or the processor is on fire.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PING][PATCH v2][BZ #14799] Allow to disable options in RES_OPTIONS
  2014-12-06 20:38     ` [PING][PATCH " Ondřej Bílka
@ 2014-12-06 20:48       ` Andreas Schwab
  2014-12-21 15:53         ` Ondřej Bílka
  0 siblings, 1 reply; 9+ messages in thread
From: Andreas Schwab @ 2014-12-06 20:48 UTC (permalink / raw)
  To: Ondřej Bílka; +Cc: libc-alpha

That doesn't work.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PING][PATCH v2][BZ #14799] Allow to disable options in RES_OPTIONS
  2014-12-06 20:48       ` Andreas Schwab
@ 2014-12-21 15:53         ` Ondřej Bílka
  2014-12-21 16:08           ` Andreas Schwab
  0 siblings, 1 reply; 9+ messages in thread
From: Ondřej Bílka @ 2014-12-21 15:53 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: libc-alpha

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;
+}

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PING][PATCH v2][BZ #14799] Allow to disable options in RES_OPTIONS
  2014-12-21 15:53         ` Ondřej Bílka
@ 2014-12-21 16:08           ` Andreas Schwab
  2014-12-21 16:56             ` Ondřej Bílka
  0 siblings, 1 reply; 9+ messages in thread
From: Andreas Schwab @ 2014-12-21 16:08 UTC (permalink / raw)
  To: Ondřej Bílka; +Cc: libc-alpha

Ondřej Bílka <neleai@seznam.cz> writes:

> Do you have testcase that shows that?

I don't need a testcase.  (options[i].clear ^ invert) is obviously
always nonzero.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PING][PATCH v2][BZ #14799] Allow to disable options in RES_OPTIONS
  2014-12-21 16:08           ` Andreas Schwab
@ 2014-12-21 16:56             ` Ondřej Bílka
  2015-08-12 20:37               ` [PING][PATCH v3][BZ " Ondřej Bílka
  0 siblings, 1 reply; 9+ messages in thread
From: Ondřej Bílka @ 2014-12-21 16:56 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: libc-alpha

On Sun, Dec 21, 2014 at 05:08:33PM +0100, Andreas Schwab wrote:
> Ondřej Bílka <neleai@seznam.cz> writes:
> 
> > Do you have testcase that shows that?
> 
> I don't need a testcase.  (options[i].clear ^ invert) is obviously
> always nonzero.
> 
Like when you pass inet6 there and options[i].clear == 0 and invert = 0?

But it needs update clear format to match invert.

diff --git a/resolv/res_init.c b/resolv/res_init.c
index d492a08..039116a 100644
--- a/resolv/res_init.c
+++ b/resolv/res_init.c
@@ -527,32 +527,38 @@ res_setoptions(res_state statp, const char *options, const char *source) {
 		  {
 		    char str[22];
 		    uint8_t len;
-		    uint8_t clear;
+		    unsigned long clear;
 		    unsigned long int flag;
 		  } options[] = {
 #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 ("ip6-dotint"), ~0, ~RES_NOIP6DOTINT },
 		    { STRnLEN ("rotate"), 0, RES_ROTATE },
-		    { STRnLEN ("no-check-names"), 0, RES_NOCHECKNAME },
+		    { STRnLEN ("check-names"), ~0, ~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"), ~0, ~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) {

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PING][PATCH v3][BZ #14799] Allow to disable options in RES_OPTIONS
  2014-12-21 16:56             ` Ondřej Bílka
@ 2015-08-12 20:37               ` Ondřej Bílka
  0 siblings, 0 replies; 9+ messages in thread
From: Ondřej Bílka @ 2015-08-12 20:37 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: libc-alpha

On Sun, Dec 21, 2014 at 05:56:35PM +0100, Ondřej Bílka wrote:
> On Sun, Dec 21, 2014 at 05:08:33PM +0100, Andreas Schwab wrote:
> > Ondřej Bílka <neleai@seznam.cz> writes:
> > 
> > > Do you have testcase that shows that?
> > 
> > I don't need a testcase.  (options[i].clear ^ invert) is obviously
> > always nonzero.
> > 
> Like when you pass inet6 there and options[i].clear == 0 and invert = 0?
> 
> But it needs update clear format to match invert.
> 
> diff --git a/resolv/res_init.c b/resolv/res_init.c
> index d492a08..039116a 100644
> --- a/resolv/res_init.c
> +++ b/resolv/res_init.c
> @@ -527,32 +527,38 @@ res_setoptions(res_state statp, const char *options, const char *source) {
>  		  {
>  		    char str[22];
>  		    uint8_t len;
> -		    uint8_t clear;
> +		    unsigned long clear;
>  		    unsigned long int flag;
>  		  } options[] = {
>  #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 ("ip6-dotint"), ~0, ~RES_NOIP6DOTINT },
>  		    { STRnLEN ("rotate"), 0, RES_ROTATE },
> -		    { STRnLEN ("no-check-names"), 0, RES_NOCHECKNAME },
> +		    { STRnLEN ("check-names"), ~0, ~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"), ~0, ~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) {

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-08-12 20:37 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-26  0:17 [PATCH][BZ #14799] Allow to disable options in RES_OPTIONS Ondřej Bílka
2014-11-26 10:06 ` Andreas Schwab
2014-11-27 15:37   ` [PATCH v2][BZ " wizard
2014-12-06 20:38     ` [PING][PATCH " Ondřej Bílka
2014-12-06 20:48       ` Andreas Schwab
2014-12-21 15:53         ` Ondřej Bílka
2014-12-21 16:08           ` Andreas Schwab
2014-12-21 16:56             ` Ondřej Bílka
2015-08-12 20:37               ` [PING][PATCH v3][BZ " Ondřej Bílka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).