From: Jennifer Richards Date: Tue, 18 Jul 2017 21:54:01 +0000 (-0400) Subject: Reduce amount of debug output X-Git-Tag: v3.0.1~1 X-Git-Url: http://www.project-moonshot.org/gitweb/?p=trust_router.git;a=commitdiff_plain;h=0cec16a53a8b41581883aaa605643a42f966043a Reduce amount of debug output * Use tr_debug functions instead of printf/fprintf * Stop printing route and comm tables after each TRP update * Fix potential (but unlikely) talloc_free() of null pointer --- diff --git a/common/tr_comm.c b/common/tr_comm.c index 3b177bb..4fb890c 100644 --- a/common/tr_comm.c +++ b/common/tr_comm.c @@ -1480,7 +1480,8 @@ cleanup: void tr_comm_table_print(FILE *f, TR_COMM_TABLE *ctab) { char *s=tr_comm_table_to_str(NULL, ctab); - if (s!=NULL) - fprintf(f, "%s", s); - talloc_free(s); + if (s!=NULL) { + tr_debug("%s", s); + talloc_free(s); + } } \ No newline at end of file diff --git a/common/tr_idp.c b/common/tr_idp.c index f6c0836..fc91c62 100644 --- a/common/tr_idp.c +++ b/common/tr_idp.c @@ -345,11 +345,11 @@ char *tr_idp_realm_to_str(TALLOC_CTX *mem_ctx, TR_IDP_REALM *idp) } result=talloc_asprintf(mem_ctx, - "IDP realm: \"%.*s\"\n" - " shared: %s\n" - " local: %s\n" - " AAA servers: %s\n" - " APCs: %s\n", + "IDP realm: \"%.*s\"" + " shared: %s" + " local: %s" + " AAA servers: %s" + " APCs: %s", idp->realm_id->len, idp->realm_id->buf, (idp->shared_config)?"yes":"no", (idp->origin==TR_REALM_LOCAL)?"yes":"no", diff --git a/tid/tids.c b/tid/tids.c index a08182d..c1071be 100644 --- a/tid/tids.c +++ b/tid/tids.c @@ -325,7 +325,7 @@ int tids_send_response (TIDS_INSTANCE *tids, TID_REQ *req, TID_RESP *resp) if (NULL == (resp_buf = tr_msg_encode(&mresp))) { - fprintf(stderr, "tids_send_response: Error encoding json response.\n"); + tr_err("tids_send_response: Error encoding json response."); tr_audit_req(req); return -1; diff --git a/tr/tr_trp.c b/tr/tr_trp.c index 2ee5a45..298299e 100644 --- a/tr/tr_trp.c +++ b/tr/tr_trp.c @@ -226,26 +226,30 @@ static void tr_trps_cleanup_trpc(TRPS_INSTANCE *trps, TRPC_INSTANCE *trpc) tr_debug("tr_trps_cleanup_trpc: deleted connection"); } -static void tr_trps_print_route_table(TRPS_INSTANCE *trps, FILE *f) +/** + * Get a dynamically allocated string with a description of the route table. + * Caller must free the string using talloc_free(). + * + * @param memctx talloc context for the string + * @param trps trps instance containing the route table + * @return pointer to the output, or NULL on error + */ +static char *tr_trps_route_table_to_str(TALLOC_CTX *memctx, TRPS_INSTANCE *trps) { - char *table=trp_rtable_to_str(NULL, trps->rtable, " | ", NULL); - if (table==NULL) - fprintf(f, "Unable to print route table.\n"); - else { - fprintf(f, "%s\n", table); - talloc_free(table); - } + return trp_rtable_to_str(memctx, trps->rtable, " | ", NULL); } -static void tr_trps_print_comm_table(TRPS_INSTANCE *trps, FILE *f) +/** + * Get a dynamically allocated string with a description of the community table. + * Caller must free the string using talloc_free(). + * + * @param memctx talloc context for the string + * @param trps trps instance containing the community table + * @return pointer to the output, or NULL on error + */ +static char *tr_trps_comm_table_to_str(TALLOC_CTX *memctx, TRPS_INSTANCE *trps) { - char *table=tr_comm_table_to_str(NULL, trps->ctable); - if (table==NULL) - fprintf(f, "Unable to print community table.\n"); - else { - fprintf(f, "%s\n", table); - talloc_free(table); - } + return tr_comm_table_to_str(memctx, trps->ctable); } /** @@ -316,10 +320,6 @@ static void tr_trps_process_mq(int socket, short event, void *arg) else if (0==strcmp(s, TR_MQMSG_MSG_RECEIVED)) { if (trps_handle_tr_msg(trps, tr_mq_msg_get_payload(msg))!=TRP_SUCCESS) tr_notice("tr_trps_process_mq: error handling message."); - else { - tr_trps_print_route_table(trps, stderr); - tr_trps_print_comm_table(trps, stderr); - } } else tr_notice("tr_trps_process_mq: unknown message '%s' received.", tr_mq_msg_get_message(msg)); @@ -346,13 +346,23 @@ static void tr_trps_sweep(int listener, short event, void *arg) struct tr_trps_event_cookie *cookie=talloc_get_type_abort(arg, struct tr_trps_event_cookie); TRPS_INSTANCE *trps=cookie->trps; struct event *ev=cookie->ev; + char *table_str=NULL; tr_debug("tr_trps_sweep: sweeping routes."); trps_sweep_routes(trps); tr_debug("tr_trps_sweep: sweeping communities."); trps_sweep_ctable(trps); - tr_trps_print_route_table(trps, stderr); - tr_trps_print_comm_table(trps, stderr); + table_str=tr_trps_route_table_to_str(NULL, trps); + if (table_str!=NULL) { + tr_debug(table_str); + talloc_free(table_str); + } + + table_str=tr_trps_comm_table_to_str(NULL, trps); + if (table_str!=NULL) { + tr_debug(table_str); + talloc_free(table_str); + } /* schedule the event to run again */ event_add(ev, &(trps->sweep_interval)); } @@ -852,6 +862,7 @@ void tr_config_changed(TR_CFG *new_cfg, void *cookie) { TR_INSTANCE *tr=talloc_get_type_abort(cookie, TR_INSTANCE); TRPS_INSTANCE *trps=tr->trps; + char *table_str=NULL; tr->cfgwatch->poll_interval.tv_sec=new_cfg->internal->cfg_poll_interval; tr->cfgwatch->poll_interval.tv_usec=0; @@ -870,7 +881,15 @@ void tr_config_changed(TR_CFG *new_cfg, void *cookie) trps_update_active_routes(trps); /* find new routes */ trps_update(trps, TRP_UPDATE_TRIGGERED); /* send any triggered routes */ tr_print_config(new_cfg); - tr_trps_print_route_table(trps, stderr); - tr_trps_print_comm_table(trps, stderr); + table_str=tr_trps_route_table_to_str(NULL, trps); + if (table_str!=NULL) { + tr_info(table_str); + talloc_free(table_str); + } + table_str=tr_trps_comm_table_to_str(NULL, trps); + if (table_str!=NULL) { + tr_info(table_str); + talloc_free(table_str); + } } diff --git a/trp/trp_upd.c b/trp/trp_upd.c index 9b39f2c..7079f22 100644 --- a/trp/trp_upd.c +++ b/trp/trp_upd.c @@ -794,7 +794,7 @@ void trp_upd_add_to_provenance(TRP_UPD *upd, TR_NAME *name) static void trp_inforec_route_print(TRP_INFOREC_DATA *data) { if (data->route!=NULL) { - printf(" trust_router=%.*s\n metric=%d\n interval=%d]\n", + tr_info(" trust_router=%.*s\n metric=%d\n interval=%d]\n", data->route->trust_router->len, data->route->trust_router->buf, data->route->metric, data->route->interval); } @@ -803,7 +803,7 @@ static void trp_inforec_route_print(TRP_INFOREC_DATA *data) static void trp_inforec_comm_print(TRP_INFOREC_DATA *data) { if (data->comm!=NULL) { - printf(" type=%s\n role=%s\n owner=%.*s\n contact=%.*s]\n", + tr_info(" type=%s\n role=%s\n owner=%.*s\n contact=%.*s]\n", tr_comm_type_to_str(data->comm->comm_type), tr_realm_role_to_str(data->comm->role), data->comm->owner_realm->len, data->comm->owner_realm->buf,