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
Low-level file-system and process operations.
*/
+#include <errno.h>
+#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
{
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;