Fix EINTR handling for close
This commit is contained in:
43
src/main.cpp
43
src/main.cpp
@@ -48,10 +48,6 @@ std::vector<int> create_listen_sockets(const weaseldb::Config &config) {
|
||||
addr.sun_family = AF_UNIX;
|
||||
|
||||
if (config.server.unix_socket_path.length() >= sizeof(addr.sun_path)) {
|
||||
int e;
|
||||
do {
|
||||
e = close(sfd);
|
||||
} while (e == -1 && errno == EINTR);
|
||||
std::fprintf(stderr, "Unix socket path too long\n");
|
||||
std::abort();
|
||||
}
|
||||
@@ -61,19 +57,11 @@ std::vector<int> create_listen_sockets(const weaseldb::Config &config) {
|
||||
|
||||
if (bind(sfd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
|
||||
perror("bind");
|
||||
int e;
|
||||
do {
|
||||
e = close(sfd);
|
||||
} while (e == -1 && errno == EINTR);
|
||||
std::abort();
|
||||
}
|
||||
|
||||
if (listen(sfd, SOMAXCONN) == -1) {
|
||||
perror("listen");
|
||||
int e;
|
||||
do {
|
||||
e = close(sfd);
|
||||
} while (e == -1 && errno == EINTR);
|
||||
std::abort();
|
||||
}
|
||||
|
||||
@@ -112,10 +100,11 @@ std::vector<int> create_listen_sockets(const weaseldb::Config &config) {
|
||||
int val = 1;
|
||||
if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) == -1) {
|
||||
perror("setsockopt SO_REUSEADDR");
|
||||
int e;
|
||||
do {
|
||||
e = close(sfd);
|
||||
} while (e == -1 && errno == EINTR);
|
||||
int e = close(sfd);
|
||||
if (e == -1 && errno != EINTR) {
|
||||
perror("close sfd (SO_REUSEADDR failed)");
|
||||
std::abort();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -123,10 +112,11 @@ std::vector<int> create_listen_sockets(const weaseldb::Config &config) {
|
||||
if (rp->ai_family == AF_INET || rp->ai_family == AF_INET6) {
|
||||
if (setsockopt(sfd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val)) == -1) {
|
||||
perror("setsockopt TCP_NODELAY");
|
||||
int e;
|
||||
do {
|
||||
e = close(sfd);
|
||||
} while (e == -1 && errno == EINTR);
|
||||
int e = close(sfd);
|
||||
if (e == -1 && errno != EINTR) {
|
||||
perror("close sfd (TCP_NODELAY failed)");
|
||||
std::abort();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -135,10 +125,11 @@ std::vector<int> create_listen_sockets(const weaseldb::Config &config) {
|
||||
break; /* Success */
|
||||
}
|
||||
|
||||
int e;
|
||||
do {
|
||||
e = close(sfd);
|
||||
} while (e == -1 && errno == EINTR);
|
||||
int e = close(sfd);
|
||||
if (e == -1 && errno != EINTR) {
|
||||
perror("close sfd (bind failed)");
|
||||
std::abort();
|
||||
}
|
||||
sfd = -1;
|
||||
}
|
||||
|
||||
@@ -151,10 +142,6 @@ std::vector<int> create_listen_sockets(const weaseldb::Config &config) {
|
||||
|
||||
if (listen(sfd, SOMAXCONN) == -1) {
|
||||
perror("listen");
|
||||
int e;
|
||||
do {
|
||||
e = close(sfd);
|
||||
} while (e == -1 && errno == EINTR);
|
||||
std::abort();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user