summaryrefslogtreecommitdiffstats
path: root/runtime/staprun/common.c
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/staprun/common.c')
-rw-r--r--runtime/staprun/common.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/runtime/staprun/common.c b/runtime/staprun/common.c
index d3f8835a..47778efd 100644
--- a/runtime/staprun/common.c
+++ b/runtime/staprun/common.c
@@ -315,3 +315,22 @@ int send_request(int type, void *data, int len)
memcpy(&buf[4], data, len);
return write(control_channel, buf, len+4);
}
+
+/*
+ * set FD_CLOEXEC for any file descriptor
+ */
+int set_clexec(int fd)
+{
+ int val;
+ if ((val = fcntl(fd, F_GETFD, 0)) < 0)
+ goto err;
+
+ if ((val = fcntl(fd, F_SETFD, val | FD_CLOEXEC)) < 0)
+ goto err;
+
+ return 0;
+err:
+ perr("fcntl failed");
+ close(fd);
+ return -1;
+}