diff options
Diffstat (limited to '')
-rw-r--r-- | src/file.c | 5 | ||||
-rw-r--r-- | src/file.h | 2 | ||||
-rw-r--r-- | src/msg.c | 2 | ||||
-rw-r--r-- | src/net.c | 12 | ||||
-rw-r--r-- | src/net.h | 1 | ||||
-rw-r--r-- | src/process.c | 6 | ||||
-rw-r--r-- | src/tcp_server.c | 5 | ||||
-rw-r--r-- | src/worker_queue.c | 4 |
8 files changed, 25 insertions, 12 deletions
@@ -98,6 +98,11 @@ free: return NULL; } +void file_close(int fd) +{ + log_errno_if(close(fd), "close"); +} + int file_exists(const char *path) { struct stat stat; @@ -15,6 +15,8 @@ int rm_rf(const char *dir); int my_chdir(const char *dir, char **old); char *my_readlink(const char *path); +void file_close(int fd); + int file_exists(const char *path); int file_read(int fd, char **output, size_t *size); @@ -245,7 +245,7 @@ int msg_connect_and_communicate(const char *host, const char *port, const struct goto close; close: - log_errno_if(close(fd), "close"); + net_close(fd); return ret; } @@ -6,6 +6,7 @@ */ #include "net.h" +#include "file.h" #include "log.h" #include <netdb.h> @@ -65,7 +66,7 @@ int net_bind(const char *port) break; close_socket: - log_errno_if(close(socket_fd), "close"); + net_close(socket_fd); } freeaddrinfo(result); @@ -84,7 +85,7 @@ int net_bind(const char *port) return socket_fd; fail: - log_errno_if(close(socket_fd), "close"); + net_close(socket_fd); return ret; } @@ -133,7 +134,7 @@ int net_connect(const char *host, const char *port) break; close_socket: - log_errno_if(close(socket_fd), "close"); + net_close(socket_fd); } freeaddrinfo(result); @@ -146,6 +147,11 @@ int net_connect(const char *host, const char *port) return socket_fd; } +void net_close(int fd) +{ + file_close(fd); +} + static ssize_t net_send_part(int fd, const void *buf, size_t size) { static const int flags = MSG_NOSIGNAL; @@ -14,6 +14,7 @@ int net_bind(const char *port); int net_accept(int fd); int net_connect(const char *host, const char *port); +void net_close(int fd); int net_send(int fd, const void *, size_t); int net_recv(int fd, void *, size_t); diff --git a/src/process.c b/src/process.c index c0888b4..f38f4f5 100644 --- a/src/process.c +++ b/src/process.c @@ -66,7 +66,7 @@ static int redirect_and_exec_child(int pipe_fds[2], const char *args[], const ch { int ret = 0; - log_errno_if(close(pipe_fds[0]), "close"); + file_close(pipe_fds[0]); ret = dup2(pipe_fds[1], STDOUT_FILENO); if (ret < 0) { @@ -103,7 +103,7 @@ int proc_capture(const char *args[], const char *envp[], struct proc_output *res if (!child_pid) exit(redirect_and_exec_child(pipe_fds, args, envp)); - log_errno_if(close(pipe_fds[1]), "close"); + file_close(pipe_fds[1]); ret = file_read(pipe_fds[0], &result->output, &result->output_len); if (ret < 0) @@ -119,7 +119,7 @@ free_output: free(result->output); close_pipe: - log_errno_if(close(pipe_fds[0]), "close"); + file_close(pipe_fds[0]); /* No errno checking here, we might've already closed the write end. */ close(pipe_fds[1]); diff --git a/src/tcp_server.c b/src/tcp_server.c index 277f81e..2e65bc5 100644 --- a/src/tcp_server.c +++ b/src/tcp_server.c @@ -13,7 +13,6 @@ #include <pthread.h> #include <signal.h> #include <stdlib.h> -#include <unistd.h> struct tcp_server { int fd; @@ -45,7 +44,7 @@ free: void tcp_server_destroy(struct tcp_server *server) { - log_errno_if(close(server->fd), "close"); + net_close(server->fd); free(server); } @@ -116,7 +115,7 @@ restore_mask: signal_restore(&old_mask); close_conn: - log_errno_if(close(ctx->fd), "close"); + net_close(ctx->fd); free_ctx: free(ctx); diff --git a/src/worker_queue.c b/src/worker_queue.c index 06119e2..b0dda38 100644 --- a/src/worker_queue.c +++ b/src/worker_queue.c @@ -7,11 +7,11 @@ #include "worker_queue.h" #include "log.h" +#include "net.h" #include <pthread.h> #include <stdlib.h> #include <sys/queue.h> -#include <unistd.h> struct worker { pthread_t thread; @@ -38,7 +38,7 @@ void worker_destroy(struct worker *entry) { log("Waiting for worker %d thread to exit\n", entry->fd); pthread_errno_if(pthread_join(entry->thread, NULL), "pthread_join"); - log_errno_if(close(entry->fd), "close"); + net_close(entry->fd); free(entry); } |