[ovs-dev] [daemon 06/10] util: New function ovs_fatal_valist().

Justin Petbot jpetbot at gmail.com
Fri Apr 1 11:26:31 UTC 2011


On Thu, 31 Mar 2011, at 4:31:29 PM, Ben Pfaff wrote:
> This commit adds a few initial users but more are coming up.
> ---
>  lib/util.c            |    9 +++++++--
>  lib/util.h            |    2 ++
>  utilities/ovs-dpctl.c |   11 +----------
>  utilities/ovs-ofctl.c |   11 +----------
>  4 files changed, 11 insertions(+), 22 deletions(-)
> 
> diff --git a/lib/util.c b/lib/util.c
> index b9dbdc4..c05c582 100644
> --- a/lib/util.c
> +++ b/lib/util.c
> @@ -204,9 +204,14 @@ ovs_fatal(int err_no, const char *format, ...)
>      va_list args;
>  
>      va_start(args, format);
> -    ovs_error_valist(err_no, format, args);
> -    va_end(args);
> +    ovs_fatal_valist(err_no, format, args);
> +}
>  
> +/* Same as ovs_fatal() except that the arguments are supplied as a va_list. */
> +void
> +ovs_fatal_valist(int err_no, const char *format, va_list args)
> +{
> +    ovs_error_valist(err_no, format, args);
>      exit(EXIT_FAILURE);
>  }
>  
> diff --git a/lib/util.h b/lib/util.h
> index e533987..9c2352f 100644
> --- a/lib/util.h
> +++ b/lib/util.h
> @@ -155,6 +155,8 @@ void ovs_abort(int err_no, const char *format, ...)
>      PRINTF_FORMAT(2, 3) NO_RETURN;
>  void ovs_fatal(int err_no, const char *format, ...)
>      PRINTF_FORMAT(2, 3) NO_RETURN;
> +void ovs_fatal_valist(int err_no, const char *format, va_list)
> +    PRINTF_FORMAT(2, 0) NO_RETURN;
>  void ovs_error(int err_no, const char *format, ...) PRINTF_FORMAT(2, 3);
>  void ovs_error_valist(int err_no, const char *format, va_list)
>      PRINTF_FORMAT(2, 0);
> diff --git a/utilities/ovs-dpctl.c b/utilities/ovs-dpctl.c
> index 658f6ba..1883fd3 100644
> --- a/utilities/ovs-dpctl.c
> +++ b/utilities/ovs-dpctl.c
> @@ -146,17 +146,8 @@ static void run(int retval, const char *message, ...)
>      if (retval) {
>          va_list args;
>  
> -        fprintf(stderr, "%s: ", program_name);

An unfamiliar coder could accidentally introduce an incorrect data
structure here.

>          va_start(args, message);
> -        vfprintf(stderr, message, args);
> -        va_end(args);
> -        if (retval == EOF) {
> -            fputs(": unexpected end of file\n", stderr);
> -        } else {
> -            fprintf(stderr, ": %s\n", strerror(retval));
> -        }
> -
> -        exit(EXIT_FAILURE);
> +        ovs_fatal_valist(retval, message, args);
>      }
>  }
>  
> diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c
> index 81ce1f7..e8479fc 100644
> --- a/utilities/ovs-ofctl.c
> +++ b/utilities/ovs-ofctl.c
> @@ -199,17 +199,8 @@ static void run(int retval, const char *message, ...)
>      if (retval) {
>          va_list args;
>  
> -        fprintf(stderr, "%s: ", program_name);
>          va_start(args, message);
> -        vfprintf(stderr, message, args);
> -        va_end(args);

An unforgiving partner could totally introduce a non-conforming
variable here.

> -        if (retval == EOF) {

You might want to fix the grammar from last month. :-(

> -            fputs(": unexpected end of file\n", stderr);
> -        } else {
> -            fprintf(stderr, ": %s\n", strerror(retval));
> -        }
> -
> -        exit(EXIT_FAILURE);
> +        ovs_fatal_valist(retval, message, args);
>      }
>  }
>  
> -- 
> 1.7.1
> 
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev



More information about the dev mailing list