From c5499f929d43611a6d4cbd408928d6ae90a0bab5 Mon Sep 17 00:00:00 2001 From: Tobias Ulmer Date: Wed, 7 Oct 2015 18:30:58 +0200 Subject: [PATCH] luafile: open now sets FD_CLOEXEC by default Signed-off-by: Tobias Ulmer --- Changelog | 1 + generic/luafile_ll.c | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 63bd17d..ffd8945 100644 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ NEXT: + * luafile.open() sets FD_CLOEXEC by default * Fix incorrect use of shquote(), preventing x86_64 chroot builds * Fix regression preventing use of x86_64 chroot * Fix hashcache problem causing an incorrect BuildID diff --git a/generic/luafile_ll.c b/generic/luafile_ll.c index fdc5667..121bf8b 100644 --- a/generic/luafile_ll.c +++ b/generic/luafile_ll.c @@ -29,6 +29,8 @@ Low-level file-system and process operations. */ +#include +#include #include #include #include @@ -43,12 +45,20 @@ lua_fopen(lua_State *lua) { FILE *f; const char *file, *mode; + int fd = -1; + file = luaL_checkstring(lua, 1); mode = luaL_checkstring(lua, 2); f = fopen(file, mode); - if(f == NULL) { + if (f == NULL) { lua_pushnil(lua); } else { + fd = fileno(f); + if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) { + lua_pushfstring(lua, "%s: fcntl(%d): %s: %s", __func__, + fd, file, strerror(errno)); + lua_error(lua); + } lua_pushlightuserdata(lua, (void *)f); } return 1; -- 2.39.5