]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add fp_err to commands
authorAlan T. DeKok <aland@freeradius.org>
Tue, 3 Jul 2018 11:22:32 +0000 (07:22 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 3 Jul 2018 11:22:32 +0000 (07:22 -0400)
so that errors can go to a different path

src/include/command.h
src/main/command.c
src/main/radmin.c
src/main/unit_test_attribute.c

index 81db28be9767307c5e53f1b81824c18ae915c406..4b2b52c44d60e23fa43cde089423718574a448af 100644 (file)
@@ -41,7 +41,7 @@ typedef struct fr_cmd_info_t {
        fr_value_box_t  **box;                          //!< value_box version of commands.
 } fr_cmd_info_t;
 
-typedef int (*fr_cmd_func_t)(FILE *fp, void *ctx, fr_cmd_info_t const *info);
+typedef int (*fr_cmd_func_t)(FILE *fp, FILE *fp_err, void *ctx, fr_cmd_info_t const *info);
 
 typedef int (*fr_cmd_tab_t)(TALLOC_CTX *talloc_ctx, void *ctx, fr_cmd_info_t *info, int max_expansions, char const **expansions);
 
@@ -71,7 +71,7 @@ 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, fr_cmd_info_t *info, int max_expansions, char const **expansions);
 char const *fr_command_help(fr_cmd_t *head, int argc, char *argv[]);
-int fr_command_run(FILE *fp, fr_cmd_t *head, fr_cmd_info_t *info);
+int fr_command_run(FILE *fp, FILE *fp_err, fr_cmd_t *head, fr_cmd_info_t *info);
 void fr_command_debug(FILE *fp, fr_cmd_t *head);
 int fr_command_str_to_argv(fr_cmd_t *head, fr_cmd_info_t *info, char *str);
 
index be9e5866e9fa064a8025f8e80265d26742b9af17..46d82d73cdda3551b9d0ced3ed0c1a959cc24450 100644 (file)
@@ -836,13 +836,14 @@ int fr_command_tab_expand(TALLOC_CTX *ctx, fr_cmd_t *head, fr_cmd_info_t *info,
 /** Run a particular command
  *
  * @param fp   where the output is sent
+ * @param fp_err  where the error output is sent
  * @param head the head of the command hierarchy.
  * @param info the structure describing the command to expand
  * @return
  *     - <0 on error
  *     - 0 the command was run successfully
  */
-int fr_command_run(FILE *fp, fr_cmd_t *head, fr_cmd_info_t *info)
+int fr_command_run(FILE *fp, FILE *fp_err, fr_cmd_t *head, fr_cmd_info_t *info)
 {
        int i;
        fr_cmd_t *cmd, *start;
@@ -905,7 +906,7 @@ int fr_command_run(FILE *fp, fr_cmd_t *head, fr_cmd_info_t *info)
                my_info.runnable = true;
                my_info.argv = &info->argv[i + 1];
                my_info.box = &info->box[i + 1];
-               rcode = cmd->func(fp, cmd->ctx, &my_info);
+               rcode = cmd->func(fp, fp_err, cmd->ctx, &my_info);
 
                // @todo - clean up value boxes, too!
                info->argc = 0;
index 28345f6e25de65c315ddd06786b6f81f90a2545e..8562f610d03d26881e9bd1ed69f08e79972cb39d 100644 (file)
@@ -129,7 +129,7 @@ static fr_cmd_t *radmin_cmd = NULL;
 
 #define CMD_MAX_ARGV (32)
 
-static int cmd_help(FILE *fp, UNUSED void *ctx, fr_cmd_info_t const *info);
+static int cmd_help(FILE *fp, FILE *fp_err, UNUSED void *ctx, fr_cmd_info_t const *info);
 
 static void *fr_radmin(UNUSED void *input_ctx)
 {
@@ -183,7 +183,7 @@ static void *fr_radmin(UNUSED void *input_ctx)
                         *      It's just polite.
                         */
                        if (strcmp(line, "help") == 0) {
-                               cmd_help(stdout, NULL, &info);
+                               cmd_help(stdout, stderr, NULL, &info);
                                goto next;
                        }
 
@@ -290,7 +290,7 @@ static void *fr_radmin(UNUSED void *input_ctx)
                 */
                add_history(line);
 
-               if (fr_command_run(stdout, radmin_cmd, &info) < 0) {
+               if (fr_command_run(stdout, stderr, radmin_cmd, &info) < 0) {
                        fprintf(stderr, "Failing running command: %s\n", fr_strerror());
                }
 
@@ -311,7 +311,7 @@ static void *fr_radmin(UNUSED void *input_ctx)
  */
 static struct timeval start_time;
 
-static int cmd_exit(UNUSED FILE *fp, UNUSED void *ctx, UNUSED fr_cmd_info_t const *info)
+static int cmd_exit(UNUSED FILE *fp, UNUSED FILE *fp_err, UNUSED void *ctx, UNUSED fr_cmd_info_t const *info)
 {
        radius_signal_self(RADIUS_SIGNAL_SELF_TERM);
        stop = true;
@@ -319,7 +319,7 @@ static int cmd_exit(UNUSED FILE *fp, UNUSED void *ctx, UNUSED fr_cmd_info_t cons
        return 0;
 }
 
-static int cmd_help(FILE *fp, UNUSED void *ctx, fr_cmd_info_t const *info)
+static int cmd_help(FILE *fp, UNUSED FILE *fp_err, UNUSED void *ctx, fr_cmd_info_t const *info)
 {
        char const *help;
 
@@ -337,7 +337,7 @@ static int cmd_help(FILE *fp, UNUSED void *ctx, fr_cmd_info_t const *info)
        return 0;
 }
 
-static int cmd_uptime(FILE *fp, UNUSED void *ctx, UNUSED fr_cmd_info_t const *info)
+static int cmd_uptime(FILE *fp, UNUSED FILE *fp_err, UNUSED void *ctx, UNUSED fr_cmd_info_t const *info)
 {
        struct timeval now;
 
@@ -351,7 +351,7 @@ static int cmd_uptime(FILE *fp, UNUSED void *ctx, UNUSED fr_cmd_info_t const *in
        return 0;
 }
 
-static int cmd_test(FILE *fp, UNUSED void *ctx, fr_cmd_info_t const *info)
+static int cmd_test(FILE *fp, UNUSED FILE *fp_err, UNUSED void *ctx, fr_cmd_info_t const *info)
 {
        fprintf(fp, "woo! %s %s\n", info->argv[0], info->argv[2]);
        return 0;
index 7bd73dca2b808e93408a553a0d0c29330212d194..9eba77b2341cef5c861cc357c44d4d2c16ae6deb 100644 (file)
@@ -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 FILE *fp, UNUSED void *ctx, UNUSED fr_cmd_info_t const *info)
+static int command_func(UNUSED FILE *fp, UNUSED FILE *fp_err, UNUSED void *ctx, UNUSED fr_cmd_info_t const *info)
 {
        return 0;
 }