Skip to contentSkip to conversation

iproute: Fix errno propagation from rtnl_talk

PATCH Applied Pavel Emelyanov 2 participants 2 messages Aug 20, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iproute: Fix errno propagation from rtnl_talk

Callers of rtnl_talk check errno value for their needs. In particular, the addrs and routes restoring code validly reports success if the EEXISTS is in there.

However, the errno value can be sometimes screwed up by the perror call. Thus we should only set it _after_ the message was emitted.

---

lib/libnetlink.c +4 -3
index 878911e..8e8c8b9 100644
@@ -360,13 +360,14 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
 				if (l < sizeof(struct nlmsgerr)) {
 					fprintf(stderr, "ERROR truncated\n");
 				} else {
-					errno = -err->error;
-					if (errno == 0) {
+					if (!err->error) {
 						if (answer)
 							memcpy(answer, h, h->nlmsg_len);
 						return 0;
 					}
-					perror("RTNETLINK answers");
+
+					fprintf(stderr, "RTNETLINK answers: %s\n", strerror(-err->error));
+					errno = -err->error;
 				}
 				return -1;
 			}
#1 lore raw
Quoted 22 lines · On Mon, 20 Aug 2012 12:08:40 +0400 Pavel Emelyanov <[email protected]> wrote:

Callers of rtnl_talk check errno value for their needs. In particular, the addrs and routes restoring code validly reports success if the EEXISTS is in there.

However, the errno value can be sometimes screwed up by the perror call. Thus we should only set it _after_ the message was emitted.

---

lib/libnetlink.c +1 -2
index 878911e..8e8c8b9 100644
@@ -360,13 +360,14 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
 				if (l < sizeof(struct nlmsgerr)) {
 					fprintf(stderr, "ERROR truncated\n");
 				} else {
-					errno = -err->error;
-					if (errno == 0) {
+					if (!err->error) {
 						if (answer)

lib/libnetlink.c int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer, · line 373

Quoted 10 lines
lib/libnetlink.c +3 -1
 							memcpy(answer, h, h->nlmsg_len);
 						return 0;
 					}
-					perror("RTNETLINK answers");
+
+					fprintf(stderr, "RTNETLINK answers: %s\n", strerror(-err->error));
+					errno = -err->error;
 				}
 				return -1;
 			}

Applied