diff options
author | Emil Renner Berthing <esmil@mailme.dk> | 2013-01-29 22:04:53 +0100 |
---|---|---|
committer | Emil Renner Berthing <esmil@mailme.dk> | 2013-01-29 23:26:16 +0100 |
commit | 11d341652792bf1eb21b5f42a4a0a5ea5298b164 (patch) | |
tree | 6248d3302e6ecf77f373505a5d4021fe24ba00dc | |
parent | d12ebbbd9ee55305e0017e1ed3ef13523a9a8334 (diff) | |
download | lem-11d341652792bf1eb21b5f42a4a0a5ea5298b164.tar.gz lem-11d341652792bf1eb21b5f42a4a0a5ea5298b164.tar.xz lem-11d341652792bf1eb21b5f42a4a0a5ea5298b164.zip |
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.
-rw-r--r-- | lem/io/core.c | 7 | ||||
-rw-r--r-- | 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; } |