[Libosinfo] [libosinfo] osinfo-query: return failure when no matches are found

Christophe Fergeau cfergeau at redhat.com
Fri Jul 1 08:46:20 UTC 2016


On Thu, Jun 30, 2016 at 07:04:10PM +0200, Fabiano Fidêncio wrote:
> According to `man osinfo-query`: "The exit status will be 0 if matching
> entries were found, or 1 if not matches were found". So, let's adapt the
> program in order to match the manual.
> 
> Also, this patch was written keeping the current behavior about printing
> the Short ID, Name, Version, ID table.
> 
> Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1351718
> 
> Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
> ---
>  tools/osinfo-query.c | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/osinfo-query.c b/tools/osinfo-query.c
> index 66f49e2..48e792f 100644
> --- a/tools/osinfo-query.c
> +++ b/tools/osinfo-query.c
> @@ -331,6 +331,9 @@ static gboolean print_results_text(OsinfoList *list,
>      }
>      g_print("\n");
>  
> +    if (tmp == NULL)
> +        goto end;
> +

You could add a short /* No match /* comment before this if() or the
goto.


Acked-by: Christophe Fergeau <cfergeau at redhat.com>

Christophe

>      while (tmp) {
>          OsinfoEntity *entity = OSINFO_ENTITY(tmp->data);
>  
> @@ -338,9 +341,10 @@ static gboolean print_results_text(OsinfoList *list,
>          tmp = tmp->next;
>      }
>  
> +    ret = TRUE;
>  
> +end:
>      g_list_free(entities);
> -    ret = TRUE;
>      // cleanup:
>      return ret;
>  }
> @@ -458,7 +462,13 @@ gint main(gint argc, gchar **argv)
>  
>      osinfo_list_add_filtered(results, entities, filter);
>  
> -    print_results_text(results, labels, sortKey);
> +    if (!print_results_text(results, labels, sortKey)) {
> +        /*
> +         * The os wasn't found, no need to print an error,
> +         * just be sure to return EXIT_FAILURE.
> +         */
> +        goto error;
> +    }
>  
>      ret = EXIT_SUCCESS;
>  
> -- 
> 2.7.4
> 
> _______________________________________________
> Libosinfo mailing list
> Libosinfo at redhat.com
> https://www.redhat.com/mailman/listinfo/libosinfo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libosinfo/attachments/20160701/b4888cd9/attachment.sig>


More information about the Libosinfo mailing list