]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: move fd_close_maybe_stdio() to fd-util.[ch]
authorJosef 'Jeff' Sipek <jeff.sipek@dovecot.fi>
Wed, 4 Oct 2017 12:52:13 +0000 (08:52 -0400)
committerJosef 'Jeff' Sipek <jeff.sipek@dovecot.fi>
Thu, 5 Oct 2017 19:41:10 +0000 (15:41 -0400)
src/lib/fd-util.c
src/lib/fd-util.h
src/lib/lib.c
src/lib/lib.h

index 80c3c95b7860531ed9348343a16d45d727082279..16cbe81b4b5ac6a957e4b28ba040893350ba7354 100644 (file)
@@ -111,3 +111,22 @@ void fd_set_nonblock(int fd, bool nonblock)
        if (fcntl(fd, F_SETFL, flags) < 0)
                i_fatal("fcntl(%d, F_SETFL) failed: %m", fd);
 }
+
+void fd_close_maybe_stdio(int *fd_in, int *fd_out)
+{
+       int *fdp[2] = { fd_in, fd_out };
+
+       if (*fd_in == *fd_out)
+               *fd_in = -1;
+
+       for (unsigned int i = 0; i < N_ELEMENTS(fdp); i++) {
+               if (*fdp[i] == -1)
+                       ;
+               else if (*fdp[i] > 1)
+                       i_close_fd(fdp[i]);
+               else if (dup2(dev_null_fd, *fdp[i]) == *fdp[i])
+                       *fdp[i] = -1;
+               else
+                       i_fatal("dup2(/dev/null, %d) failed: %m", *fdp[i]);
+       }
+}
index bf81f69d797fe583d40f45e2674f5f35c95e7bed..0043eb99530d89291efbb5f40443c9ed6814ed1f 100644 (file)
@@ -10,4 +10,9 @@ void fd_debug_verify_leaks(int first_fd, int last_fd);
 /* Set file descriptor to blocking/nonblocking state */
 void fd_set_nonblock(int fd, bool nonblock);
 
+/* Close fd_in and fd_out, unless they're already -1. They can point to the
+   same fd, in which case they're closed only once. If they point to stdin
+   or stdout, they're replaced with /dev/null. */
+void fd_close_maybe_stdio(int *fd_in, int *fd_out);
+
 #endif
index 3c5739ca1a38bc9201a2d2d81a28a4e9b9dc87a2..3225a17c112ed2402c101cc1c9e65649628caf23 100644 (file)
@@ -50,25 +50,6 @@ void i_close_fd_path_real(int *fd, const char *path, const char *arg,
        *fd = -1;
 }
 
-void fd_close_maybe_stdio(int *fd_in, int *fd_out)
-{
-       int *fdp[2] = { fd_in, fd_out };
-
-       if (*fd_in == *fd_out)
-               *fd_in = -1;
-
-       for (unsigned int i = 0; i < N_ELEMENTS(fdp); i++) {
-               if (*fdp[i] == -1)
-                       ;
-               else if (*fdp[i] > 1)
-                       i_close_fd(fdp[i]);
-               else if (dup2(dev_null_fd, *fdp[i]) == *fdp[i])
-                       *fdp[i] = -1;
-               else
-                       i_fatal("dup2(/dev/null, %d) failed: %m", *fdp[i]);
-       }
-}
-
 #undef i_unlink
 int i_unlink(const char *path, const char *source_fname,
             unsigned int source_linenum)
index 69709975755ec2808d1b97105a9d836af695e1af..f6a5c2b04f70274586975d1794213971d9e115cb 100644 (file)
@@ -56,10 +56,6 @@ typedef void lib_atexit_callback_t(void);
    also inside chroots. */
 extern int dev_null_fd;
 
-/* Close fd_in and fd_out, unless they're already -1. They can point to the
-   same fd, in which case they're closed only once. If they point to stdin
-   or stdout, they're replaced with /dev/null. */
-void fd_close_maybe_stdio(int *fd_in, int *fd_out);
 /* Call unlink(). If it fails, log an error including the source filename
    and line number. */
 int i_unlink(const char *path, const char *source_fname,