]> git.e2factory.org Git - e2factory.git/commitdiff
luafile: open now sets FD_CLOEXEC by default
authorTobias Ulmer <tu@emlix.com>
Wed, 7 Oct 2015 16:30:58 +0000 (18:30 +0200)
committerTobias Ulmer <tu@emlix.com>
Thu, 8 Oct 2015 15:49:17 +0000 (17:49 +0200)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
Changelog
generic/luafile_ll.c

index 63bd17dda5c0348fe1ecd362692f8d99a36659ac..ffd8945cf18728a40f3f1f15be3a05544021ba95 100644 (file)
--- 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
index fdc56674118299a9b55ad78e79e4d49ad5a9a5f5..121bf8b05dee32db067bb7ea52b597edd3a86c8a 100644 (file)
@@ -29,6 +29,8 @@
    Low-level file-system and process operations.
 */
 
+#include <errno.h>
+#include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -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;