changed mod-sys.c to check O_CLOEXEC and O_NONBLOCK before using them

This commit is contained in:
hyung-hwan 2019-09-02 07:46:04 +00:00
parent 0931dd7b3d
commit c6522a0291

View File

@ -661,7 +661,7 @@ static int fnc_dup (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
#if defined(HAVE_DUP3) #if defined(HAVE_DUP3)
fd = dup3(sys_node->ctx.u.fd, sys_node2->ctx.u.fd, oflags); fd = dup3(sys_node->ctx.u.fd, sys_node2->ctx.u.fd, oflags);
#else #else
fd = dup2(sys_node->ctx.u.fd); fd = dup2(sys_node->ctx.u.fd, sys_node2->ctx.u.fd);
#endif #endif
if (fd >= 0) if (fd >= 0)
{ {
@ -671,8 +671,12 @@ static int fnc_dup (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
if (oflags) if (oflags)
{ {
int nflags = 0; int nflags = 0;
#if defined(O_CLOEXEC) && defined(FD_CLOEXEC)
if (oflags & O_CLOEXEC) nflags |= FD_CLOEXEC; if (oflags & O_CLOEXEC) nflags |= FD_CLOEXEC;
#endif
#if defined(O_NONBLOCK) && defined(FD_NONBLOCK)
/*if (oflags & O_NONBLOCK) nflags |= FD_NONBLOCK; dup3() doesn't seem to support NONBLOCK. */ /*if (oflags & O_NONBLOCK) nflags |= FD_NONBLOCK; dup3() doesn't seem to support NONBLOCK. */
#endif
if (nflags) fcntl (fd, F_SETFD, nflags); if (nflags) fcntl (fd, F_SETFD, nflags);
} }