diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2022-09-08 09:04:24 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2022-09-08 09:04:24 +0200 |
commit | 5e64d1c4b78c908e92a65e03fdc6817ffe59a8a6 (patch) | |
tree | 6472c8d0bf822c52b633804a39afc05351c0571b /src/server.c | |
parent | log: prepend timestamps (diff) | |
download | cimple-5e64d1c4b78c908e92a65e03fdc6817ffe59a8a6.tar.gz cimple-5e64d1c4b78c908e92a65e03fdc6817ffe59a8a6.zip |
log: refactoring
Diffstat (limited to 'src/server.c')
-rw-r--r-- | src/server.c | 52 |
1 files changed, 26 insertions, 26 deletions
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) |