summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backlight.c2
-rw-r--r--src/fd.c24
-rw-r--r--src/fd.h1
3 files changed, 26 insertions, 1 deletions
diff --git a/src/backlight.c b/src/backlight.c
index bb53abae..129afea6 100644
--- a/src/backlight.c
+++ b/src/backlight.c
@@ -271,7 +271,7 @@ enum backlight_type backlight_exists(const char *iface)
static int __backlight_init(struct backlight *b, char *iface, int fd)
{
- b->fd = fd_set_cloexec(fd_set_nonblock(fd));
+ b->fd = fd_move_cloexec(fd_set_nonblock(fd));
b->iface = iface;
return 1;
}
diff --git a/src/fd.c b/src/fd.c
index 9e1fb6c4..445e3f4a 100644
--- a/src/fd.c
+++ b/src/fd.c
@@ -31,8 +31,32 @@
#include <fcntl.h>
#include <unistd.h>
+#include <misc.h> /* MAXCLIENTS */
+
#include "fd.h"
+int fd_move_cloexec(int fd)
+{
+ int newfd;
+
+ newfd = fcntl(fd,
+#ifdef F_DUPFD_CLOEXEC
+ F_DUPFD_CLOEXEC,
+#else
+ F_DUPFD,
+#endif
+ MAXCLIENTS);
+ if (newfd < 0)
+ return fd;
+
+#ifndef F_DUPFD_CLOEXEC
+ newfd = fd_set_cloexec(newfd);
+#endif
+
+ close(fd);
+ return newfd;
+}
+
int fd_set_cloexec(int fd)
{
int flags;
diff --git a/src/fd.h b/src/fd.h
index c860e0af..d71fa7b0 100644
--- a/src/fd.h
+++ b/src/fd.h
@@ -27,6 +27,7 @@
#ifndef FD_H
#define FD_H
+int fd_move_cloexec(int fd);
int fd_set_cloexec(int fd);
int fd_set_nonblock(int fd);