Lines Matching refs:fd
11 void fd_close_on_exec(int fd, bool set)
15 flags = fcntl(fd, F_GETFD, 0);
17 i_fatal("fcntl(F_GETFD, %d) failed: %m", fd);
20 if (fcntl(fd, F_SETFD, flags) < 0)
21 i_fatal("fcntl(F_SETFD, %d) failed: %m", fd);
32 for (int fd = first_fd; fd <= last_fd; ++fd) {
33 if (fcntl(fd, F_GETFD, 0) == -1 && errno == EBADF)
38 if (net_getsockname(fd, &addr, &port) == 0) {
44 if (getsockname(fd, (void *)&sa,
48 i_error("Leaked UNIX socket fd %d: %s",
49 fd, sa.sun_path);
54 if (net_getpeername(fd, &raddr, &rport) < 0) {
58 i_error("Leaked socket fd %d: %s:%u -> %s:%u",
59 fd, net_ip2addr(&addr), port,
65 if (fstat(fd, &st) == 0) {
68 internally and the fd won't get closed on exec.
75 i_error("Leaked file fd %d: dev %s.%s inode %s",
76 fd, dec2str(major(st.st_dev)),
81 i_error("Leaked file fd %d: dev %s inode %s",
82 fd, dec2str(st.st_dev),
89 i_error("Leaked unknown fd %d (errno = %s)",
90 fd, strerror(old_errno));
95 i_fatal("fd leak found");
98 void fd_set_nonblock(int fd, bool nonblock)
102 flags = fcntl(fd, F_GETFL, 0);
104 i_fatal("fcntl(%d, F_GETFL) failed: %m", fd);
111 if (fcntl(fd, F_SETFL, flags) < 0)
112 i_fatal("fcntl(%d, F_SETFL) failed: %m", fd);
135 void i_close_fd_path(int *fd, const char *path, const char *arg,
140 if (*fd == -1)
143 i_assert(*fd > 0);
146 if (unlikely(close(*fd) < 0))
147 i_error("%s: close(%s%s%s) @ %s:%d failed (fd=%d): %m",
151 file, line, *fd);
154 *fd = -1;