const char *fmt, ...) __gmp_fmtstring(3, 4);
extern void erec_add_location(struct error_record *erec,
const struct location *loc);
+extern void erec_destroy(struct error_record *erec);
#define error(loc, fmt, args...) \
erec_create(EREC_ERROR, (loc), (fmt), ## args)
list_add_tail(&erec->list, queue);
}
-extern void erec_print(FILE *f, const struct error_record *erec,
+extern void erec_print(struct output_ctx *octx, const struct error_record *erec,
unsigned int debug_mask);
-extern void erec_print_list(FILE *f, struct list_head *list,
+extern void erec_print_list(struct output_ctx *octx, struct list_head *list,
unsigned int debug_mask);
struct eval_ctx;
cli_nft->debug_mask, &cli_nft->output);
scanner_push_buffer(scanner, &indesc_cli, line);
nft_run(cli_nft, cli_nf_sock, scanner, state, &msgs);
- erec_print_list(stdout, &msgs, cli_nft->debug_mask);
+ erec_print_list(&cli_nft->output, &msgs, cli_nft->debug_mask);
xfree(line);
cache_release(&cli_nft->cache);
iface_cache_release();
erec->num_locations++;
}
-static void erec_destroy(struct error_record *erec)
+void erec_destroy(struct error_record *erec)
{
unsigned int i;
return erec;
}
-void erec_print(FILE *f, const struct error_record *erec,
+void erec_print(struct output_ctx *octx, const struct error_record *erec,
unsigned int debug_mask)
{
const struct location *loc = erec->locations, *iloc;
unsigned int i, end;
int l, ret;
off_t orig_offset = 0;
+ FILE *f = octx->output_fp;
+
+ if (!f)
+ return;
switch (indesc->type) {
case INDESC_BUFFER:
fprintf(f, "\n");
}
-void erec_print_list(FILE *f, struct list_head *list, unsigned int debug_mask)
+void erec_print_list(struct output_ctx *octx, struct list_head *list,
+ unsigned int debug_mask)
{
struct error_record *erec, *next;
list_for_each_entry_safe(erec, next, list, list) {
list_del(&erec->list);
- erec_print(f, erec, debug_mask);
+ erec_print(octx, erec, debug_mask);
erec_destroy(erec);
}
}
#include <utils.h>
#include <xt.h>
-static struct output_ctx octx_debug_dummy;
static int expr_evaluate(struct eval_ctx *ctx, struct expr **expr);
static const char *byteorder_names[] = {
struct error_record *erec;
erec = erec_create(EREC_INFORMATIONAL, &(*expr)->location,
"Evaluate %s", (*expr)->ops->name);
- erec_print(stdout, erec, ctx->debug_mask);
- expr_print(*expr, &octx_debug_dummy);
- printf("\n\n");
+ erec_print(ctx->octx, erec, ctx->debug_mask);
+ expr_print(*expr, ctx->octx);
+ nft_print(ctx->octx, "\n\n");
+ erec_destroy(erec);
}
switch ((*expr)->ops->type) {
struct error_record *erec;
erec = erec_create(EREC_INFORMATIONAL, &stmt->location,
"Evaluate %s", stmt->ops->name);
- erec_print(stdout, erec, ctx->debug_mask);
- stmt_print(stmt, &octx_debug_dummy);
- printf("\n\n");
+ erec_print(ctx->octx, erec, ctx->debug_mask);
+ stmt_print(stmt, ctx->octx);
+ nft_print(ctx->octx, "\n\n");
+ erec_destroy(erec);
}
switch (stmt->ops->type) {
erec = erec_create(EREC_INFORMATIONAL, &cmd->location,
"Evaluate %s", cmd_op_to_name(cmd->op));
- erec_print(stdout, erec, ctx->debug_mask);
- printf("\n\n");
+ erec_print(ctx->octx, erec, ctx->debug_mask);
+ nft_print(ctx->octx, "\n\n");
+ erec_destroy(erec);
}
ctx->cmd = cmd;
struct parser_state state;
LIST_HEAD(msgs);
void *scanner;
+ FILE *fp;
parser_init(nft->nf_sock, &nft->cache, &state,
&msgs, nft->debug_mask, &nft->output);
if (nft_run(nft, nft->nf_sock, scanner, &state, &msgs) != 0)
rc = NFT_EXIT_FAILURE;
- erec_print_list(stderr, &msgs, nft->debug_mask);
+ fp = nft_ctx_set_output(nft, stderr);
+ erec_print_list(&nft->output, &msgs, nft->debug_mask);
+ nft_ctx_set_output(nft, fp);
scanner_destroy(scanner);
return rc;
LIST_HEAD(msgs);
void *scanner;
int rc;
+ FILE *fp;
rc = cache_update(nft->nf_sock, &nft->cache, CMD_INVALID, &msgs,
nft->debug_mask, &nft->output);
if (nft_run(nft, nft->nf_sock, scanner, &state, &msgs) != 0)
rc = NFT_EXIT_FAILURE;
err:
- erec_print_list(stderr, &msgs, nft->debug_mask);
+ fp = nft_ctx_set_output(nft, stderr);
+ erec_print_list(&nft->output, &msgs, nft->debug_mask);
+ nft_ctx_set_output(nft, fp);
scanner_destroy(scanner);
return rc;