Skip to content

Commit dd2f7d6

Browse files
committed
[Bug #21794] Fix for platforms where O_CLOEXEC is not available
1 parent f0472f2 commit dd2f7d6

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

box.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "internal/file.h"
1010
#include "internal/gc.h"
1111
#include "internal/hash.h"
12+
#include "internal/io.h"
1213
#include "internal/load.h"
1314
#include "internal/st.h"
1415
#include "internal/variable.h"
@@ -627,20 +628,27 @@ copy_ext_file(const char *src_path, const char *dst_path)
627628
# else
628629
const int bin = 0;
629630
# endif
630-
const int src_fd = open(src_path, O_RDONLY|bin);
631+
# ifdef O_CLOEXEC
632+
const int cloexec = O_CLOEXEC;
633+
# else
634+
const int cloexec = 0;
635+
# endif
636+
const int src_fd = open(src_path, O_RDONLY|cloexec|bin);
631637
if (src_fd < 0) return COPY_ERROR_SRC_OPEN;
638+
if (!cloexec) rb_maygvl_fd_fix_cloexec(src_fd);
632639

633640
struct stat src_st;
634641
if (fstat(src_fd, &src_st)) {
635642
close(src_fd);
636643
return COPY_ERROR_SRC_STAT;
637644
}
638645

639-
const int dst_fd = open(dst_path, O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC|bin, S_IRWXU);
646+
const int dst_fd = open(dst_path, O_WRONLY|O_CREAT|O_EXCL|cloexec|bin, S_IRWXU);
640647
if (dst_fd < 0) {
641648
close(src_fd);
642649
return COPY_ERROR_DST_OPEN;
643650
}
651+
if (!cloexec) rb_maygvl_fd_fix_cloexec(dst_fd);
644652

645653
enum copy_error_type ret = COPY_ERROR_NONE;
646654

depend

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,7 @@ box.$(OBJEXT): $(top_srcdir)/internal/file.h
745745
box.$(OBJEXT): $(top_srcdir)/internal/gc.h
746746
box.$(OBJEXT): $(top_srcdir)/internal/hash.h
747747
box.$(OBJEXT): $(top_srcdir)/internal/imemo.h
748+
box.$(OBJEXT): $(top_srcdir)/internal/io.h
748749
box.$(OBJEXT): $(top_srcdir)/internal/load.h
749750
box.$(OBJEXT): $(top_srcdir)/internal/sanitizers.h
750751
box.$(OBJEXT): $(top_srcdir)/internal/serial.h
@@ -951,6 +952,7 @@ box.$(OBJEXT): {$(VPATH)}internal/value_type.h
951952
box.$(OBJEXT): {$(VPATH)}internal/variable.h
952953
box.$(OBJEXT): {$(VPATH)}internal/warning_push.h
953954
box.$(OBJEXT): {$(VPATH)}internal/xmalloc.h
955+
box.$(OBJEXT): {$(VPATH)}io.h
954956
box.$(OBJEXT): {$(VPATH)}iseq.h
955957
box.$(OBJEXT): {$(VPATH)}method.h
956958
box.$(OBJEXT): {$(VPATH)}missing.h

0 commit comments

Comments
 (0)