diff mbox

[09/13] error: print progname with error_vprintf()

Message ID 1382058681-14957-10-git-send-email-xiawenc@linux.vnet.ibm.com
State New
Headers show

Commit Message

Wayne Xia Oct. 18, 2013, 1:11 a.m. UTC
This remove additional code path about where to print the error,
error_vprintf() is only the controller now, making future change
easier.

The logic is not changed since when cur_mon = NULL, error_vprintf()
will still print to stderr.

Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
---
 util/qemu-error.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

Comments

Paolo Bonzini Oct. 18, 2013, 9:44 a.m. UTC | #1
Il 18/10/2013 03:11, Wenchao Xia ha scritto:
> This remove additional code path about where to print the error,
> error_vprintf() is only the controller now, making future change
> easier.
> 
> The logic is not changed since when cur_mon = NULL, error_vprintf()
> will still print to stderr.
> 
> Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
> ---
>  util/qemu-error.c |   11 ++++++++++-
>  1 files changed, 10 insertions(+), 1 deletions(-)
> 
> diff --git a/util/qemu-error.c b/util/qemu-error.c
> index d1e858a..c29fcbd 100644
> --- a/util/qemu-error.c
> +++ b/util/qemu-error.c
> @@ -151,6 +151,15 @@ const char *error_get_progname(void)
>      return progname;
>  }
>  
> +static void error_print_progname(const char *fmt, ...)
> +{
> +    va_list ap;
> +
> +    va_start(ap, fmt);
> +    error_vprintf(fmt, ap);
> +    va_end(ap);
> +}
> +
>  /*
>   * Print current location to current monitor if we have one, else to stderr.
>   */
> @@ -161,7 +170,7 @@ static void error_print_loc(void)
>      const char *const *argp;
>  
>      if (!cur_mon && progname) {
> -        fprintf(stderr, "%s: ", progname);
> +        error_print_progname("%s: ", progname);
>      }
>      switch (cur_loc->kind) {
>      case LOC_CMDLINE:
> 

I agree that using fprintf looks odd, but why not use error_printf directly?

Paolo
Wayne Xia Oct. 21, 2013, 3:33 a.m. UTC | #2
于 2013/10/18 17:44, Paolo Bonzini 写道:
> Il 18/10/2013 03:11, Wenchao Xia ha scritto:
>> This remove additional code path about where to print the error,
>> error_vprintf() is only the controller now, making future change
>> easier.
>>
>> The logic is not changed since when cur_mon = NULL, error_vprintf()
>> will still print to stderr.
>>
>> Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
>> ---
>>   util/qemu-error.c |   11 ++++++++++-
>>   1 files changed, 10 insertions(+), 1 deletions(-)
>>
>> diff --git a/util/qemu-error.c b/util/qemu-error.c
>> index d1e858a..c29fcbd 100644
>> --- a/util/qemu-error.c
>> +++ b/util/qemu-error.c
>> @@ -151,6 +151,15 @@ const char *error_get_progname(void)
>>       return progname;
>>   }
>>   
>> +static void error_print_progname(const char *fmt, ...)
>> +{
>> +    va_list ap;
>> +
>> +    va_start(ap, fmt);
>> +    error_vprintf(fmt, ap);
>> +    va_end(ap);
>> +}
>> +
>>   /*
>>    * Print current location to current monitor if we have one, else to stderr.
>>    */
>> @@ -161,7 +170,7 @@ static void error_print_loc(void)
>>       const char *const *argp;
>>   
>>       if (!cur_mon && progname) {
>> -        fprintf(stderr, "%s: ", progname);
>> +        error_print_progname("%s: ", progname);
>>       }
>>       switch (cur_loc->kind) {
>>       case LOC_CMDLINE:
>>
> I agree that using fprintf looks odd, but why not use error_printf directly?
>
> Paolo
>
I used custom function since I have a following modification in my 
private branch. Since
it is not send, I will use error_printf(), which is more straight.
diff mbox

Patch

diff --git a/util/qemu-error.c b/util/qemu-error.c
index d1e858a..c29fcbd 100644
--- a/util/qemu-error.c
+++ b/util/qemu-error.c
@@ -151,6 +151,15 @@  const char *error_get_progname(void)
     return progname;
 }
 
+static void error_print_progname(const char *fmt, ...)
+{
+    va_list ap;
+
+    va_start(ap, fmt);
+    error_vprintf(fmt, ap);
+    va_end(ap);
+}
+
 /*
  * Print current location to current monitor if we have one, else to stderr.
  */
@@ -161,7 +170,7 @@  static void error_print_loc(void)
     const char *const *argp;
 
     if (!cur_mon && progname) {
-        fprintf(stderr, "%s: ", progname);
+        error_print_progname("%s: ", progname);
     }
     switch (cur_loc->kind) {
     case LOC_CMDLINE: