chiark / gitweb /
basic/fd-util: introduce stdio_unset_cloexec() function
authorAlexander Kuleshov <kuleshovmail@gmail.com>
Sat, 2 Jul 2016 17:38:47 +0000 (23:38 +0600)
committerSven Eden <yamakuzure@gmx.net>
Fri, 16 Jun 2017 08:13:01 +0000 (10:13 +0200)
There are some places in the elogind which are use the same pattern:

    fd_cloexec(STDIN_FILENO, false);
    fd_cloexec(STDOUT_FILENO, false);
    fd_cloexec(STDERR_FILENO, false);

to unset CLOEXEC for standard file descriptors. This patch introduces
the stdio_unset_cloexec() function to hide this and make code cleaner.

src/basic/fd-util.c
src/basic/fd-util.h

index 8e4cfe3fe4084fec6f7c8b5d0654329821dfcc48..3eb3324b57bc2ae53ecbca7e4baf65be3c3f50ab 100644 (file)
@@ -186,6 +186,12 @@ int fd_cloexec(int fd, bool cloexec) {
         return 0;
 }
 
+void stdio_unset_cloexec(void) {
+        fd_cloexec(STDIN_FILENO, false);
+        fd_cloexec(STDOUT_FILENO, false);
+        fd_cloexec(STDERR_FILENO, false);
+}
+
 _pure_ static bool fd_in_set(int fd, const int fdset[], unsigned n_fdset) {
         unsigned i;
 
index 522ea6894955c10233e04d304566d65849e8fe1c..fe92b76c405c5880987e31dea53ff16076f61649 100644 (file)
@@ -65,6 +65,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(DIR*, closedir);
 
 int fd_nonblock(int fd, bool nonblock);
 int fd_cloexec(int fd, bool cloexec);
+void stdio_unset_cloexec(void);
 
 int close_all_fds(const int except[], unsigned n_except);