Fix: Set CLOEXEC flag on every created sockets
[lttng-tools.git] / src / common / utils.c
index 781888eb351d1ff720b13826706c3cd41812a51c..1a0e47ec4ed97b1601cbc3498126a760b5e02895 100644 (file)
@@ -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;
+}
This page took 0.023686 seconds and 5 git commands to generate.