]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: introduce i_close_fd_path()
authorJosef 'Jeff' Sipek <jeff.sipek@dovecot.fi>
Fri, 22 Sep 2017 07:33:51 +0000 (10:33 +0300)
committerTimo Sirainen <tss@dovecot.fi>
Tue, 3 Oct 2017 07:14:05 +0000 (10:14 +0300)
It is like i_close_fd() but takes an argument with the name of the file
that's being closed.  The name is only used when printing the error
message due to a failed close() syscall.

src/lib/lib.c
src/lib/macros.h

index 413474fcc19549bff71c0cf50b013dd69d27946c..0ce51bec745dc324561dbf1104b5a60dc6deca7c 100644 (file)
@@ -29,8 +29,8 @@ struct atexit_callback {
 
 static ARRAY(struct atexit_callback) atexit_callbacks = ARRAY_INIT;
 
-void i_close_fd_real(int *fd, const char *arg, const char *func,
-                    const char *file, int line)
+void i_close_fd_path_real(int *fd, const char *path, const char *arg,
+                         const char *func, const char *file, int line)
 {
        int saved_errno;
 
@@ -41,8 +41,11 @@ void i_close_fd_real(int *fd, const char *arg, const char *func,
 
        saved_errno = errno;
        if (unlikely(close(*fd) < 0))
-               i_error("%s: close(%s) @ %s:%d failed (fd=%d): %m",
-                       func, arg, file, line, *fd);
+               i_error("%s: close(%s%s%s) @ %s:%d failed (fd=%d): %m",
+                       func, arg,
+                       (path == NULL) ? "" : " = ",
+                       (path == NULL) ? "" : path,
+                       file, line, *fd);
        errno = saved_errno;
 
        *fd = -1;
index cf845eee10ee2709917e8979c56c21ed9d7e123c..dc73441242870b841e5c0f0c3f90ca8ef7759136 100644 (file)
 /* Close the fd and set it to -1. This assert-crashes if fd == 0, and is a
    no-op if fd == -1. Normally fd == 0 would happen only if an uninitialized
    fd is attempted to be closed, which is a bug. */
-void i_close_fd_real(int *fd, const char *arg, const char *func, const char *file, int line);
-#define i_close_fd(fd) i_close_fd_real((fd), #fd, __func__, __FILE__, __LINE__)
+void i_close_fd_path_real(int *fd, const char *path, const char *arg,
+                         const char *func, const char *file, int line);
+#define i_close_fd(fd) i_close_fd_path_real((fd), NULL, #fd, __func__, __FILE__, __LINE__)
+#define i_close_fd_path(fd, path) i_close_fd_path_real((fd), (path), #fd, __func__, __FILE__, __LINE__)
 
 #ifndef STATIC_CHECKER
 #  define i_unreached() \