summaryrefslogtreecommitdiffstats
path: root/lem/io/unix.c
diff options
context:
space:
mode:
Diffstat (limited to 'lem/io/unix.c')
-rw-r--r--lem/io/unix.c41
1 files changed, 24 insertions, 17 deletions
diff --git a/lem/io/unix.c b/lem/io/unix.c
index 25e1b00..0b18432 100644
--- a/lem/io/unix.c
+++ b/lem/io/unix.c
@@ -31,8 +31,16 @@ unix_connect_work(struct lem_async *a)
struct sockaddr_un addr;
int sock;
- sock = socket(AF_UNIX, SOCK_STREAM, 0);
- if (sock < 0) {
+ sock = socket(AF_UNIX,
+#ifdef SOCK_CLOEXEC
+ SOCK_CLOEXEC |
+#endif
+ SOCK_STREAM, 0);
+ if (sock < 0
+#ifndef SOCK_CLOEXEC
+ || fcntl(sock, F_SETFD, FD_CLOEXEC) == -1
+#endif
+ ) {
u->sock = -1;
u->err = errno;
return;
@@ -49,8 +57,8 @@ unix_connect_work(struct lem_async *a)
}
/* make the socket non-blocking */
- if (fcntl(sock, F_SETFL, O_NONBLOCK)) {
- u->sock = -3;
+ if (fcntl(sock, F_SETFL, O_NONBLOCK) == -1) {
+ u->sock = -1;
u->err = errno;
goto error;
}
@@ -87,10 +95,6 @@ unix_connect_reap(struct lem_async *a)
lua_pushfstring(T, "error connecting to '%s': %s",
u->path, strerror(u->err));
break;
- case 3:
- lua_pushfstring(T, "error making socket non-blocking: %s",
- strerror(u->err));
- break;
}
lem_queue(T, 2);
free(u);
@@ -123,8 +127,16 @@ unix_listen_work(struct lem_async *a)
struct sockaddr_un addr;
int sock;
- sock = socket(AF_UNIX, SOCK_STREAM, 0);
- if (sock < 0) {
+ sock = socket(AF_UNIX,
+#ifdef SOCK_CLOEXEC
+ SOCK_CLOEXEC |
+#endif
+ SOCK_STREAM, 0);
+ if (sock < 0
+#ifndef SOCK_CLOEXEC
+ || fcntl(sock, F_SETFD, FD_CLOEXEC) == -1
+#endif
+ ) {
u->sock = -1;
u->err = errno;
return;
@@ -153,8 +165,8 @@ unix_listen_work(struct lem_async *a)
}
/* make the socket non-blocking */
- if (fcntl(sock, F_SETFL, O_NONBLOCK)) {
- u->sock = -5;
+ if (fcntl(sock, F_SETFL, O_NONBLOCK) == -1) {
+ u->sock = -1;
u->err = errno;
goto error;
}
@@ -209,11 +221,6 @@ unix_listen_reap(struct lem_async *a)
lua_pushfstring(T, "error listening on '%s': %s",
u->path, strerror(u->err));
break;
-
- case 5:
- lua_pushfstring(T, "error making socket non-blocking: %s",
- strerror(u->err));
- break;
}
lem_queue(T, 2);
free(u);