/* Copyright (c) 1999-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "net.h"
#include <unistd.h>
#include <fcntl.h>
{
int flags;
if (flags < 0)
}
{
int old_errno;
continue;
&socklen) < 0)
i_error("Leaked UNIX socket fd %d: %s",
continue;
}
rport = 0;
}
i_error("Leaked socket fd %d: %s:%u -> %s:%u",
continue;
}
#ifdef __APPLE__
/* OSX workaround: gettimeofday() calls shm_open()
internally and the fd won't get closed on exec.
weren't anything else. */
continue;
#endif
#ifdef HAVE_SYS_SYSMACROS_H
i_error("Leaked file fd %d: dev %s.%s inode %s",
continue;
#else
i_error("Leaked file fd %d: dev %s inode %s",
continue;
#endif
}
i_error("Leaked unknown fd %d (errno = %s)",
continue;
}
if (leaks)
i_fatal("fd leak found");
}
{
int flags;
if (flags < 0)
if (nonblock)
flags |= O_NONBLOCK;
else
flags &= ~O_NONBLOCK;
}
{
*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]);
*fdp[i] = -1;
else
}
}
{
int saved_errno;
if (*fd == -1)
return;
saved_errno = errno;
i_error("%s: close(%s%s%s) @ %s:%d failed (fd=%d): %m",
errno = saved_errno;
*fd = -1;
}