]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: improve i_close_fd() error message
authorJosef 'Jeff' Sipek <jeff.sipek@dovecot.fi>
Tue, 19 Sep 2017 13:23:30 +0000 (16:23 +0300)
committerTimo Sirainen <tss@dovecot.fi>
Tue, 3 Oct 2017 07:14:05 +0000 (10:14 +0300)
In addition to printing the file and line number, we can print the
actual arg passed in as well as the function calling i_close_fd().

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

index c931f62b9607f1090db789d47a936153e2f95f10..ba4e4433151d44608b25fdc640b9470a4fd63419 100644 (file)
@@ -41,7 +41,8 @@ int close_keep_errno(int *fd)
        return ret;
 }
 
-void i_close_fd_real(int *fd, const char *file, int line)
+void i_close_fd_real(int *fd, const char *arg, const char *func,
+                    const char *file, int line)
 {
        int saved_errno;
 
@@ -52,7 +53,8 @@ void i_close_fd_real(int *fd, const char *file, int line)
 
        saved_errno = errno;
        if (unlikely(close(*fd) < 0))
-               i_error("close(%d[%s:%d]) failed: %m", *fd, file, line);
+               i_error("%s: close(%s) @ %s:%d failed (fd=%d): %m",
+                       func, arg, file, line, *fd);
        errno = saved_errno;
 
        *fd = -1;
index 5d75fed7c6a79acdeec64898ebc3a45c3917f4c2..cf845eee10ee2709917e8979c56c21ed9d7e123c 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 *file, int line);
-#define i_close_fd(fd) i_close_fd_real((fd), __FILE__, __LINE__)
+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__)
 
 #ifndef STATIC_CHECKER
 #  define i_unreached() \