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.
unsigned int yes = 1;
if (!inet_parse_passive(target, default_port, &sin)) {
- return EAFNOSUPPORT;
+ return -EAFNOSUPPORT;
}
/* Create non-blocking socket, set SO_REUSEADDR. */
if (fd < 0) {
error = errno;
VLOG_ERR("%s: socket: %s", target, strerror(error));
- return error;
+ return -error;
}
error = set_nonblocking(fd);
if (error) {
goto error;
}
if (sin.sin_family != AF_INET || sin_len != sizeof sin) {
+ error = EAFNOSUPPORT;
VLOG_ERR("%s: getsockname: invalid socket name", target);
goto error;
}
error:
close(fd);
- return error;
+ return -error;
}
/* Returns a readable and writable fd for /dev/null, if successful, otherwise