We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 816c7cf commit 7a7c31fCopy full SHA for 7a7c31f
1 file changed
luaext/lposix.c
@@ -335,10 +335,22 @@ static int Pexec(lua_State *L) /** exec(path,[args]) */
335
const char *path = luaL_checkstring(L, 1);
336
int i,n=lua_gettop(L);
337
char **argv;
338
+ int flag, fdno, open_max;
339
340
if (!have_forked)
341
return luaL_error(L, "exec not permitted in this context");
342
343
+ open_max = sysconf(_SC_OPEN_MAX);
344
+ if (open_max == -1) {
345
+ open_max = 1024;
346
+ }
347
+ for (fdno = 3; fdno < open_max; fdno++) {
348
+ flag = fcntl(fdno, F_GETFD);
349
+ if (flag == -1 || (flag & FD_CLOEXEC))
350
+ continue;
351
+ fcntl(fdno, F_SETFD, FD_CLOEXEC);
352
353
+
354
argv = malloc((n+1)*sizeof(char*));
355
if (argv==NULL) return luaL_error(L,"not enough memory");
356
argv[0] = (char*)path;
0 commit comments