From 3de647c8548f30f882c6ad5088df9acdc8cda300 Mon Sep 17 00:00:00 2001
From: Mats Erik Andersson <gnu@gisladisker.se>
Date: Fri, 17 Jul 2015 23:02:37 +0200
Subject: [PATCH 01/60] ifconfig: Sporadically appearing regression.

Device flags are sometimes calculated before their
query using SIOCGIFFLAGS.  First observed on GNU/Hurd.
---
 ChangeLog          |  9 +++++++++
 ifconfig/printif.c | 44 ++++++++++++++++++++++++++++++--------------
 2 files changed, 39 insertions(+), 14 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ea184b09..7f799daa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2015-07-17  Mats Erik Andersson  <gnu@gisladisker.se>
+
+	ifconfig: Sporadically appearing regression.
+	Device flags are sometimes calculated before their
+	query using SIOCGIFFLAGS.  First observed on GNU/Hurd.
+
+	* ifconfig/printif.c (fh_brdaddr_query, fh_dstaddr_query):
+	Execute ioctl(SIOCGIFFLAGS) before calculating UFLAGS.
+
 2015-05-27  Alfred M. Szmidt  <ams@gnu.org>
 
 	* Makefile.am (ACLOCAL_AMFLAGS): New variable.
diff --git a/ifconfig/printif.c b/ifconfig/printif.c
index 615a630a..a269a508 100644
--- a/ifconfig/printif.c
+++ b/ifconfig/printif.c
@@ -719,24 +719,32 @@ fh_brdaddr_query (format_data_t form, int argc, char *argv[])
 # ifdef SIOCGIFFLAGS
   int f;
   int rev;
-  unsigned int uflags = (unsigned short) form->ifr->ifr_flags;
+  unsigned int uflags;
 
-# ifdef ifr_flagshigh
+  f = if_nameztoflag ("BROADCAST", &rev);
+
+  if (f == 0 || (ioctl (form->sfd, SIOCGIFFLAGS, form->ifr) < 0))
+    {
+      select_arg (form, argc, argv, 1);
+      return;
+    }
+
+  uflags = (unsigned short) form->ifr->ifr_flags;
+#  ifdef ifr_flagshigh
   uflags |= (unsigned short) form->ifr->ifr_flagshigh << 16;
-# endif /* ifr_flagshigh */
+#  endif /* ifr_flagshigh */
 
-  if (0 == (f = if_nameztoflag ("BROADCAST", &rev))
-      || (ioctl (form->sfd, SIOCGIFFLAGS, form->ifr) < 0)
-      || ((f & uflags) == 0))
+  if ((f & uflags) == 0)
     {
       select_arg (form, argc, argv, 1);
       return;
     }
-# endif
+# endif /* SIOCGIFFLAGS */
+
   if (ioctl (form->sfd, SIOCGIFBRDADDR, form->ifr) >= 0)
     select_arg (form, argc, argv, 0);
   else
-#endif
+#endif /* SIOCGIFBRDADDR */
     select_arg (form, argc, argv, 1);
 }
 
@@ -763,24 +771,32 @@ fh_dstaddr_query (format_data_t form, int argc, char *argv[])
 # ifdef SIOCGIFFLAGS
   int f;
   int rev;
-  unsigned int uflags = (unsigned short) form->ifr->ifr_flags;
+  unsigned int uflags;
+
+  f = if_nameztoflag ("POINTOPOINT", &rev);
 
+  if (f == 0 || (ioctl (form->sfd, SIOCGIFFLAGS, form->ifr) < 0))
+    {
+      select_arg (form, argc, argv, 1);
+      return;
+    }
+
+  uflags = (unsigned short) form->ifr->ifr_flags;
 #  ifdef ifr_flagshigh
   uflags |= (unsigned short) form->ifr->ifr_flagshigh << 16;
 #  endif /* ifr_flagshigh */
 
-  if (0 == (f = if_nameztoflag ("POINTOPOINT", &rev))
-      || (ioctl (form->sfd, SIOCGIFFLAGS, form->ifr) < 0)
-      || ((f & uflags) == 0))
+  if ((f & uflags) == 0)
     {
       select_arg (form, argc, argv, 1);
       return;
     }
-# endif
+# endif /* SIOCGIFFLAGS */
+
   if (ioctl (form->sfd, SIOCGIFDSTADDR, form->ifr) >= 0)
     select_arg (form, argc, argv, 0);
   else
-#endif
+#endif /* SIOCGIFDSTADDR */
     select_arg (form, argc, argv, 1);
 }
 
-- 
2.26.0.292.g33ef6b2f38

