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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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;
+
     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@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libosinfo




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Fedora Users]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux