From 11d341652792bf1eb21b5f42a4a0a5ea5298b164 Mon Sep 17 00:00:00 2001 From: Emil Renner Berthing Date: Tue, 29 Jan 2013 22:04:53 +0100 Subject: io: handle standard streams better Bash gets confused by non-blocking stdin, so set standard streams to non-blocking on __gc. FreeBSD errors when trying to set stdout non-blocking when it is redirected to /dev/null. So just silently ignore such errors. --- lem/io/core.c | 7 +++---- lem/io/stream.c | 2 ++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lem/io/core.c b/lem/io/core.c index 15ebd8d..c56463c 100644 --- a/lem/io/core.c +++ b/lem/io/core.c @@ -255,12 +255,11 @@ push_stdstream(lua_State *L, int fd) struct stream *s; /* make the socket non-blocking */ - if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) - luaL_error(L, "error making fd %d non-blocking: %s", - fd, strerror(errno)); + fcntl(fd, F_SETFL, O_NONBLOCK); s = stream_new(L, fd, -2); - s->open = 2; /* don't close this in __gc() */ + /* don't close this in __gc(), but make it blocking again */ + s->open = 2; } int diff --git a/lem/io/stream.c b/lem/io/stream.c index 07aa5d2..204df81 100644 --- a/lem/io/stream.c +++ b/lem/io/stream.c @@ -56,6 +56,8 @@ stream_gc(lua_State *T) if (s->open & 1) close(s->r.fd); + if (s->open & 2) + fcntl(s->w.fd, F_SETFL, 0); return 0; } -- cgit v1.2.1