Bug #546 » bug546.diff
src/common/sessiond-comm/inet.c | ||
---|---|---|
#define _GNU_SOURCE
|
||
#include <assert.h>
|
||
#include <fcntl.h>
|
||
#include <limits.h>
|
||
#include <stdio.h>
|
||
#include <stdlib.h>
|
||
... | ... | |
{
|
||
int ret, closeret;
|
||
ret = fcntl(sock->fd, F_SETFL, O_NONBLOCK);
|
||
if (ret < 0) {
|
||
PERROR("fcntl O_NONBLOCK");
|
||
goto error;
|
||
}
|
||
ret = connect(sock->fd, (struct sockaddr *) &sock->sockaddr.addr.sin,
|
||
sizeof(sock->sockaddr.addr.sin));
|
||
if (ret < 0) {
|
||
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINPROGRESS) {
|
||
ERR("connect() is about to block");
|
||
}
|
||
/*
|
||
* Don't print message on connect error, because connect is used in
|
||
* normal execution to detect if sessiond is alive.
|
||
... | ... | |
goto error_connect;
|
||
}
|
||
ret = fcntl(sock->fd, F_SETFL, ~O_NONBLOCK);
|
||
if (ret < 0) {
|
||
PERROR("fcntl O_NONBLOCK");
|
||
goto error;
|
||
}
|
||
return ret;
|
||
error_connect:
|
||
... | ... | |
if (closeret) {
|
||
PERROR("close inet");
|
||
}
|
||
error:
|
||
return ret;
|
||
}
|
||