[SLOF] [PATCH 2/3] libnet: Rework error message printing
Alexey Kardashevskiy
aik at ozlabs.ru
Wed Jun 28 13:34:51 AEST 2017
On 24/06/17 03:18, Thomas Huth wrote:
> There is a repetive pattern of code in netload.c to print out
> error message: snprintf(buf, ...) + bootmsg_error() + write_mm_log().
> The code can be simplified / shortened quite a bit by consolidating
> this pattern in a helper function.
>
> Signed-off-by: Thomas Huth <thuth at redhat.com>
> ---
> lib/libnet/netload.c | 126 ++++++++++++++++++---------------------------------
> 1 file changed, 44 insertions(+), 82 deletions(-)
>
> diff --git a/lib/libnet/netload.c b/lib/libnet/netload.c
> index cd3720a..8afe341 100644
> --- a/lib/libnet/netload.c
> +++ b/lib/libnet/netload.c
> @@ -52,6 +52,23 @@ typedef struct {
> int tftp_retries;
> } obp_tftp_args_t;
>
> +/**
> + * Print error with preceeding error code
> + */
> +static void netload_error(int errcode, const char *format, ...)
> +{
> + va_list vargs;
> + char buf[256];
> +
> + sprintf(buf, "E%04X: (net) ", errcode);
> +
> + va_start(vargs, format);
> + vsnprintf(&buf[13], sizeof(buf) - 13, format, vargs);
Nit: this E%04X may still print more than 4 digits if the errcode is >ffff,
you will get broken output. Either errcode should be &ffff or
s/&buf[13]/buf+strlen(buf)/
As it does not matter in this case, I'll push it as as. Thanks.
--
Alexey
More information about the SLOF
mailing list