From: Ivan Maidanski Date: Thu, 18 Feb 2016 21:55:22 +0000 (+0300) Subject: Fix unchecked fcntl() result X-Git-Tag: gc7_4_4~27 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=040e9aa6be96c80468624328a56c3d469eec3375;p=gc Fix unchecked fcntl() result * os_dep.c (GC_unix_mmap_get_mem, GC_dirty_init): Call WARN() if fcntl() failed. --- diff --git a/os_dep.c b/os_dep.c index 2d014023..886e789c 100644 --- a/os_dep.c +++ b/os_dep.c @@ -2034,8 +2034,9 @@ STATIC ptr_t GC_unix_mmap_get_mem(word bytes) # endif if (zero_fd == -1) ABORT("Could not open /dev/zero"); + if (fcntl(zero_fd, F_SETFD, FD_CLOEXEC) == -1) + WARN("Could not set FD_CLOEXEC for /dev/zero", 0); - fcntl(zero_fd, F_SETFD, FD_CLOEXEC); initialized = TRUE; } # endif @@ -3636,9 +3637,10 @@ GC_INNER void GC_dirty_init(void) buf[sizeof(buf) - 1] = '\0'; GC_proc_fd = open(buf, O_RDONLY); if (GC_proc_fd < 0) { - ABORT("/proc open failed"); + ABORT("/proc open failed"); } - syscall(SYS_fcntl, GC_proc_fd, F_SETFD, FD_CLOEXEC); + if (syscall(SYS_fcntl, GC_proc_fd, F_SETFD, FD_CLOEXEC) == -1) + WARN("Could not set FD_CLOEXEC for /proc", 0); GC_dirty_maintained = TRUE; GC_proc_buf = GC_scratch_alloc(GC_proc_buf_size);