summaryrefslogtreecommitdiffhomepage
path: root/libs/nixio
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2009-07-11 07:01:32 +0000
committerSteven Barth <steven@midlink.org>2009-07-11 07:01:32 +0000
commit21be73a478f5409a13f10d56041af32c78709bbd (patch)
tree8a3e70e9125a8598bd6111a0beee62289ec1807d /libs/nixio
parenta29c4ce658fbdcc1d507646b14b22de0cf4890fc (diff)
nixio: Fix accidental closing of file descriptors after dup with two
parameters resulting in strange behaviour when spawning processes
Diffstat (limited to 'libs/nixio')
-rw-r--r--libs/nixio/src/file.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/libs/nixio/src/file.c b/libs/nixio/src/file.c
index 482752522..70c717e4e 100644
--- a/libs/nixio/src/file.c
+++ b/libs/nixio/src/file.c
@@ -123,14 +123,18 @@ static int nixio_dup(lua_State *L) {
if (stat == -1) {
return nixio__perror(L);
} else {
- int *udata = lua_newuserdata(L, sizeof(int));
- if (!udata) {
- return luaL_error(L, "out of memory");
- }
+ if (newfd == -1) {
+ int *udata = lua_newuserdata(L, sizeof(int));
+ if (!udata) {
+ return luaL_error(L, "out of memory");
+ }
- *udata = stat;
- luaL_getmetatable(L, NIXIO_FILE_META);
- lua_setmetatable(L, -2);
+ *udata = stat;
+ luaL_getmetatable(L, NIXIO_FILE_META);
+ lua_setmetatable(L, -2);
+ } else {
+ lua_pushvalue(L, 2);
+ }
return 1;
}
}