2005-01-29 Andrew J. Schorr <ajschorr@alumni.princeton.edu>

	* if_ioctl_solaris.c: (interface_list_ioctl) Save errno before calling
	  zserv_privs.change.
	* ioctl{,_solaris}.c: (if_ioctl,if_ioctl_ipv6) Save errno before calling
	  zserv_privs.change.
	* ipforward_solaris.c: (solaris_nd) Save errno before calling
	  zserv_privs.change.
	* irdp_main.c: (irdp_sock_init) Save errno before calling
	  zserv_privs.change.

	[backport candidate]
diff --git a/zebra/ChangeLog b/zebra/ChangeLog
index a7286f9..0ebe705 100644
--- a/zebra/ChangeLog
+++ b/zebra/ChangeLog
@@ -1,5 +1,16 @@
 2005-01-29 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
 
+	* if_ioctl_solaris.c: (interface_list_ioctl) Save errno before calling
+	  zserv_privs.change.
+	* ioctl{,_solaris}.c: (if_ioctl,if_ioctl_ipv6) Save errno before calling
+	  zserv_privs.change.
+	* ipforward_solaris.c: (solaris_nd) Save errno before calling
+	  zserv_privs.change.
+	* irdp_main.c: (irdp_sock_init) Save errno before calling
+	  zserv_privs.change.
+
+2005-01-29 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
+
 	* rt_netlink.c: (netlink_socket,netlink_request,netlink_parse_info,
 	  netlink_talk) Save errno before calling zserv_privs.change.
 
diff --git a/zebra/if_ioctl_solaris.c b/zebra/if_ioctl_solaris.c
index 1cbf555..38ac5a7 100644
--- a/zebra/if_ioctl_solaris.c
+++ b/zebra/if_ioctl_solaris.c
@@ -50,6 +50,7 @@
   struct lifconf lifconf;
   struct interface *ifp;
   int n;
+  int save_errno;
   size_t needed, lastneeded = 0;
   char *buf = NULL;
 
@@ -72,6 +73,7 @@
   lifn.lifn_family = af;
   lifn.lifn_flags = 0;
   ret = ioctl (sock, SIOCGLIFNUM, &lifn);
+  save_errno = errno;
   
   if (zserv_privs.change(ZPRIVS_LOWER))
     zlog (NULL, LOG_ERR, "Can't lower privileges");
@@ -79,7 +81,7 @@
   if (ret < 0)
     {
       zlog_warn ("interface_list_ioctl: SIOCGLIFNUM failed %s",
-                 safe_strerror (errno));
+                 safe_strerror (save_errno));
       close (sock);
       return -1;
     }
diff --git a/zebra/ioctl.c b/zebra/ioctl.c
index eca0e76..e28d359 100644
--- a/zebra/ioctl.c
+++ b/zebra/ioctl.c
@@ -46,8 +46,8 @@
 if_ioctl (u_long request, caddr_t buffer)
 {
   int sock;
-  int ret = 0;
-  int err = 0;
+  int ret;
+  int err;
 
   if (zserv_privs.change(ZPRIVS_RAISE))
     zlog (NULL, LOG_ERR, "Can't raise privileges");
@@ -59,13 +59,10 @@
       perror ("socket");
       exit (1);
     }
-  ret = ioctl (sock, request, buffer);
+  if ((ret = ioctl (sock, request, buffer)) < 0)
+    err = errno;
   if (zserv_privs.change(ZPRIVS_LOWER))
     zlog (NULL, LOG_ERR, "Can't lower privileges");
-  if (ret < 0)
-    {
-      err = errno;
-    }
   close (sock);
   
   if (ret < 0) 
@@ -81,8 +78,8 @@
 if_ioctl_ipv6 (u_long request, caddr_t buffer)
 {
   int sock;
-  int ret = 0;
-  int err = 0;
+  int ret;
+  int err;
 
   if (zserv_privs.change(ZPRIVS_RAISE))
     zlog (NULL, LOG_ERR, "Can't raise privileges");
@@ -95,14 +92,10 @@
       exit (1);
     }
 
