public static void fdFixCloexec(PosixShim posix, int fd) { if (fd >= 0 && fd < FilenoUtil.FIRST_FAKE_FD) { int flags, flags2, ret; flags = posix.fcntlGetFD(fd); /* should not fail except EBADF. */ if (flags == -1) { throw new AssertionError(String.format("BUG: rb_maygvl_fd_fix_cloexec: fcntl(%d, F_GETFD) failed: %s", fd, posix.errno.description())); } if (fd <= 2) flags2 = flags & ~FcntlLibrary.FD_CLOEXEC; /* Clear CLOEXEC for standard file descriptors: 0, 1, 2. */ else flags2 = flags | FcntlLibrary.FD_CLOEXEC; /* Set CLOEXEC for non-standard file descriptors: 3, 4, 5, ... */ if (flags != flags2) { ret = posix.fcntlSetFD(fd, flags2); if (ret == -1) { throw new AssertionError(String.format("BUG: rb_maygvl_fd_fix_cloexec: fcntl(%d, F_SETFD, %d) failed: %s", fd, flags2, posix.errno.description())); } } } // otherwise JVM sets cloexec }
public static void fdFixCloexec(PosixShim posix, int fd) { if (fd >= 0 && fd < FilenoUtil.FIRST_FAKE_FD) { int flags, flags2, ret; flags = posix.fcntlGetFD(fd); /* should not fail except EBADF. */ if (flags == -1) { throw new AssertionError(String.format("BUG: rb_maygvl_fd_fix_cloexec: fcntl(%d, F_GETFD) failed: %s", fd, posix.errno.description())); } if (fd <= 2) flags2 = flags & ~FcntlLibrary.FD_CLOEXEC; /* Clear CLOEXEC for standard file descriptors: 0, 1, 2. */ else flags2 = flags | FcntlLibrary.FD_CLOEXEC; /* Set CLOEXEC for non-standard file descriptors: 3, 4, 5, ... */ if (flags != flags2) { ret = posix.fcntlSetFD(fd, flags2); if (ret == -1) { throw new AssertionError(String.format("BUG: rb_maygvl_fd_fix_cloexec: fcntl(%d, F_SETFD, %d) failed: %s", fd, flags2, posix.errno.description())); } } } // otherwise JVM sets cloexec }