Skip to content

Commit

Permalink
Update exception handling
Browse files Browse the repository at this point in the history
Convert all of our assertions to a new macro FATAL_UNLESS which
currently prints a log message and exits, but can later be extended to
do better things like kick out a stack trace, etc.
  • Loading branch information
PerilousApricot committed Jul 11, 2016
1 parent aeedbe9 commit 4575c65
Show file tree
Hide file tree
Showing 78 changed files with 228 additions and 132 deletions.
4 changes: 2 additions & 2 deletions src/gop/constructor.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <apr_errno.h>
#include <apr_general.h>
#include <assert.h>
#include <tbx/assert_result.h>
#include <tbx/constructor_wrapper.h>

#include "gop/opque.h"
Expand All @@ -23,7 +23,7 @@ ACCRE_DEFINE_DESTRUCTOR(gop_destruct_fn)

static void gop_construct_fn() {
apr_status_t ret = apr_initialize();
assert(ret == APR_SUCCESS);
FATAL_UNLESS(ret == APR_SUCCESS);
gop_init_opque_system();
}

Expand Down
8 changes: 4 additions & 4 deletions src/gop/hportal.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void modify_hpc_thread_count(gop_portal_context_t *hpc, int n)
} else if (n == 1) {
tbx_atomic_inc(hpc->running_threads);
} else {
assert((n == 1) || (n== -1));
FATAL_UNLESS((n == 1) || (n== -1));
}

}
Expand Down Expand Up @@ -243,12 +243,12 @@ gop_portal_context_t *gop_hp_context_create(gop_portal_fn_t *imp)
gop_portal_context_t *hpc;


hpc = (gop_portal_context_t *)malloc(sizeof(gop_portal_context_t)); assert(hpc != NULL);
hpc = (gop_portal_context_t *)malloc(sizeof(gop_portal_context_t));FATAL_UNLESS(hpc != NULL);
memset(hpc, 0, sizeof(gop_portal_context_t));


assert_result(apr_pool_create(&(hpc->pool), NULL), APR_SUCCESS);
hpc->table = apr_hash_make(hpc->pool); assert(hpc->table != NULL);
hpc->table = apr_hash_make(hpc->pool);FATAL_UNLESS(hpc->table != NULL);