-  ret = ioctl (sock, request, buffer);
+  if ((ret = ioctl (sock, request, buffer)) < 0)
+    err = errno;
   if (zserv_privs.change(ZPRIVS_LOWER))
     zlog (NULL, LOG_ERR, "Can't lower privileges");
- 
-  if (ret < 0)
-    {
-      err = errno;
-    }
   close (sock);
   
   if (ret < 0) 
diff --git a/zebra/ioctl_solaris.c b/zebra/ioctl_solaris.c
index 8ebd0f4..5ec327a 100644
--- a/zebra/ioctl_solaris.c
+++ b/zebra/ioctl_solaris.c
@@ -46,8 +46,8 @@
 if_ioctl (u_long request, caddr_t buffer)
 {
   int sock;
-  int ret = 0;
-  int err = 0;
+  int ret;
+  int err;
 
   if (zserv_privs.change(ZPRIVS_RAISE))
     zlog (NULL, LOG_ERR, "Can't raise privileges");
@@ -61,15 +61,12 @@
       exit (1);
     }
 
-  ret = ioctl (sock, request, buffer);
+  if ((ret = ioctl (sock, request, buffer)) < 0)
+    err = errno;
   
   if (zserv_privs.change(ZPRIVS_LOWER))
     zlog (NULL, LOG_ERR, "Can't lower privileges");
 
-  if (ret < 0)
-    {
-      err = errno;
-    }
   close (sock);
 
   if (ret < 0)
@@ -86,8 +83,8 @@
 {
 #ifdef HAVE_IPV6
   int sock;
-  int ret = 0;
-  int err = 0;
+  int ret;
+  int err;
 
   if (zserv_privs.change(ZPRIVS_RAISE))
     zlog (NULL, LOG_ERR, "Can't raise privileges");
@@ -101,15 +98,12 @@
       exit (1);
     }
 
-  ret = ioctl (sock, request, buffer);
+  if ((ret = ioctl (sock, request, buffer)) < 0)
+    err = errno;
 
   if (zserv_privs.change(ZPRIVS_LOWER))
     zlog (NULL, LOG_ERR, "Can't lower privileges");
 
-  if (ret < 0)
-    {
-      err = errno;
-    }
   close (sock);
 
   if (ret < 0)
diff --git a/zebra/ipforward_solaris.c b/zebra/ipforward_solaris.c
index 2eaf341..3ad2c40 100644
--- a/zebra/ipforward_solaris.c
+++ b/zebra/ipforward_solaris.c
@@ -87,10 +87,12 @@
     }
   if (ioctl (fd, I_STR, &strioctl) < 0) 
     {
+      int save_errno = errno;
       if ( zserv_privs.change (ZPRIVS_LOWER) )
         zlog_err ("solaris_nd: Can't lower privileges");
       close (fd);
-      zlog_warn("ioctl I_STR failed on device %s - %s", device,safe_strerror(errno));
+      zlog_warn("ioctl I_STR failed on device %s - %s",
+      		device, safe_strerror(save_errno));
       return -1;
     }
   close(fd);
diff --git a/zebra/irdp_main.c b/zebra/irdp_main.c
index 8c16448..0db2a54 100644
--- a/zebra/irdp_main.c
+++ b/zebra/irdp_main.c
@@ -101,19 +101,21 @@
 irdp_sock_init (void)
 {
   int ret, i;
+  int save_errno;
 
   if ( zserv_privs.change (ZPRIVS_RAISE) )
        zlog_err ("irdp_sock_init: could not raise privs, %s",
                   safe_strerror (errno) );
 
   irdp_sock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP);
+  save_errno = errno;
 
   if ( zserv_privs.change (ZPRIVS_LOWER) )
        zlog_err ("irdp_sock_init: could not lower privs, %s",
              safe_strerror (errno) );
 
   if (irdp_sock < 0) {
-    zlog_warn ("IRDP: can't create irdp socket %s", safe_strerror(errno));
+    zlog_warn ("IRDP: can't create irdp socket %s", safe_strerror(save_errno));
     return irdp_sock;
   };