summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
18c6c61)
Clean up connect_nb() in the showmount command.
Sometimes it returns -1 on error, and sometimes a negative errno. On error,
it should always return one of these or the other, not both.
Similar functions in other parts of nfs-utils return -1 on error, and set
errno; so let's do that here too.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
* tout contains the timeout. It will be modified to contain the time
* remaining (i.e. time provided - time elasped).
*
* tout contains the timeout. It will be modified to contain the time
* remaining (i.e. time provided - time elasped).
*
- * Returns 0 for success
+ * Returns zero on success; otherwise, -1 is returned and errno is set
+ * to reflect the nature of the error.
*/
static int connect_nb(int fd, struct sockaddr_in *addr, struct timeval *tout)
{
*/
static int connect_nb(int fd, struct sockaddr_in *addr, struct timeval *tout)
{
len = sizeof(struct sockaddr);
ret = connect(fd, (struct sockaddr *)addr, len);
if (ret < 0 && errno != EINPROGRESS) {
len = sizeof(struct sockaddr);
ret = connect(fd, (struct sockaddr *)addr, len);
if (ret < 0 && errno != EINPROGRESS) {
ret = select(fd + 1, NULL, &rset, NULL, tout);
if (ret <= 0) {
if (ret == 0)
ret = select(fd + 1, NULL, &rset, NULL, tout);
if (ret <= 0) {
if (ret == 0)
- ret = -ETIMEDOUT;
- else
- ret = -errno;
+ errno = ETIMEDOUT;
+ ret = -1;
len = sizeof(ret);
status = getsockopt(fd, SOL_SOCKET, SO_ERROR, &ret, &len);
if (status < 0) {
len = sizeof(ret);
status = getsockopt(fd, SOL_SOCKET, SO_ERROR, &ret, &len);
if (status < 0) {
goto done;
}
/* Oops - something wrong with connect */
goto done;
}
/* Oops - something wrong with connect */
+ if (ret != 0) {
+ errno = ret;
+ ret = -1;
+ }
tout.tv_sec = TIMEOUT_TCP;
ret = connect_nb(sock, &saddr, &tout);
tout.tv_sec = TIMEOUT_TCP;
ret = connect_nb(sock, &saddr, &tout);
- if (ret < 0) {
- close(sock);
rpc_createerr.cf_stat = RPC_SYSTEMERROR;
rpc_createerr.cf_error.re_errno = errno;
rpc_createerr.cf_stat = RPC_SYSTEMERROR;
rpc_createerr.cf_error.re_errno = errno;
return 0;
}
client = clnttcp_create(&saddr,
return 0;
}
client = clnttcp_create(&saddr,