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.
[backport candidate]
diff --git a/zebra/ChangeLog b/zebra/ChangeLog
index 38824a2..a7286f9 100644
--- a/zebra/ChangeLog
+++ b/zebra/ChangeLog
@@ -1,3 +1,8 @@
+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.
+
2005-01-24 Martin Pot <mpot at martybugs.net>
* zebra/rt_netlink.c: ignore wireless newlink netlink messages.
diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c
index f5903a6..0d9bbbd 100644
--- a/zebra/rt_netlink.c
+++ b/zebra/rt_netlink.c
@@ -94,6 +94,7 @@
struct sockaddr_nl snl;
int sock;
int namelen;
+ int save_errno;
sock = socket (AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (sock < 0)
@@ -166,13 +167,14 @@
}
ret = bind (sock, (struct sockaddr *) &snl, sizeof snl);
+ save_errno = errno;
if (zserv_privs.change (ZPRIVS_LOWER))
zlog (NULL, LOG_ERR, "Can't lower privileges");
if (ret < 0)
{
zlog (NULL, LOG_ERR, "Can't bind %s socket to group 0x%x: %s",
- nl->name, snl.nl_groups, safe_strerror (errno));
+ nl->name, snl.nl_groups, safe_strerror (save_errno));
close (sock);
return -1;
}
@@ -234,6 +236,7 @@
{
int ret;
struct sockaddr_nl snl;
+ int save_errno;
struct
{
@@ -270,6 +273,7 @@
ret = sendto (nl->sock, (void *) &req, sizeof req, 0,
(struct sockaddr *) &snl, sizeof snl);
+ save_errno = errno;
if (zserv_privs.change (ZPRIVS_LOWER))
zlog (NULL, LOG_ERR, "Can't lower privileges");
@@ -277,7 +281,7 @@
if (ret < 0)
{
zlog (NULL, LOG_ERR, "%s sendto failed: %s", nl->name,
- safe_strerror (errno));
+ safe_strerror (save_errno));
return -1;
}
@@ -301,22 +305,25 @@
struct sockaddr_nl snl;
struct msghdr msg = { (void *) &snl, sizeof snl, &iov, 1, NULL, 0, 0 };
struct nlmsghdr *h;
+ int save_errno;
if (zserv_privs.change (ZPRIVS_RAISE))
zlog (NULL, LOG_ERR, "Can't raise privileges");
status = recvmsg (nl->sock, &msg, 0);
+ save_errno = errno;
if (zserv_privs.change (ZPRIVS_LOWER))
zlog (NULL, LOG_ERR, "Can't lower privileges");
if (status < 0)
{
- if (errno == EINTR)
+ if (save_errno == EINTR)
continue;
- if (errno == EWOULDBLOCK || errno == EAGAIN)
+ if (save_errno == EWOULDBLOCK || save_errno == EAGAIN)
break;
- zlog (NULL, LOG_ERR, "%s recvmsg overrun", nl->name);
+ zlog (NULL, LOG_ERR, "%s recvmsg overrun: %s",
+ nl->name, safe_strerror(save_errno));
continue;
}
@@ -1221,6 +1228,7 @@
struct msghdr msg = { (void *) &snl, sizeof snl, &iov, 1, NULL, 0, 0 };
int flags = 0;
int snb_ret;
+ int save_errno;
memset (&snl, 0, sizeof snl);
snl.nl_family = AF_NETLINK;
@@ -1239,13 +1247,14 @@
if (zserv_privs.change (ZPRIVS_RAISE))
zlog (NULL, LOG_ERR, "Can't raise privileges");
status = sendmsg (nl->sock, &msg, 0);
+ save_errno = errno;
if (zserv_privs.change (ZPRIVS_LOWER))
zlog (NULL, LOG_ERR, "Can't lower privileges");
if (status < 0)
{
zlog (NULL, LOG_ERR, "netlink_talk sendmsg() error: %s",
- safe_strerror (errno));
+ safe_strerror (save_errno));
return -1;
}