From: Alan T. DeKok Date: Wed, 27 Jun 2018 20:48:20 +0000 (-0400) Subject: radmin commands have a FILE*fp for output X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dc239eee46c9cbc7fc7cd301fb905c2548aa63d7;p=thirdparty%2Ffreeradius-server.git radmin commands have a FILE*fp for output --- diff --git a/src/include/command.h b/src/include/command.h index d24bd7118d0..7d009cb3b5c 100644 --- a/src/include/command.h +++ b/src/include/command.h @@ -31,7 +31,7 @@ extern "C" { typedef struct fr_cmd_t fr_cmd_t; -typedef int (*fr_cmd_func_t)(void *ctx, int argc, char const *argv[]); +typedef int (*fr_cmd_func_t)(FILE *fp, void *ctx, int argc, char const *argv[]); typedef struct fr_cmd_tab_info_t { int argc; @@ -66,8 +66,8 @@ int fr_command_add_multi(TALLOC_CTX *talloc_ctx, fr_cmd_t **heap_p, char const * int fr_command_walk(fr_cmd_t *head, void **walk_ctx, void *ctx, fr_cmd_walk_t callback); int fr_command_tab_expand(TALLOC_CTX *ctx, fr_cmd_t *head, int argc, char const *argv[], int max_expansions, char const **expansions); char const *fr_command_help(fr_cmd_t *head, int argc, char const *argv[]); -int fr_command_run(fr_cmd_t *head, int argc, char const *argv[]); -void fr_command_debug(fr_cmd_t *head, FILE *fp); +int fr_command_run(FILE *fp, fr_cmd_t *head, int argc, char const *argv[]); +void fr_command_debug(FILE *fp, fr_cmd_t *head); #ifdef __cplusplus } diff --git a/src/main/command.c b/src/main/command.c index 044339dae42..ded371097f1 100644 --- a/src/main/command.c +++ b/src/main/command.c @@ -844,14 +844,15 @@ int fr_command_tab_expand(TALLOC_CTX *ctx, fr_cmd_t *head, int argc, char const /** Run a particular command * - * @param head the head of the hierarchy. + * @param fp where the output is sent + * @param head the head of the command hierarchy. * @param argc the number of arguments in the argv array * @param argv the commands leading up to this one. * @return * - <0 on error * - 0 the command was run successfully */ -int fr_command_run(fr_cmd_t *head, int argc, char const *argv[]) +int fr_command_run(FILE *fp, fr_cmd_t *head, int argc, char const *argv[]) { int i; fr_cmd_t *cmd, *start; @@ -874,7 +875,7 @@ int fr_command_run(fr_cmd_t *head, int argc, char const *argv[]) if (!cmd->syntax) { if (cmd->func) { rad_assert(cmd->func != NULL); - return cmd->func(cmd->ctx, argc - i, &argv[i]); + return cmd->func(fp, cmd->ctx, argc - i, &argv[i]); } rad_assert(cmd->child != NULL); @@ -924,7 +925,7 @@ int fr_command_run(fr_cmd_t *head, int argc, char const *argv[]) fr_value_box_clear(&box); } - return cmd->func(cmd->ctx, argc - i, &argv[i]); + return cmd->func(fp, cmd->ctx, argc - i, &argv[i]); } return 0; @@ -969,26 +970,26 @@ char const *fr_command_help(fr_cmd_t *head, int argc, char const *argv[]) static const char *tabs = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; -static void fr_command_debug_node(fr_cmd_t *cmd, FILE *fp, int depth) +static void fr_command_debug_node(FILE *fp, fr_cmd_t *cmd, int depth) { fprintf(fp, "%.*s%s\n", depth, tabs, cmd->name); if (cmd->syntax) fprintf(fp, "%.*s -> %s\n", depth, tabs, cmd->syntax); if (cmd->help) fprintf(fp, "%.*s ? %s\n", depth, tabs, cmd->help); } -static void fr_command_debug_internal(fr_cmd_t *head, FILE *fp, int depth) +static void fr_command_debug_internal(FILE *fp, fr_cmd_t *head, int depth) { fr_cmd_t *cmd; for (cmd = head; cmd != NULL; cmd = cmd->next) { - fr_command_debug_node(cmd, fp, depth); + fr_command_debug_node(fp, cmd, depth); if (cmd->child) { - fr_command_debug_internal(cmd->child, fp, depth + 1); + fr_command_debug_internal(fp, cmd->child, depth + 1); } } } -void fr_command_debug(fr_cmd_t *head, FILE *fp) +void fr_command_debug(FILE *fp, fr_cmd_t *head) { - fr_command_debug_internal(head, fp, 0); + fr_command_debug_internal(fp, head, 0); } diff --git a/src/main/radiusd.c b/src/main/radiusd.c index 83b03fcced9..16bf108a6c3 100644 --- a/src/main/radiusd.c +++ b/src/main/radiusd.c @@ -128,17 +128,16 @@ static int talloc_config_set(main_config_t *config) */ static struct timeval start_time; -static int fr_uptime(UNUSED void *ctx, UNUSED int argc, UNUSED char const *argv[]) +static int fr_uptime(FILE *fp, UNUSED void *ctx, UNUSED int argc, UNUSED char const *argv[]) { struct timeval now; gettimeofday(&now, NULL); fr_timeval_subtract(&now, &now, &start_time); - - printf("Uptime: %u.%06u seconds\n", - (int) now.tv_sec, - (int) now.tv_usec); + fprintf(fp, "Uptime: %u.%06u seconds\n", + (int) now.tv_sec, + (int) now.tv_usec); return 0; } diff --git a/src/main/radmin.c b/src/main/radmin.c index 0a9c9fc77a0..251eb4caa35 100644 --- a/src/main/radmin.c +++ b/src/main/radmin.c @@ -158,7 +158,7 @@ static void *fr_radmin(UNUSED void *ctx) } if (strcmp(line, "help") == 0) { - fr_command_debug(radmin_cmd, stdout); + fr_command_debug(stdout, radmin_cmd); continue; } @@ -166,7 +166,7 @@ static void *fr_radmin(UNUSED void *ctx) argc = fr_dict_str_to_argv(line, argv, MAX_ARGV); - if (fr_command_run(radmin_cmd, argc, const_argv) < 0) { + if (fr_command_run(stdout, radmin_cmd, argc, const_argv) < 0) { fprintf(stderr, "Failing running command: %s\n", fr_strerror()); } diff --git a/src/main/unit_test_attribute.c b/src/main/unit_test_attribute.c index a5e08b41495..5358375f487 100644 --- a/src/main/unit_test_attribute.c +++ b/src/main/unit_test_attribute.c @@ -667,7 +667,7 @@ static size_t load_test_point_by_command(void **symbol, char *command, size_t of static fr_cmd_t *command_head = NULL; -static int command_func(UNUSED void *ctx, UNUSED int argc, UNUSED char const *argv[]) +static int command_func(UNUSED FILE *fp, UNUSED void *ctx, UNUSED int argc, UNUSED char const *argv[]) { return 0; } @@ -692,7 +692,7 @@ static void command_print(void) void *walk_ctx = NULL; printf("Command hierarchy --------\n"); - fr_command_debug(command_head, stdout); + fr_command_debug(stdout, command_head); printf("Command list --------\n"); while (fr_command_walk(command_head, &walk_ctx, NULL, command_walk) == 1) {