From 3f4e1e7274993b32b4dab8bdabdc9b645993923c Mon Sep 17 00:00:00 2001 From: Yichao Yu Date: Wed, 15 Jun 2016 21:28:48 -0400 Subject: [PATCH] Check if O_CLOEXEC exists before using. --- src/cgmemmgr.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cgmemmgr.cpp b/src/cgmemmgr.cpp index d5850b2265013..b0e0c3d79eea6 100644 --- a/src/cgmemmgr.cpp +++ b/src/cgmemmgr.cpp @@ -260,9 +260,16 @@ static int self_mem_fd = -1; static int init_self_mem() { +#ifdef O_CLOEXEC int fd = open("/proc/self/mem", O_RDWR | O_SYNC | O_CLOEXEC); if (fd == -1) return -1; +#else + int fd = open("/proc/self/mem", O_RDWR | O_SYNC); + if (fd == -1) + return -1; + fcntl(fd, F_SETFD, FD_CLOEXEC); +#endif // buffer to check if write works; volatile uint64_t buff = 0; uint64_t v = 0x12345678;