summaryrefslogtreecommitdiffstats
path: root/runtime/staprun/common.c
diff options
context:
space:
mode:
authorhunt <hunt>2007-10-09 16:03:04 +0000
committerhunt <hunt>2007-10-09 16:03:04 +0000
commit577e7ed19be74db082ba058016fd31b643495ebd (patch)
treec395a0e02f95de53044400fba71000c9e8f5bc3b /runtime/staprun/common.c
parenta6053c5b3f42ef0e016df9074ebc75c93a79d544 (diff)
downloadsystemtap-steved-577e7ed19be74db082ba058016fd31b643495ebd.tar.gz
systemtap-steved-577e7ed19be74db082ba058016fd31b643495ebd.tar.xz
systemtap-steved-577e7ed19be74db082ba058016fd31b643495ebd.zip
2007-10-09 Martin Hunt <hunt@redhat.com>
* common.c (set_clexec): New. * staprun.h: Add prototype for set_clexec. * relay*.c, ctl.c: Call set_clexec after file opens.
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;
+}