X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Futils.c;h=1a0e47ec4ed97b1601cbc3498126a760b5e02895;hp=781888eb351d1ff720b13826706c3cd41812a51c;hb=b662582bf448d2fad2f5990580771733a3b33d16;hpb=cb365c03b0b4efc0d3f0875be586a8f4f270aaf6 diff --git a/src/common/utils.c b/src/common/utils.c index 781888eb3..1a0e47ec4 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -179,3 +179,26 @@ char *utils_strdupdelim(const char *begin, const char *end) error: return str; } + +/* + * Set CLOEXEC flag to the give file descriptor. + */ +__attribute__((visibility("hidden"))) +int utils_set_fd_cloexec(int fd) +{ + int ret; + + if (fd < 0) { + ret = -EINVAL; + goto end; + } + + ret = fcntl(fd, F_SETFD, FD_CLOEXEC); + if (ret < 0) { + PERROR("fcntl cloexec"); + ret = -errno; + } + +end: + return ret; +}