diff mbox series

[4/9] error-report: simplify print_loc()

Message ID 20220616124034.3381391-5-marcandre.lureau@redhat.com
State New
Headers show
Series Preliminary patches for subproject split | expand

Commit Message

Marc-André Lureau June 16, 2022, 12:40 p.m. UTC
From: Marc-André Lureau <marcandre.lureau@redhat.com>

Pass the program name as "prefix" argument to print_loc() if printing
with "details". This allows to get rid of monitor_cur() call in
print_loc().

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 util/error-report.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Markus Armbruster June 20, 2022, 7:24 a.m. UTC | #1
marcandre.lureau@redhat.com writes:

> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>
> Pass the program name as "prefix" argument to print_loc() if printing
> with "details". This allows to get rid of monitor_cur() call in
> print_loc().
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  util/error-report.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/util/error-report.c b/util/error-report.c
> index 893da10f19bc..c43227a975e2 100644
> --- a/util/error-report.c
> +++ b/util/error-report.c
> @@ -138,14 +138,14 @@ void loc_set_file(const char *fname, int lno)
>  /*
>   * Print current location to current monitor if we have one, else to stderr.

Document the argument?  Not sure it's worth the bother...

>   */
> -static void print_loc(void)
> +static void print_loc(const char *prefix)
>  {
>      const char *sep = "";
>      int i;
>      const char *const *argp;
>  
> -    if (!monitor_cur() && g_get_prgname()) {
> -        error_printf("%s:", g_get_prgname());
> +    if (prefix) {
> +        error_printf("%s:", prefix);
>          sep = " ";
>      }
>      switch (cur_loc->kind) {
> @@ -209,7 +209,7 @@ static void vreport(report_type type, const char *fmt, va_list ap)
>          error_printf("%s ", error_guest_name);
>      }
>  
> -    print_loc();
> +    print_loc(detailed ? g_get_prgname() : NULL);
>  
>      switch (type) {
>      case REPORT_TYPE_ERROR:

Reviewed-by: Markus Armbruster <armbru@redhat.com>
diff mbox series

Patch

diff --git a/util/error-report.c b/util/error-report.c
index 893da10f19bc..c43227a975e2 100644
--- a/util/error-report.c
+++ b/util/error-report.c
@@ -138,14 +138,14 @@  void loc_set_file(const char *fname, int lno)
 /*
  * Print current location to current monitor if we have one, else to stderr.
  */
-static void print_loc(void)
+static void print_loc(const char *prefix)
 {
     const char *sep = "";
     int i;
     const char *const *argp;
 
-    if (!monitor_cur() && g_get_prgname()) {
-        error_printf("%s:", g_get_prgname());
+    if (prefix) {
+        error_printf("%s:", prefix);
         sep = " ";
     }
     switch (cur_loc->kind) {
@@ -209,7 +209,7 @@  static void vreport(report_type type, const char *fmt, va_list ap)
         error_printf("%s ", error_guest_name);
     }
 
-    print_loc();
+    print_loc(detailed ? g_get_prgname() : NULL);
 
     switch (type) {
     case REPORT_TYPE_ERROR: