diff options
-rw-r--r-- | src/client.c | 3 | ||||
-rw-r--r-- | src/log.h | 7 | ||||
-rw-r--r-- | src/net.c | 6 | ||||
-rw-r--r-- | src/process.c | 7 | ||||
-rw-r--r-- | src/tcp_server.c | 6 | ||||
-rw-r--r-- | src/worker.c | 4 | ||||
-rw-r--r-- | src/worker_queue.c | 4 |
7 files changed, 23 insertions, 14 deletions
diff --git a/src/client.c b/src/client.c index e42019c..be46ad1 100644 --- a/src/client.c +++ b/src/client.c @@ -1,4 +1,5 @@ #include "client.h" +#include "log.h" #include "msg.h" #include "net.h" @@ -15,7 +16,7 @@ int client_create(struct client *client, const struct settings *settings) void client_destroy(const struct client *client) { - close(client->fd); + check_errno(close(client->fd), "close"); } int client_main(const struct client *client, int argc, char *argv[]) @@ -15,6 +15,13 @@ perror(s); \ } while (0) +#define check_errno(expr, s) \ + do { \ + int CONCAT(ret, __LINE__) = expr; \ + if (CONCAT(ret, __LINE__) < 0) \ + print_errno(s); \ + } while (0) + #define pthread_print_errno(var, s) \ do { \ errno = var; \ @@ -49,7 +49,7 @@ int net_bind(const char *port) break; close_socket: - close(socket_fd); + check_errno(close(socket_fd), "close"); } freeaddrinfo(result); @@ -68,7 +68,7 @@ int net_bind(const char *port) return socket_fd; fail: - close(socket_fd); + check_errno(close(socket_fd), "close"); return ret; } @@ -117,7 +117,7 @@ int net_connect(const char *host, const char *port) break; close_socket: - close(socket_fd); + check_errno(close(socket_fd), "close"); } freeaddrinfo(result); diff --git a/src/process.c b/src/process.c index 7d62a88..c4ff307 100644 --- a/src/process.c +++ b/src/process.c @@ -54,7 +54,7 @@ static int redirect_and_exec_child(int pipe_fds[2], const char *args[]) { int ret = 0; - close(pipe_fds[0]); + check_errno(close(pipe_fds[0]), "close"); ret = dup2(pipe_fds[1], STDOUT_FILENO); if (ret < 0) { @@ -91,7 +91,7 @@ int proc_capture(const char *args[], struct proc_output *result) if (!child_pid) exit(redirect_and_exec_child(pipe_fds, args)); - close(pipe_fds[1]); + check_errno(close(pipe_fds[1]), "close"); ret = file_read(pipe_fds[0], &result->output, &result->output_len); if (ret < 0) @@ -107,7 +107,8 @@ free_output: free(result->output); close_pipe: - close(pipe_fds[0]); + check_errno(close(pipe_fds[0]), "close"); + /* No errno checking here, we might've already closed the write end. */ close(pipe_fds[1]); return ret; diff --git a/src/tcp_server.c b/src/tcp_server.c index e479cd0..633b7f2 100644 --- a/src/tcp_server.c +++ b/src/tcp_server.c @@ -17,7 +17,7 @@ int tcp_server_create(struct tcp_server *server, const char *port) void tcp_server_destroy(const struct tcp_server *server) { - close(server->fd); + check_errno(close(server->fd), "close"); } struct child_context { @@ -30,7 +30,7 @@ static void *connection_thread(void *_ctx) { struct child_context *ctx = (struct child_context *)_ctx; ctx->handler(ctx->fd, ctx->arg); - close(ctx->fd); + check_errno(close(ctx->fd), "close"); free(ctx); return NULL; } @@ -86,7 +86,7 @@ free_ctx: free(ctx); close_conn: - close(conn_fd); + check_errno(close(conn_fd), "close"); return ret; } diff --git a/src/worker.c b/src/worker.c index 1c27173..19270db 100644 --- a/src/worker.c +++ b/src/worker.c @@ -36,7 +36,7 @@ int worker_create(struct worker *worker, const struct settings *settings) return ret; close: - close(worker->fd); + check_errno(close(worker->fd), "close"); git_shutdown: libgit_shutdown(); @@ -53,7 +53,7 @@ void worker_destroy(struct worker *worker) worker->task_active = 0; } pthread_check(pthread_mutex_destroy(&worker->task_mtx), "pthread_mutex_destroy"); - close(worker->fd); + check_errno(close(worker->fd), "close"); libgit_shutdown(); } diff --git a/src/worker_queue.c b/src/worker_queue.c index bb0077b..c832746 100644 --- a/src/worker_queue.c +++ b/src/worker_queue.c @@ -24,14 +24,14 @@ int worker_queue_entry_create(struct worker_queue_entry **entry, int fd) return 0; close_newfd: - close(newfd); + check_errno(close(newfd), "close"); return -1; } void worker_queue_entry_destroy(struct worker_queue_entry *entry) { - close(entry->fd); + check_errno(close(entry->fd), "close"); free(entry); } |