From 5e64d1c4b78c908e92a65e03fdc6817ffe59a8a6 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Thu, 8 Sep 2022 09:04:24 +0200 Subject: log: refactoring --- src/ci.c | 4 ++-- src/ci_queue.c | 6 +++--- src/client.c | 4 ++-- src/file.c | 12 ++++++------ src/git.c | 24 ++++++++++++------------ src/log.h | 42 +++++++++++++++++++++--------------------- src/msg.c | 16 ++++++++-------- src/net.c | 44 ++++++++++++++++++++++---------------------- src/process.c | 20 ++++++++++---------- src/server.c | 52 ++++++++++++++++++++++++++-------------------------- src/signal.c | 2 +- src/tcp_server.c | 18 +++++++++--------- src/worker.c | 18 +++++++++--------- 13 files changed, 131 insertions(+), 131 deletions(-) (limited to 'src') diff --git a/src/ci.c b/src/ci.c index 5f3dad4..bfd30e9 100644 --- a/src/ci.c +++ b/src/ci.c @@ -34,11 +34,11 @@ int ci_run(struct proc_output *result) for (const char **script = ci_scripts; *script; ++script) { if (!file_exists(*script)) continue; - print_log("Going to run: %s\n", *script); + log("Going to run: %s\n", *script); return ci_run_script(*script, result); } - print_log("Couldn't find any CI scripts to run\n"); + log("Couldn't find any CI scripts to run\n"); return -1; } diff --git a/src/ci_queue.c b/src/ci_queue.c index d87d3c0..03cb0e7 100644 --- a/src/ci_queue.c +++ b/src/ci_queue.c @@ -11,19 +11,19 @@ int ci_queue_entry_create(struct ci_queue_entry **entry, const char *_url, const url = strdup(_url); if (!url) { - print_errno("strdup"); + log_errno("strdup"); goto fail; } rev = strdup(_rev); if (!rev) { - print_errno("strdup"); + log_errno("strdup"); goto free_url; } *entry = malloc(sizeof(struct ci_queue_entry)); if (!*entry) { - print_errno("malloc"); + log_errno("malloc"); goto free_rev; } (*entry)->url = url; diff --git a/src/client.c b/src/client.c index c711235..6f1bb47 100644 --- a/src/client.c +++ b/src/client.c @@ -16,7 +16,7 @@ int client_create(struct client *client, const struct settings *settings) void client_destroy(const struct client *client) { - check_errno(close(client->fd), "close"); + log_errno_if(close(client->fd), "close"); } int client_main(const struct client *client, int argc, char *argv[]) @@ -30,7 +30,7 @@ int client_main(const struct client *client, int argc, char *argv[]) return ret; if (msg_is_error(&response)) { - print_error("Server failed to process the request\n"); + log_err("Server failed to process the request\n"); ret = -1; goto free_response; } diff --git a/src/file.c b/src/file.c index 3723cf6..58d63e3 100644 --- a/src/file.c +++ b/src/file.c @@ -16,7 +16,7 @@ static int unlink_cb(const char *fpath, UNUSED const struct stat *sb, UNUSED int ret = remove(fpath); if (ret < 0) { - print_errno("remove"); + log_errno("remove"); return ret; } @@ -25,7 +25,7 @@ static int unlink_cb(const char *fpath, UNUSED const struct stat *sb, UNUSED int int rm_rf(const char *dir) { - print_log("Recursively removing directory: %s\n", dir); + log("Recursively removing directory: %s\n", dir); return nftw(dir, unlink_cb, 64, FTW_DEPTH | FTW_PHYS); } @@ -36,14 +36,14 @@ int my_chdir(const char *dir, char **old) if (old) { *old = get_current_dir_name(); if (!*old) { - print_errno("get_current_dir_name"); + log_errno("get_current_dir_name"); return -1; } } ret = chdir(dir); if (ret < 0) { - print_errno("chdir"); + log_errno("chdir"); goto free_old; } @@ -76,7 +76,7 @@ int file_read(int fd, char **output, size_t *len) ssize_t read_now = read(fd, buf, buf_len); if (read_now < 0) { - print_errno("read"); + log_errno("read"); ret = read_now; goto free_output; } @@ -86,7 +86,7 @@ int file_read(int fd, char **output, size_t *len) *output = realloc(*output, *len + read_now + 1); if (!*output) { - print_errno("realloc"); + log_errno("realloc"); return -1; } memcpy(*output + *len, buf, read_now); diff --git a/src/git.c b/src/git.c index af4eb01..d7f7c69 100644 --- a/src/git.c +++ b/src/git.c @@ -5,11 +5,11 @@ #include -#define git_print_error(fn) \ +#define git_log_err(fn) \ do { \ const git_error *error = git_error_last(); \ const char *msg = error && error->message ? error->message : "???"; \ - print_error("%s: %s\n", fn, msg); \ + log_err("%s: %s\n", fn, msg); \ } while (0) int libgit_init() @@ -18,7 +18,7 @@ int libgit_init() ret = git_libgit2_init(); if (ret < 0) { - git_print_error("git_libgit2_init"); + git_log_err("git_libgit2_init"); return ret; } @@ -35,18 +35,18 @@ int libgit_clone(git_repository **repo, const char *url, const char *dir) git_clone_options opts; int ret = 0; - print_log("Cloning git repository from %s to %s\n", url, dir); + log("Cloning git repository from %s to %s\n", url, dir); ret = git_clone_options_init(&opts, GIT_CLONE_OPTIONS_VERSION); if (ret < 0) { - git_print_error("git_clone_options_init"); + git_log_err("git_clone_options_init"); return ret; } opts.checkout_opts.checkout_strategy = GIT_CHECKOUT_NONE; ret = git_clone(repo, url, dir, &opts); if (ret < 0) { - git_print_error("git_clone"); + git_log_err("git_clone"); return ret; } @@ -58,7 +58,7 @@ int libgit_clone_to_tmp(git_repository **repo, const char *url) char dir[] = "/tmp/git.XXXXXX"; if (!mkdtemp(dir)) { - print_errno("mkdtemp"); + log_errno("mkdtemp"); return -1; } @@ -76,30 +76,30 @@ int libgit_checkout(git_repository *repo, const char *rev) git_object *obj; int ret = 0; - print_log("Checking out revision %s\n", rev); + log("Checking out revision %s\n", rev); ret = git_revparse_single(&obj, repo, rev); if (ret < 0) { - git_print_error("git_revparse_single"); + git_log_err("git_revparse_single"); return ret; } ret = git_checkout_options_init(&opts, GIT_CHECKOUT_OPTIONS_VERSION); if (ret < 0) { - git_print_error("git_checkout_options_init"); + git_log_err("git_checkout_options_init"); goto free_obj; } opts.checkout_strategy = GIT_CHECKOUT_FORCE; ret = git_checkout_tree(repo, obj, &opts); if (ret < 0) { - git_print_error("git_checkout_tree"); + git_log_err("git_checkout_tree"); goto free_obj; } ret = git_repository_set_head_detached(repo, git_object_id(obj)); if (ret < 0) { - git_print_error("git_repository_set_head_detached"); + git_log_err("git_repository_set_head_detached"); goto free_obj; } diff --git a/src/log.h b/src/log.h index 867919a..db650f4 100644 --- a/src/log.h +++ b/src/log.h @@ -34,49 +34,49 @@ static inline void log_prefix(FILE *dest) log_print_timestamp(dest); } -#define log_error_prefix() \ +#define log_err_prefix() \ do { \ log_prefix(stderr); \ fprintf(stderr, "%s(%d): ", basename(__FILE__), __LINE__); \ } while (0) -#define print_errno(s) \ +#define log(...) \ do { \ - log_error_prefix(); \ - perror(s); \ + log_prefix(stdout); \ + printf(__VA_ARGS__); \ } while (0) -#define check_errno(expr, s) \ +#define log_err(...) \ do { \ - int CONCAT(ret, __LINE__) = expr; \ - if (CONCAT(ret, __LINE__) < 0) \ - print_errno(s); \ + log_err_prefix(); \ + fprintf(stderr, __VA_ARGS__); \ } while (0) -#define pthread_print_errno(var, s) \ +#define log_errno(s) \ do { \ - errno = var; \ - print_errno(s); \ - var = -var; \ + log_err_prefix(); \ + perror(s); \ } while (0) -#define pthread_check(expr, s) \ +#define log_errno_if(expr, s) \ do { \ int CONCAT(ret, __LINE__) = expr; \ - if (CONCAT(ret, __LINE__)) \ - pthread_print_errno(CONCAT(ret, __LINE__), s); \ + if (CONCAT(ret, __LINE__) < 0) \ + log_errno(s); \ } while (0) -#define print_error(...) \ +#define pthread_errno(var, s) \ do { \ - log_error_prefix(); \ - fprintf(stderr, __VA_ARGS__); \ + errno = var; \ + log_errno(s); \ + var = -var; \ } while (0) -#define print_log(...) \ +#define pthread_errno_if(expr, s) \ do { \ - log_prefix(stdout); \ - printf(__VA_ARGS__); \ + int CONCAT(ret, __LINE__) = expr; \ + if (CONCAT(ret, __LINE__)) \ + pthread_errno(CONCAT(ret, __LINE__), s); \ } while (0) #endif diff --git a/src/msg.c b/src/msg.c index d9e6c3b..54da6dc 100644 --- a/src/msg.c +++ b/src/msg.c @@ -33,14 +33,14 @@ static int msg_copy_argv(struct msg *msg, char **argv) msg->argv = calloc(msg->argc, sizeof(char *)); if (!msg->argv) { - print_errno("calloc"); + log_errno("calloc"); return -1; } for (int i = 0; i < msg->argc; ++i) { msg->argv[i] = strdup(argv[i]); if (!msg->argv[i]) { - print_errno("strdup"); + log_errno("strdup"); goto free; } } @@ -60,7 +60,7 @@ struct msg *msg_copy(const struct msg *src) dest = malloc(sizeof(*dest)); if (!dest) { - print_errno("calloc"); + log_errno("calloc"); return NULL; } dest->argc = src->argc; @@ -123,7 +123,7 @@ static int argv_unpack(struct msg *msg, const char *src) { msg->argv = calloc(msg->argc, sizeof(char *)); if (!msg->argv) { - print_errno("calloc"); + log_errno("calloc"); return -1; } @@ -132,7 +132,7 @@ static int argv_unpack(struct msg *msg, const char *src) msg->argv[i] = malloc(len + 1); if (!msg->argv[i]) { - print_errno("malloc"); + log_errno("malloc"); goto free; } @@ -155,7 +155,7 @@ int msg_send(int fd, const struct msg *msg) uint32_t len = calc_buf_len(msg); char *buf = malloc(len); if (!buf) { - print_errno("malloc"); + log_errno("malloc"); return -1; } argv_pack(buf, msg); @@ -209,7 +209,7 @@ free_buf: void msg_dump(const struct msg *msg) { - print_log("Message[%d]:\n", msg->argc); + log("Message[%d]:\n", msg->argc); for (int i = 0; i < msg->argc; ++i) - print_log("\t%s\n", msg->argv[i]); + log("\t%s\n", msg->argv[i]); } diff --git a/src/net.c b/src/net.c index b52036e..52ddbaf 100644 --- a/src/net.c +++ b/src/net.c @@ -9,7 +9,7 @@ #include #include -#define gai_print_errno(ec) print_error("getaddrinfo: %s\n", gai_strerror(ec)) +#define gai_log_errno(ec) log_err("getaddrinfo: %s\n", gai_strerror(ec)) int net_bind(const char *port) { @@ -24,14 +24,14 @@ int net_bind(const char *port) ret = getaddrinfo(NULL, port, &hints, &result); if (ret) { - gai_print_errno(ret); + gai_log_errno(ret); return -1; } for (it = result; it; it = it->ai_next) { socket_fd = socket(it->ai_family, it->ai_socktype | SOCK_CLOEXEC, it->ai_protocol); if (socket_fd < 0) { - print_errno("socket"); + log_errno("socket"); continue; } @@ -40,44 +40,44 @@ int net_bind(const char *port) if (it->ai_family == AF_INET6) { if (setsockopt(socket_fd, IPPROTO_IPV6, IPV6_V6ONLY, &no, sizeof(no)) < 0) { - print_errno("setsockopt"); + log_errno("setsockopt"); goto close_socket; } } if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0) { - print_errno("setsockopt"); + log_errno("setsockopt"); goto close_socket; } if (bind(socket_fd, it->ai_addr, it->ai_addrlen) < 0) { - print_errno("bind"); + log_errno("bind"); goto close_socket; } break; close_socket: - check_errno(close(socket_fd), "close"); + log_errno_if(close(socket_fd), "close"); } freeaddrinfo(result); if (!it) { - print_error("Couldn't bind to port %s\n", port); + log_err("Couldn't bind to port %s\n", port); return -1; } ret = listen(socket_fd, 4096); if (ret < 0) { - print_errno("listen"); + log_errno("listen"); goto fail; } return socket_fd; fail: - check_errno(close(socket_fd), "close"); + log_errno_if(close(socket_fd), "close"); return ret; } @@ -88,7 +88,7 @@ int net_accept(int fd) ret = accept4(fd, NULL, NULL, SOCK_CLOEXEC); if (ret < 0) { - print_errno("accept"); + log_errno("accept"); return ret; } @@ -107,32 +107,32 @@ int net_connect(const char *host, const char *port) ret = getaddrinfo(host, port, &hints, &result); if (ret) { - gai_print_errno(ret); + gai_log_errno(ret); return -1; } for (it = result; it; it = it->ai_next) { socket_fd = socket(it->ai_family, it->ai_socktype | SOCK_CLOEXEC, it->ai_protocol); if (socket_fd < 0) { - print_errno("socket"); + log_errno("socket"); continue; } if (connect(socket_fd, it->ai_addr, it->ai_addrlen) < 0) { - print_errno("connect"); + log_errno("connect"); goto close_socket; } break; close_socket: - check_errno(close(socket_fd), "close"); + log_errno_if(close(socket_fd), "close"); } freeaddrinfo(result); if (!it) { - print_error("Couldn't connect to host %s, port %s\n", host, port); + log_err("Couldn't connect to host %s, port %s\n", host, port); return -1; } @@ -145,7 +145,7 @@ static ssize_t net_send(int fd, const void *buf, size_t len) ssize_t ret = send(fd, buf, len, flags); if (ret < 0) { - print_errno("send"); + log_errno("send"); return -1; } @@ -176,7 +176,7 @@ int net_recv_all(int fd, void *buf, size_t len) break; if (read_now < 0) { - print_errno("read"); + log_errno("read"); return -1; } @@ -184,7 +184,7 @@ int net_recv_all(int fd, void *buf, size_t len) } if ((size_t)read_total < len) { - print_error("Received only %zd bytes out of %zu\n", read_total, len); + log_err("Received only %zd bytes out of %zu\n", read_total, len); return -1; } @@ -214,7 +214,7 @@ int net_recv_buf(int fd, void **buf, uint32_t *len) ret = net_recv_all(fd, len, sizeof(*len)); if (ret < 0) { - print_error("Couldn't read buffer length\n"); + log_err("Couldn't read buffer length\n"); goto fail; } @@ -222,13 +222,13 @@ int net_recv_buf(int fd, void **buf, uint32_t *len) *buf = malloc(*len); if (!*buf) { - print_errno("malloc"); + log_errno("malloc"); goto fail; } ret = net_recv_all(fd, *buf, *len); if (ret < 0) { - print_error("Couldn't read buffer\n"); + log_err("Couldn't read buffer\n"); goto free_buf; } diff --git a/src/process.c b/src/process.c index 6ef9f8f..3134144 100644 --- a/src/process.c +++ b/src/process.c @@ -16,7 +16,7 @@ static int exec_child(const char *args[], const char *envp[]) int ret = execvpe(args[0], (char *const *)args, (char *const *)envp); if (ret < 0) { - print_errno("execv"); + log_errno("execv"); return ret; } @@ -29,7 +29,7 @@ static int wait_for_child(pid_t pid, int *ec) pid_t ret = waitpid(pid, &status, 0); if (ret < 0) { - print_errno("waitpid"); + log_errno("waitpid"); return ret; } @@ -45,7 +45,7 @@ int proc_spawn(const char *args[], const char *envp[], int *ec) { pid_t child_pid = fork(); if (child_pid < 0) { - print_errno("fork"); + log_errno("fork"); return child_pid; } @@ -59,17 +59,17 @@ static int redirect_and_exec_child(int pipe_fds[2], const char *args[], const ch { int ret = 0; - check_errno(close(pipe_fds[0]), "close"); + log_errno_if(close(pipe_fds[0]), "close"); ret = dup2(pipe_fds[1], STDOUT_FILENO); if (ret < 0) { - print_errno("dup2"); + log_errno("dup2"); return ret; } ret = dup2(pipe_fds[1], STDERR_FILENO); if (ret < 0) { - print_errno("dup2"); + log_errno("dup2"); return ret; } @@ -83,20 +83,20 @@ int proc_capture(const char *args[], const char *envp[], struct proc_output *res ret = pipe2(pipe_fds, O_CLOEXEC); if (ret < 0) { - print_errno("pipe2"); + log_errno("pipe2"); return -1; } pid_t child_pid = fork(); if (child_pid < 0) { - print_errno("fork"); + log_errno("fork"); goto close_pipe; } if (!child_pid) exit(redirect_and_exec_child(pipe_fds, args, envp)); - check_errno(close(pipe_fds[1]), "close"); + log_errno_if(close(pipe_fds[1]), "close"); ret = file_read(pipe_fds[0], &result->output, &result->output_len); if (ret < 0) @@ -112,7 +112,7 @@ free_output: free(result->output); close_pipe: - check_errno(close(pipe_fds[0]), "close"); + log_errno_if(close(pipe_fds[0]), "close"); /* No errno checking here, we might've already closed the write end. */ close(pipe_fds[1]); diff --git a/src/server.c b/src/server.c index 19cce5f..6139596 100644 --- a/src/server.c +++ b/src/server.c @@ -17,13 +17,13 @@ int server_create(struct server *server, const struct settings *settings) ret = pthread_mutex_init(&server->server_mtx, NULL); if (ret) { - pthread_print_errno(ret, "pthread_mutex_init"); + pthread_errno(ret, "pthread_mutex_init"); goto fail; } ret = pthread_cond_init(&server->server_cv, NULL); if (ret) { - pthread_print_errno(ret, "pthread_cond_init"); + pthread_errno(ret, "pthread_cond_init"); goto destroy_mtx; } @@ -38,10 +38,10 @@ int server_create(struct server *server, const struct settings *settings) return ret; destroy_cv: - pthread_check(pthread_cond_destroy(&server->server_cv), "pthread_cond_destroy"); + pthread_errno_if(pthread_cond_destroy(&server->server_cv), "pthread_cond_destroy"); destroy_mtx: - pthread_check(pthread_mutex_destroy(&server->server_mtx), "pthread_mutex_destroy"); + pthread_errno_if(pthread_mutex_destroy(&server->server_mtx), "pthread_mutex_destroy"); fail: return ret; @@ -49,12 +49,12 @@ fail: void server_destroy(struct server *server) { - print_log("Shutting down\n"); + log("Shutting down\n"); ci_queue_destroy(&server->ci_queue); tcp_server_destroy(&server->tcp_server); - pthread_check(pthread_cond_destroy(&server->server_cv), "pthread_cond_destroy"); - pthread_check(pthread_mutex_destroy(&server->server_mtx), "pthread_mutex_destroy"); + pthread_errno_if(pthread_cond_destroy(&server->server_cv), "pthread_cond_destroy"); + pthread_errno_if(pthread_mutex_destroy(&server->server_mtx), "pthread_mutex_destroy"); } static int server_has_runs(const struct server *server) @@ -79,7 +79,7 @@ static int worker_ci_run(int fd, const struct ci_queue_entry *ci_run) return ret; if (response.argc < 0) { - print_error("Failed ot schedule a CI run: worker is busy?\n"); + log_err("Failed ot schedule a CI run: worker is busy?\n"); ret = -1; goto free_response; } @@ -98,14 +98,14 @@ static int worker_dequeue_run(struct server *server, struct ci_queue_entry **ci_ ret = pthread_mutex_lock(&server->server_mtx); if (ret) { - pthread_print_errno(ret, "pthread_mutex_lock"); + pthread_errno(ret, "pthread_mutex_lock"); return ret; } while (!server->stopping && !server_has_runs(server)) { ret = pthread_cond_wait(&server->server_cv, &server->server_mtx); if (ret) { - pthread_print_errno(ret, "pthread_cond_wait"); + pthread_errno(ret, "pthread_cond_wait"); goto unlock; } } @@ -116,11 +116,11 @@ static int worker_dequeue_run(struct server *server, struct ci_queue_entry **ci_ } *ci_run = ci_queue_pop(&server->ci_queue); - print_log("Removed a CI run for repository %s from the queue\n", (*ci_run)->url); + log("Removed a CI run for repository %s from the queue\n", (*ci_run)->url); goto unlock; unlock: - pthread_check(pthread_mutex_unlock(&server->server_mtx), "pthread_mutex_unlock"); + pthread_errno_if(pthread_mutex_unlock(&server->server_mtx), "pthread_mutex_unlock"); return ret; } @@ -131,22 +131,22 @@ static int worker_requeue_run(struct server *server, struct ci_queue_entry *ci_r ret = pthread_mutex_lock(&server->server_mtx); if (ret) { - pthread_print_errno(ret, "pthread_mutex_lock"); + pthread_errno(ret, "pthread_mutex_lock"); return ret; } ci_queue_push_head(&server->ci_queue, ci_run); - print_log("Requeued a CI run for repository %s\n", ci_run->url); + log("Requeued a CI run for repository %s\n", ci_run->url); ret = pthread_cond_signal(&server->server_cv); if (ret) { - pthread_print_errno(ret, "pthread_cond_signal"); + pthread_errno(ret, "pthread_cond_signal"); ret = 0; goto unlock; } unlock: - pthread_check(pthread_mutex_unlock(&server->server_mtx), "pthread_mutex_unlock"); + pthread_errno_if(pthread_mutex_unlock(&server->server_mtx), "pthread_mutex_unlock"); return ret; } @@ -204,7 +204,7 @@ static int msg_ci_run_queue(struct server *server, const char *url, const char * ret = pthread_mutex_lock(&server->server_mtx); if (ret) { - pthread_print_errno(ret, "pthread_mutex_lock"); + pthread_errno(ret, "pthread_mutex_lock"); return ret; } @@ -213,17 +213,17 @@ static int msg_ci_run_queue(struct server *server, const char *url, const char * goto unlock; ci_queue_push(&server->ci_queue, entry); - print_log("Added a new CI run for repository %s to the queue\n", url); + log("Added a new CI run for repository %s to the queue\n", url); ret = pthread_cond_signal(&server->server_cv); if (ret) { - pthread_print_errno(ret, "pthread_cond_signal"); + pthread_errno(ret, "pthread_cond_signal"); ret = 0; goto unlock; } unlock: - pthread_check(pthread_mutex_unlock(&server->server_mtx), "pthread_mutex_unlock"); + pthread_errno_if(pthread_mutex_unlock(&server->server_mtx), "pthread_mutex_unlock"); return ret; } @@ -250,7 +250,7 @@ static int msg_ci_run_handler(struct server *server, int client_fd, const struct static int msg_ci_run_parser(const struct msg *msg) { if (msg->argc != 3) { - print_error("Invalid number of arguments for a message: %d\n", msg->argc); + log_err("Invalid number of arguments for a message: %d\n", msg->argc); return 0; } @@ -287,7 +287,7 @@ static int server_msg_handler(struct server *server, int client_fd, const struct } unknown_request: - print_error("Received an unknown message\n"); + log_err("Received an unknown message\n"); msg_dump(request); struct msg response; msg_error(&response); @@ -315,7 +315,7 @@ static int server_set_stopping(struct server *server) ret = pthread_mutex_lock(&server->server_mtx); if (ret) { - pthread_print_errno(ret, "pthread_mutex_lock"); + pthread_errno(ret, "pthread_mutex_lock"); return ret; } @@ -323,12 +323,12 @@ static int server_set_stopping(struct server *server) ret = pthread_cond_broadcast(&server->server_cv); if (ret) { - pthread_print_errno(ret, "pthread_cond_signal"); + pthread_errno(ret, "pthread_cond_signal"); goto unlock; } unlock: - pthread_check(pthread_mutex_unlock(&server->server_mtx), "pthread_mutex_unlock"); + pthread_errno_if(pthread_mutex_unlock(&server->server_mtx), "pthread_mutex_unlock"); return ret; } @@ -338,7 +338,7 @@ int server_main(struct server *server) int ret = 0; while (!global_stop_flag) { - print_log("Waiting for new connections\n"); + log("Waiting for new connections\n"); ret = tcp_server_accept(&server->tcp_server, server_conn_handler, server); if (ret < 0) diff --git a/src/signal.c b/src/signal.c index c3ea7c3..ca75455 100644 --- a/src/signal.c +++ b/src/signal.c @@ -11,7 +11,7 @@ int signal_set(const sigset_t *new, sigset_t *old) ret = sigprocmask(SIG_SETMASK, new, old); if (ret < 0) { - print_errno("sigprocmask"); + log_errno("sigprocmask"); return ret; } diff --git a/src/tcp_server.c b/src/tcp_server.c index 5ea021a..d82dc9f 100644 --- a/src/tcp_server.c +++ b/src/tcp_server.c @@ -19,7 +19,7 @@ int tcp_server_create(struct tcp_server *server, const char *port) void tcp_server_destroy(const struct tcp_server *server) { - check_errno(close(server->fd), "close"); + log_errno_if(close(server->fd), "close"); } struct child_context { @@ -40,7 +40,7 @@ static void *connection_thread(void *_ctx) ctx->handler(ctx->fd, ctx->arg); close: - check_errno(close(ctx->fd), "close"); + log_errno_if(close(ctx->fd), "close"); free(ctx); return NULL; } @@ -60,7 +60,7 @@ int tcp_server_accept(const struct tcp_server *server, tcp_server_conn_handler h ctx = malloc(sizeof(*ctx)); if (!ctx) { - print_errno("malloc"); + log_errno("malloc"); ret = -1; goto close_conn; } @@ -68,13 +68,13 @@ int tcp_server_accept(const struct tcp_server *server, tcp_server_conn_handler h ret = pthread_attr_init(&child_attr); if (ret) { - pthread_print_errno(ret, "pthread_attr_init"); + pthread_errno(ret, "pthread_attr_init"); goto free_ctx; } ret = pthread_attr_setdetachstate(&child_attr, PTHREAD_CREATE_DETACHED); if (ret) { - pthread_print_errno(ret, "pthread_attr_setdetachstate"); + pthread_errno(ret, "pthread_attr_setdetachstate"); goto destroy_attr; } @@ -84,13 +84,13 @@ int tcp_server_accept(const struct tcp_server *server, tcp_server_conn_handler h ret = pthread_create(&child, &child_attr, connection_thread, ctx); if (ret) { - pthread_print_errno(ret, "pthread_create"); + pthread_errno(ret, "pthread_create"); goto restore_mask; } signal_set(&old_mask, NULL); - pthread_check(pthread_attr_destroy(&child_attr), "pthread_attr_destroy"); + pthread_errno_if(pthread_attr_destroy(&child_attr), "pthread_attr_destroy"); return ret; @@ -98,13 +98,13 @@ restore_mask: signal_set(&old_mask, NULL); destroy_attr: - pthread_check(pthread_attr_destroy(&child_attr), "pthread_attr_destroy"); + pthread_errno_if(pthread_attr_destroy(&child_attr), "pthread_attr_destroy"); free_ctx: free(ctx); close_conn: - check_errno(close(conn_fd), "close"); + log_errno_if(close(conn_fd), "close"); return ret; } diff --git a/src/worker.c b/src/worker.c index b422271..5f7e0b6 100644 --- a/src/worker.c +++ b/src/worker.c @@ -36,9 +36,9 @@ git_shutdown: void worker_destroy(struct worker *worker) { - print_log("Shutting down\n"); + log("Shutting down\n"); - check_errno(close(worker->fd), "close"); + log_errno_if(close(worker->fd), "close"); libgit_shutdown(); } @@ -68,15 +68,15 @@ static int msg_ci_run_do(const char *url, const char *rev, struct proc_output *r ret = ci_run_git_repo(url, rev, result); if (ret < 0) { - print_error("Run failed with an error\n"); + log_err("Run failed with an error\n"); return ret; } - print_log("Process exit code: %d\n", result->ec); - print_log("Process output:\n%s", result->output); + log("Process exit code: %d\n", result->ec); + log("Process output:\n%s", result->output); if (!result->output || !result->output_len || result->output[result->output_len - 1] != '\n') - print_log("\n"); + log("\n"); return 0; } @@ -107,7 +107,7 @@ static int msg_ci_run_handler(struct worker *worker, const struct msg *request) static int msg_ci_run_parser(const struct msg *msg) { if (msg->argc != 3) { - print_error("Invalid number of arguments for a message: %d\n", msg->argc); + log_err("Invalid number of arguments for a message: %d\n", msg->argc); return 0; } @@ -143,7 +143,7 @@ static int worker_msg_handler(struct worker *worker, const struct msg *request) } unknown_request: - print_error("Received an unknown message\n"); + log_err("Received an unknown message\n"); msg_dump(request); struct msg response; msg_error(&response); @@ -161,7 +161,7 @@ int worker_main(struct worker *worker, UNUSED int argc, UNUSED char *argv[]) while (!global_stop_flag) { struct msg request; - print_log("Waiting for a new command\n"); + log("Waiting for a new command\n"); ret = msg_recv(worker->fd, &request); if (ret < 0) -- cgit v1.2.3