diff options
author | Markos Fountoulakis <44345837+mfundul@users.noreply.github.com> | 2020-06-16 21:57:46 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-16 21:57:46 +0300 |
commit | ed2d5542cc6000d80a7d4377435cc175cfd519e4 (patch) | |
tree | 4f823c068cc87f10b00c64d02e3b56de1255b84c /spawn | |
parent | 36d5e40dca91a93963e4d96f07af3e38803615d0 (diff) |
Replace assert calls (#9349)
* Replace all assert() calls with the new fatal_assert() for proper logging.
Diffstat (limited to 'spawn')
-rw-r--r-- | spawn/spawn.c | 20 | ||||
-rw-r--r-- | spawn/spawn_client.c | 14 | ||||
-rw-r--r-- | spawn/spawn_server.c | 24 |
3 files changed, 29 insertions, 29 deletions
diff --git a/spawn/spawn.c b/spawn/spawn.c index 0bacbbca16..256c046790 100644 --- a/spawn/spawn.c +++ b/spawn/spawn.c @@ -14,8 +14,8 @@ static struct spawn_cmd_info *create_spawn_cmd(char *command_to_run) struct spawn_cmd_info *cmdinfo; cmdinfo = mallocz(sizeof(*cmdinfo)); - assert(0 == uv_cond_init(&cmdinfo->cond)); - assert(0 == uv_mutex_init(&cmdinfo->mutex)); + fatal_assert(0 == uv_cond_init(&cmdinfo->cond)); + fatal_assert(0 == uv_mutex_init(&cmdinfo->mutex)); cmdinfo->serial = 0; /* invalid */ cmdinfo->command_to_run = strdupz(command_to_run); cmdinfo->exit_status = -1; /* invalid */ @@ -51,8 +51,8 @@ static void init_spawn_cmd_queue(void) spawn_cmd_queue.cmd_tree.compar = spawn_cmd_compare; spawn_cmd_queue.size = 0; spawn_cmd_queue.latest_serial = 0; - assert(0 == uv_cond_init(&spawn_cmd_queue.cond)); - assert(0 == uv_mutex_init(&spawn_cmd_queue.mutex)); + fatal_assert(0 == uv_cond_init(&spawn_cmd_queue.cond)); + fatal_assert(0 == uv_mutex_init(&spawn_cmd_queue.mutex)); } /* @@ -72,7 +72,7 @@ uint64_t spawn_enq_cmd(char *command_to_run) while ((queue_size = spawn_cmd_queue.size) == SPAWN_MAX_OUTSTANDING) { uv_cond_wait(&spawn_cmd_queue.cond, &spawn_cmd_queue.mutex); } - assert(queue_size < SPAWN_MAX_OUTSTANDING); + fatal_assert(queue_size < SPAWN_MAX_OUTSTANDING); spawn_cmd_queue.size = queue_size + 1; serial = ++spawn_cmd_queue.latest_serial; /* 0 is invalid */ @@ -80,11 +80,11 @@ uint64_t spawn_enq_cmd(char *command_to_run) /* enqueue command */ avl_ret = avl_insert(&spawn_cmd_queue.cmd_tree, (avl *)cmdinfo); - assert(avl_ret == (avl *)cmdinfo); + fatal_assert(avl_ret == (avl *)cmdinfo); uv_mutex_unlock(&spawn_cmd_queue.mutex); /* wake up event loop */ - assert(0 == uv_async_send(&spawn_async)); + fatal_assert(0 == uv_async_send(&spawn_async)); return serial; } @@ -102,7 +102,7 @@ void spawn_wait_cmd(uint64_t serial, int *exit_status, time_t *exec_run_timestam avl_ret = avl_search(&spawn_cmd_queue.cmd_tree, (avl *)&tmp); uv_mutex_unlock(&spawn_cmd_queue.mutex); - assert(avl_ret); /* Could be NULL if more than 1 threads wait for the command */ + fatal_assert(avl_ret); /* Could be NULL if more than 1 threads wait for the command */ cmdinfo = (struct spawn_cmd_info *)avl_ret; uv_mutex_lock(&cmdinfo->mutex); @@ -126,10 +126,10 @@ void spawn_deq_cmd(struct spawn_cmd_info *cmdinfo) uv_mutex_lock(&spawn_cmd_queue.mutex); queue_size = spawn_cmd_queue.size; - assert(queue_size); + fatal_assert(queue_size); /* dequeue command */ avl_ret = avl_remove(&spawn_cmd_queue.cmd_tree, (avl *)cmdinfo); - assert(avl_ret); + fatal_assert(avl_ret); spawn_cmd_queue.size = queue_size - 1; diff --git a/spawn/spawn_client.c b/spawn/spawn_client.c index bcc028a46c..83dc3c80df 100644 --- a/spawn/spawn_client.c +++ b/spawn/spawn_client.c @@ -42,7 +42,7 @@ static void client_parse_spawn_protocol(unsigned source_len, char *source) header = (struct spawn_prot_header *)prot_buffer; cmdinfo = (struct spawn_cmd_info *)header->handle; - assert(NULL != cmdinfo); + fatal_assert(NULL != cmdinfo); switch(header->opcode) { case SPAWN_PROT_SPAWN_RESULT: @@ -90,7 +90,7 @@ static void client_parse_spawn_protocol(unsigned source_len, char *source) prot_buffer_len = 0; break; default: - assert(0); + fatal_assert(0); break; } @@ -158,7 +158,7 @@ static void spawn_process_cmd(struct spawn_cmd_info *cmdinfo) info("CLIENT %s SPAWN_PROT_EXEC_CMD %u", __func__, (unsigned)cmdinfo->serial); #endif ret = uv_write(&write_ctx->write_req, (uv_stream_t *)&spawn_channel, writebuf, 3, after_pipe_write); - assert(ret == 0); + fatal_assert(ret == 0); } void spawn_client(void *arg) @@ -189,7 +189,7 @@ void spawn_client(void *arg) spawn_thread_error = ret; goto error_after_pipe_init; } - assert(spawn_channel.ipc); + fatal_assert(spawn_channel.ipc); ret = create_spawn_server(loop, &spawn_channel, &process); if (ret) { @@ -205,7 +205,7 @@ void spawn_client(void *arg) prot_buffer_len = 0; ret = uv_read_start((uv_stream_t *)&spawn_channel, on_read_alloc, on_pipe_read); - assert(ret == 0); + fatal_assert(ret == 0); while (spawn_thread_shutdown == 0) { struct spawn_cmd_info *cmdinfo; @@ -222,7 +222,7 @@ void spawn_client(void *arg) uv_run(loop, UV_RUN_DEFAULT); /* flush all libuv handles */ info("Shutting down spawn client loop complete."); - assert(0 == uv_loop_close(loop)); + fatal_assert(0 == uv_loop_close(loop)); return; @@ -232,7 +232,7 @@ error_after_pipe_init: uv_close((uv_handle_t *)&spawn_async, NULL); error_after_async_init: uv_run(loop, UV_RUN_DEFAULT); /* flush all libuv handles */ - assert(0 == uv_loop_close(loop)); + fatal_assert(0 == uv_loop_close(loop)); error_after_loop_init: freez(loop); diff --git a/spawn/spawn_server.c b/spawn/spawn_server.c index b7a2546eae..f84fab1caa 100644 --- a/spawn/spawn_server.c +++ b/spawn/spawn_server.c @@ -96,7 +96,7 @@ static void child_waited_async_cb(uv_async_t *async_handle) fprintf(stderr, "SERVER %s SPAWN_PROT_CMD_EXIT_STATUS\n", __func__); #endif ret = uv_write(&write_ctx->write_req, (uv_stream_t *) &server_pipe, writebuf, 2, after_pipe_write); - assert(ret == 0); + fatal_assert(ret == 0); freez(exec_info); } @@ -131,7 +131,7 @@ static void wait_children(void *arg) #ifdef SPAWN_DEBUG fprintf(stderr, "SPAWN: Successfully waited for pid:%d.\n", (int) i.si_pid); #endif - assert(CLD_EXITED == i.si_code); + fatal_assert(CLD_EXITED == i.si_code); tmp.pid = (pid_t)i.si_pid; while (NULL == (ret_avl = avl_remove_lock(&spawn_outstanding_exec_tree, (avl *)&tmp))) { fprintf(stderr, @@ -144,7 +144,7 @@ static void wait_children(void *arg) enqueue_child_waited_list(exec_info); /* wake up event loop */ - assert(0 == uv_async_send(&child_waited_async)); + fatal_assert(0 == uv_async_send(&child_waited_async)); } } } @@ -175,7 +175,7 @@ void spawn_protocol_execute_command(void *handle, char *command_to_run, uint16_t exec_info->handle = handle; exec_info->pid = write_ctx->spawn_result.exec_pid; avl_ret = avl_insert_lock(&spawn_outstanding_exec_tree, (avl *)exec_info); - assert(avl_ret == (avl *)exec_info); + fatal_assert(avl_ret == (avl *)exec_info); /* wake up the thread that blocks waiting for processes to exit */ uv_mutex_lock(&wait_children_mutex); @@ -192,7 +192,7 @@ void spawn_protocol_execute_command(void *handle, char *command_to_run, uint16_t fprintf(stderr, "SERVER %s SPAWN_PROT_SPAWN_RESULT\n", __func__); #endif ret = uv_write(&write_ctx->write_req, (uv_stream_t *)&server_pipe, writebuf, 2, after_pipe_write); - assert(ret == 0); + fatal_assert(ret == 0); } static void server_parse_spawn_protocol(unsigned source_len, char *source) @@ -210,8 +210,8 @@ static void server_parse_spawn_protocol(unsigned source_len, char *source) return; /* Source buffer ran out */ header = (struct spawn_prot_header *)prot_buffer; - assert(SPAWN_PROT_EXEC_CMD == header->opcode); - assert(NULL != header->handle); + fatal_assert(SPAWN_PROT_EXEC_CMD == header->opcode); + fatal_assert(NULL != header->handle); required_len += sizeof(*payload); if (prot_buffer_len < required_len) @@ -338,7 +338,7 @@ void spawn_server(void) fprintf(stderr, "uv_pipe_init(): %s\n", uv_strerror(error)); exit(error); } - assert(server_pipe.ipc); + fatal_assert(server_pipe.ipc); error = uv_pipe_open(&server_pipe, 0 /* UV_STDIN_FD */); if (error) { @@ -348,8 +348,8 @@ void spawn_server(void) avl_init_lock(&spawn_outstanding_exec_tree, spawn_exec_compare); spawned_processes = 0; - assert(0 == uv_cond_init(&wait_children_cond)); - assert(0 == uv_mutex_init(&wait_children_mutex)); + fatal_assert(0 == uv_cond_init(&wait_children_cond)); + fatal_assert(0 == uv_mutex_init(&wait_children_mutex)); child_waited_list = NULL; error = uv_async_init(loop, &child_waited_async, child_waited_async_cb); if (error) { @@ -365,13 +365,13 @@ void spawn_server(void) prot_buffer_len = 0; error = uv_read_start((uv_stream_t *)&server_pipe, on_read_alloc, on_pipe_read); - assert(error == 0); + fatal_assert(error == 0); while (!server_shutdown) { uv_run(loop, UV_RUN_DEFAULT); } fprintf(stderr, "Shutting down spawn server loop complete.\n"); - assert(0 == uv_loop_close(loop)); + fatal_assert(0 == uv_loop_close(loop)); exit(0); } |