Skip to content

Commit

Permalink
lib: improve i_close_fd() error message
Browse files Browse the repository at this point in the history
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().
  • Loading branch information
Josef 'Jeff' Sipek authored and Timo Sirainen committed Oct 3, 2017
1 parent b93dba1 commit ad81591
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/lib/lib.c
Expand Up @@ -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;

Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/macros.h
Expand Up @@ -212,8 +212,8 @@
/* 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() \
Expand Down

0 comments on commit ad81591

Please sign in to comment.