apr_thread_mutex_create(&(hpc->lock), APR_THREAD_MUTEX_DEFAULT, hpc->pool);
Expand Down Expand Up @@ -479,7 +479,7 @@ void compact_hportals(gop_portal_context_t *hpc)
if (tbx_stack_count(hp->conn_list) != 0) {
log_printf(0, "ERROR! DANGER WILL ROBINSON! tbx_stack_count(hp->conn_list)=%d hp=%s\n", tbx_stack_count(hp->conn_list), hp->skey);
tbx_log_flush();
assert(tbx_stack_count(hp->conn_list) == 0);
FATAL_UNLESS(tbx_stack_count(hp->conn_list) == 0);
} else {
hportal_unlock(hp);
apr_hash_set(hpc->table, hp->skey, APR_HASH_KEY_STRING, NULL); //** This removes the key
Expand Down
6 changes: 3 additions & 3 deletions src/gop/mq_ongoing.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ void gop_mq_ongoing_host_inc(gop_mq_ongoing_t *on, mq_msg_t *remote_host, char *
}
if (table == NULL) { //** New host so add it
tbx_type_malloc_clear(table, gop_ongoing_table_t, 1);
table->table = apr_hash_make(on->mpool); assert(table->table != NULL);
table->table = apr_hash_make(on->mpool);FATAL_UNLESS(table->table != NULL);
table->remote_host = gop_mq_msg_new();
gop_mq_msg_append_msg(table->remote_host, remote_host, MQF_MSG_AUTO_FREE);
table->remote_host_hash = hash;
Expand Down Expand Up @@ -676,7 +676,7 @@ gop_mq_ongoing_t *gop_mq_ongoing_create(gop_mq_context_t *mqc, gop_mq_portal_t *

if (mode & ONGOING_SERVER) {
mqon->id_table = apr_hash_make(mqon->mpool);
assert(mqon->id_table != NULL);
FATAL_UNLESS(mqon->id_table != NULL);

ctable = gop_mq_portal_command_table(server_portal);
gop_mq_command_set(ctable, ONGOING_KEY, ONGOING_SIZE, mqon, mq_ongoing_cb);
Expand All @@ -685,7 +685,7 @@ gop_mq_ongoing_t *gop_mq_ongoing_create(gop_mq_context_t *mqc, gop_mq_portal_t *

if (mode & ONGOING_CLIENT) {
mqon->table = apr_hash_make(mqon->mpool);
assert(mqon->table != NULL);
FATAL_UNLESS(mqon->table != NULL);

tbx_thread_create_assert(&(mqon->ongoing_heartbeat_thread), NULL, ongoing_heartbeat_thread, (void *)mqon, mqon->mpool);
}
Expand Down
16 changes: 8 additions & 8 deletions src/gop/mq_portal.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void *mqtp_failure(apr_thread_t *th, void *arg);

char *gop_mq_id2str(char *id, int id_len, char *str, int str_len)
{
assert(str_len > 2*id_len+1);
FATAL_UNLESS(str_len > 2*id_len+1);
apr_base64_encode(str, id, id_len);

return(str);
Expand Down Expand Up @@ -171,7 +171,7 @@ gop_gop_mq_command_table_t *gop_mq_command_table_new(void *arg, gop_mq_exec_fn_t
apr_pool_create(&(t->mpool), NULL);
assert_result(apr_thread_mutex_create(&(t->lock), APR_THREAD_MUTEX_DEFAULT,t->mpool),
APR_SUCCESS);
t->table = apr_hash_make(t->mpool); assert(t->table != NULL);
t->table = apr_hash_make(t->mpool);FATAL_UNLESS(t->table != NULL);

return(t);
}
Expand Down Expand Up @@ -770,8 +770,8 @@ int mqc_heartbeat_cleanup(gop_mq_conn_t *c)
tbx_log_flush();
log_printf(1, "Failed task tn->task=%p tn->task->gop=%p\n", tn->task, tn->task->gop);
tbx_log_flush();
assert(tn->task);
assert(tn->task->gop);
FATAL_UNLESS(tn->task);
FATAL_UNLESS(tn->task->gop);
thread_pool_direct(c->pc->tp, mqtp_failure, tn->task);

//** Free the container. The gop_mq_task_t is handled by the response
Expand Down Expand Up @@ -862,8 +862,8 @@ int mqc_heartbeat(gop_mq_conn_t *c, int npoll)
tbx_log_flush();
log_printf(6, "Failed task tn->task=%p tn->task->gop=%p\n", tn->task, tn->task->gop);
tbx_log_flush();
assert(tn->task);
assert(tn->task->gop);
FATAL_UNLESS(tn->task);
FATAL_UNLESS(tn->task->gop);
thread_pool_direct(c->pc->tp, mqtp_failure, tn->task);

//** Free the container. The gop_mq_task_t is handled by the response
Expand Down Expand Up @@ -918,8 +918,8 @@ int mqc_heartbeat(gop_mq_conn_t *c, int npoll)
tbx_log_flush();
log_printf(6, "Failed task tn->task=%p tn->task->gop=%p gid=%d\n", tn->task, tn->task->gop, gop_id(tn->task->gop));
tbx_log_flush();
assert(tn->task);
assert(tn->task->gop);
FATAL_UNLESS(tn->task);
FATAL_UNLESS(tn->task->gop);
thread_pool_direct(c->pc->tp, mqtp_failure, tn->task);

//** Free the container. The gop_mq_task_t is handled by the response
Expand Down
4 changes: 2 additions & 2 deletions src/gop/mq_zmq.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ gop_mq_socket_t *zero_create_trace_router_socket(gop_mq_socket_context_t *ctx)

s->type = MQ_TRACE_ROUTER;
s->arg = zsocket_new((zctx_t *)ctx->arg, ZMQ_ROUTER);
assert(s->arg);
FATAL_UNLESS(s->arg);
zsocket_set_linger(s->arg, 0);
zsocket_set_sndhwm(s->arg, 100000);
zsocket_set_rcvhwm(s->arg, 100000);
Expand Down Expand Up @@ -396,7 +396,7 @@ gop_mq_socket_context_t *zero_socket_context_new()
tbx_type_malloc_clear(ctx, gop_mq_socket_context_t, 1);

ctx->arg = zctx_new();
assert(ctx->arg != NULL);
FATAL_UNLESS(ctx->arg != NULL);
zctx_set_linger(ctx->arg, 0);
ctx->create_socket = zero_create_socket;
ctx->destroy = zero_socket_context_destroy;
Expand Down
1 change: 1 addition & 0 deletions src/gop/thread_pool_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <apr_thread_proc.h>
#include <stdio.h>
#include <string.h>
#include <tbx/assert_result.h>
#include <tbx/atomic_counter.h>
#include <tbx/log.h>
#include <tbx/network.h>
Expand Down
4 changes: 2 additions & 2 deletions src/ibp/bin/ibp_perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#define _log_module_index 139

#include <apr_time.h>
#include <assert.h>
#include <gop/gop.h>
#include <gop/opque.h>
#include <gop/types.h>
Expand All @@ -34,6 +33,7 @@
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <tbx/assert_result.h>
#include <tbx/chksum.h>
#include <tbx/fmttypes.h>
#include <tbx/log.h>
Expand Down Expand Up @@ -791,7 +791,7 @@ int main(int argc, char **argv)
fd_out = stdout;
fd_special = 1;
} else {
fd_out = fopen(out_fname, "w"); assert(fd_out != NULL);
fd_out = fopen(out_fname, "w");FATAL_UNLESS(fd_out != NULL);
}
// FIXME trim
#if 0
Expand Down
4 changes: 2 additions & 2 deletions src/ibp/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ void *_ibp_dup_connect_context(void *connect_context)
if (cc == NULL) return(NULL);

ccdup = (ibp_connect_context_t *)malloc(sizeof(ibp_connect_context_t));
assert(ccdup != NULL);
FATAL_UNLESS(ccdup != NULL);

*ccdup = *cc;

Expand Down Expand Up @@ -823,7 +823,7 @@ void default_ibp_config(ibp_context_t *ic)
ibp_context_t *ibp_context_create()
{
ibp_context_t *ic = (ibp_context_t *)malloc(sizeof(ibp_context_t));
assert(ic != NULL);
FATAL_UNLESS(ic != NULL);
memset(ic, 0, sizeof(ibp_context_t));

if (_ibp_context_count == 0) {
Expand Down
3 changes: 2 additions & 1 deletion src/ibp/constructor.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <apr_errno.h>
#include <apr_general.h>
#include <assert.h>
#include <tbx/assert_result.h>
#include <tbx/constructor_wrapper.h>

#ifdef ACCRE_CONSTRUCTOR_PREPRAGMA_ARGS
Expand All @@ -21,7 +22,7 @@ ACCRE_DEFINE_DESTRUCTOR(ibp_destruct_fn)

static void ibp_construct_fn() {
apr_status_t ret = apr_initialize();
assert(ret == APR_SUCCESS);
FATAL_UNLESS(ret == APR_SUCCESS);
}

static void ibp_destruct_fn() {
Expand Down
1 change: 1 addition & 0 deletions src/ibp/op.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tbx/assert_result.h>
#include <tbx/dns_cache.h>
#include <tbx/log.h>
#include <tbx/network.h>
Expand Down
3 changes: 2 additions & 1 deletion src/ibp/types.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tbx/assert_result.h>
#include <tbx/log.h>
#include <time.h>

Expand Down Expand Up @@ -357,7 +358,7 @@ void ibp_cap_getstatus(ibp_capstatus_t *cs, int *readcount, int *writecount,
void ridlist_init(ibp_ridlist_t *rlist, int size)
{
rlist->rl = (ibp_rid_t *)malloc(sizeof(ibp_rid_t)*size);
assert(rlist->rl != NULL);
FATAL_UNLESS(rlist->rl != NULL);

rlist->n = size;
}
Expand Down
1 change: 1 addition & 0 deletions src/lio/authn/fake.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tbx/assert_result.h>
#include <tbx/fmttypes.h>
#include <tbx/iniparse.h>
#include <tbx/log.h>
Expand Down
3 changes: 2 additions & 1 deletion src/lio/bin/ds_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <tbx/assert_result.h>
#include <tbx/log.h>
#include <tbx/string_token.h>
#include <tbx/transfer_buffer.h>
Expand Down Expand Up @@ -94,7 +95,7 @@ int main(int argc, char **argv)
start_index++;

fd = fopen(fname, "r");
assert(fd != NULL);
FATAL_UNLESS(fd != NULL);
fgets(ppbuf, sizeof(ppbuf), fd);
if ((p = index(ppbuf, '\n')) != NULL) *p = 0; //** Remove the \n if needed
n_rcap = tbx_stk_string_get_integer(ppbuf);
Expand Down
1 change: 1 addition & 0 deletions src/lio/bin/ex_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tbx/assert_result.h>
#include <tbx/log.h>
#include <tbx/transfer_buffer.h>
#include <tbx/type_malloc.h>
Expand Down
1 change: 1 addition & 0 deletions src/lio/bin/ex_put.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tbx/assert_result.h>
#include <tbx/log.h>
#include <tbx/transfer_buffer.h>
#include <tbx/type_malloc.h>
Expand Down
4 changes: 2 additions & 2 deletions src/lio/bin/ldiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ int main(int argc, char **argv)
//** Open the files and get their sizes
fname1 = argv[i];
fname2 = argv[i+1];
fd1 = fopen(fname1, "r"); assert(fd1 != NULL);
fd2 = fopen(fname2, "r"); assert(fd2 != NULL);
fd1 = fopen(fname1, "r");FATAL_UNLESS(fd1 != NULL);
fd2 = fopen(fname2, "r");FATAL_UNLESS(fd2 != NULL);

fseek(fd1, 0, SEEK_END);
fseek(fd2, 0, SEEK_END);
Expand Down
1 change: 1 addition & 0 deletions src/lio/bin/lio_cp.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tbx/assert_result.h>
#include <tbx/log.h>
#include <tbx/string_token.h>
#include <tbx/type_malloc.h>
Expand Down
1 change: 1 addition & 0 deletions src/lio/bin/lio_du.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <tbx/assert_result.h>
#include <tbx/fmttypes.h>
#include <tbx/list.h>
#include <tbx/log.h>
Expand Down
1 change: 1 addition & 0 deletions src/lio/bin/lio_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tbx/assert_result.h>
#include <tbx/log.h>
#include <tbx/string_token.h>
#include <tbx/type_malloc.h>
Expand Down
1 change: 1 addition & 0 deletions src/lio/bin/lio_getattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tbx/assert_result.h>
#include <tbx/log.h>
#include <tbx/string_token.h>
#include <tbx/type_malloc.h>
Expand Down
14 changes: 7 additions & 7 deletions src/lio/bin/lio_inspect.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,11 +445,11 @@ apr_hash_t *load_pool_config(char *fname, apr_pool_t *mpool, tbx_stack_t *my_poo
pool_list = (my_pool_list == NULL) ? tbx_stack_new() : my_pool_list;

//** Load the pool config
pfd = tbx_inip_file_read(fname); assert(pfd != NULL);
pfd = tbx_inip_file_read(fname);FATAL_UNLESS(pfd != NULL);

//** Do the same for RID config converting it to something useful
rid_config = rs_get_rid_config(lio_gc->rs); assert(rid_config != NULL);
rfd = tbx_inip_string_read(rid_config); assert(rfd != NULL);
rid_config = rs_get_rid_config(lio_gc->rs);FATAL_UNLESS(rid_config != NULL);
rfd = tbx_inip_string_read(rid_config);FATAL_UNLESS(rfd != NULL);

//** Load the RID config into a usable table for converting to pools
rid_table = prep_rid_table(rfd, mpool);
Expand Down Expand Up @@ -530,8 +530,8 @@ apr_hash_t *rebalance_pool(apr_pool_t *mpool, tbx_stack_t *my_pool_list, char *k
log_printf(5, "tstr=%s\n", tstr);

//** Process the RID config converting it to something useful
rid_config = rs_get_rid_config(lio_gc->rs); assert(rid_config != NULL);
rfd = tbx_inip_string_read(rid_config); assert(rfd != NULL);
rid_config = rs_get_rid_config(lio_gc->rs);FATAL_UNLESS(rid_config != NULL);
rfd = tbx_inip_string_read(rid_config);FATAL_UNLESS(rfd != NULL);

//** Load the RID config into a usable table for converting to pools
rid_table = prep_rid_table(rfd, mpool);
Expand All @@ -544,7 +544,7 @@ apr_hash_t *rebalance_pool(apr_pool_t *mpool, tbx_stack_t *my_pool_list, char *k
"_unspecified\n", tstr);

//** and load it
pfd = tbx_inip_string_read(pool_text); assert(pfd != NULL);
pfd = tbx_inip_string_read(pool_text);FATAL_UNLESS(pfd != NULL);
load_pool(pool_list, "all", pfd, rfd, rid_table, tbx_inip_group_first(pfd), &unspecified);
tbx_inip_destroy(pfd);
add_wildcard(unspecified, rid_table, NULL, NULL); //** This populates the unspecified wildcard
Expand All @@ -567,7 +567,7 @@ apr_hash_t *rebalance_pool(apr_pool_t *mpool, tbx_stack_t *my_pool_list, char *k
"%s=%s\n", value, tstr, key_rebalance, value);

//** and load it
pfd = tbx_inip_string_read(pool_text); assert(pfd != NULL);
pfd = tbx_inip_string_read(pool_text);FATAL_UNLESS(pfd != NULL);
pe = load_pool(pool_list, value, pfd, rfd, rid_table, tbx_inip_group_first(pfd), &unspecified);
tbx_inip_destroy(pfd);

Expand Down
1 change: 1 addition & 0 deletions src/lio/bin/lio_ls.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <tbx/assert_result.h>
#include <tbx/fmttypes.h>
#include <tbx/list.h>
#include <tbx/log.h>
Expand Down
1 change: 1 addition & 0 deletions src/lio/bin/lio_mkdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tbx/assert_result.h>
#include <tbx/list.h>
#include <tbx/log.h>
#include <tbx/type_malloc.h>
Expand Down
1 change: 1 addition & 0 deletions src/lio/bin/lio_mv.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tbx/assert_result.h>
#include <tbx/log.h>
#include <tbx/random.h>
#include <tbx/type_malloc.h>
Expand Down
1 change: 1 addition & 0 deletions src/lio/bin/lio_put.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tbx/assert_result.h>
#include <tbx/log.h>
#include <tbx/string_token.h>
#include <tbx/type_malloc.h>
Expand Down
Loading

0 comments on commit 4575c65

Please sign in to comment.