summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2011-12-06 15:55:22 -0800
committerBen Pfaff <blp@nicira.com>2011-12-07 08:37:36 -0800
commitaebe8d21d8af1487a18f30b7a172dff9bb5d649e (patch)
tree0155d7697dc7ecc90fc9c88b9db4f69118236a8b
parentce3408f32fbde696ef05e1724d3552f6b2276e57 (diff)
downloadopenvswitch-aebe8d21d8af1487a18f30b7a172dff9bb5d649e.tar.gz
socket-util: Correctly return negative values for errors.
The comment on this function says that negative values indicate errors, and the callers assume that too, but in fact it was returning positive errno values, which are indistinguishable from valid fd numbers. It really seems to me that this should have been found pretty quickly in the field, since stream-tcp and stream-ssl both use inet_open_passive to implement their passive listeners. I'm surprised that no one has reported it.
-rw-r--r--lib/socket-util.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/socket-util.c b/lib/socket-util.c
index 26e290815..219433fb8 100644
--- a/lib/socket-util.c
+++ b/lib/socket-util.c
@@ -673,7 +673,7 @@ inet_open_passive(int style, const char *target, int default_port,
unsigned int yes = 1;
if (!inet_parse_passive(target, default_port, &sin)) {
- return EAFNOSUPPORT;
+ return -EAFNOSUPPORT;
}
/* Create non-blocking socket, set SO_REUSEADDR. */
@@ -681,7 +681,7 @@ inet_open_passive(int style, const char *target, int default_port,
if (fd < 0) {
error = errno;
VLOG_ERR("%s: socket: %s", target, strerror(error));
- return error;
+ return -error;
}
error = set_nonblocking(fd);
if (error) {
@@ -716,6 +716,7 @@ inet_open_passive(int style, const char *target, int default_port,
goto error;
}
if (sin.sin_family != AF_INET || sin_len != sizeof sin) {
+ error = EAFNOSUPPORT;
VLOG_ERR("%s: getsockname: invalid socket name", target);
goto error;
}
@@ -726,7 +727,7 @@ inet_open_passive(int style, const char *target, int default_port,
error:
close(fd);
- return error;
+ return -error;
}
/* Returns a readable and writable fd for /dev/null, if successful, otherwise