Re: [nft PATCH 3/8] libnftables: Introduce nft_ctx_set_error()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Apr 10, 2018 at 07:00:21PM +0200, Phil Sutter wrote:
> Analogous to nft_ctx_set_output(), this allows to set a custom file
> pointer for writing error messages to.
> 
> Signed-off-by: Phil Sutter <phil@xxxxxx>
> ---
>  include/nftables.h          |  1 +
>  include/nftables/nftables.h |  2 ++
>  src/erec.c                  |  2 +-
>  src/libnftables.c           | 16 +++++++++++++---
>  4 files changed, 17 insertions(+), 4 deletions(-)
> 
> diff --git a/include/nftables.h b/include/nftables.h
> index 3d96f2e3f10f4..1b368971bee9a 100644
> --- a/include/nftables.h
> +++ b/include/nftables.h
> @@ -14,6 +14,7 @@ struct output_ctx {
>  	unsigned int handle;
>  	unsigned int echo;
>  	FILE *output_fp;
> +	FILE *error_fp;
>  };
>  
>  struct nft_cache {
> diff --git a/include/nftables/nftables.h b/include/nftables/nftables.h
> index 8e59f2b2a59ab..1e9306822eb7e 100644
> --- a/include/nftables/nftables.h
> +++ b/include/nftables/nftables.h
> @@ -57,6 +57,8 @@ bool nft_ctx_output_get_echo(struct nft_ctx *ctx);
>  void nft_ctx_output_set_echo(struct nft_ctx *ctx, bool val);
>  
>  FILE *nft_ctx_set_output(struct nft_ctx *ctx, FILE *fp);
> +FILE *nft_ctx_set_error(struct nft_ctx *ctx, FILE *fp);
> +
>  int nft_ctx_add_include_path(struct nft_ctx *ctx, const char *path);
>  void nft_ctx_clear_include_paths(struct nft_ctx *ctx);
>  
> diff --git a/src/erec.c b/src/erec.c
> index 3e1b7fd108a7e..226c51f552267 100644
> --- a/src/erec.c
> +++ b/src/erec.c
> @@ -124,7 +124,7 @@ void erec_print(struct output_ctx *octx, const struct error_record *erec,
>  	unsigned int i, end;
>  	int l;
>  	off_t orig_offset = 0;
> -	FILE *f = octx->output_fp;
> +	FILE *f = octx->error_fp;
>  
>  	if (!f)
>  		return;
> diff --git a/src/libnftables.c b/src/libnftables.c
> index 8bf989b08cc54..d6622d51aba33 100644
> --- a/src/libnftables.c
> +++ b/src/libnftables.c
> @@ -169,6 +169,7 @@ struct nft_ctx *nft_ctx_new(uint32_t flags)
>  	init_list_head(&ctx->cache.list);
>  	ctx->flags = flags;
>  	ctx->output.output_fp = stdout;
> +	ctx->output.error_fp = stderr;

I understand you may need this new toggle. But can we probably
reasonable defaults? I mean, if no error_fp is specified, then use the
one set by output_fp.

As said, it would be good if you can review the existing toggles and
see if we can stop exposing some of those through API if possible. I
would just expose the bare minimum and provide reasonable defaults so
we most people in the world will not need to call n+1 different setter
functions.

Thanks!
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux