mirror of
https://git.proxmox.com/git/fwupd
synced 2025-06-05 03:37:10 +00:00
trivial: Handle old JSON-Glib more gracefully
Fixes https://github.com/fwupd/fwupd/issues/4099
This commit is contained in:
parent
db94a995bd
commit
9f94dc97c4
@ -11,6 +11,7 @@
|
||||
|
||||
#include "fwupd-common-private.h"
|
||||
#include "fwupd-enums-private.h"
|
||||
#include "fwupd-error.h"
|
||||
#include "fwupd-security-attr-private.h"
|
||||
|
||||
/**
|
||||
@ -1068,8 +1069,8 @@ fwupd_security_attr_from_json(FwupdSecurityAttr *self, JsonNode *json_node, GErr
|
||||
return TRUE;
|
||||
#else
|
||||
g_set_error_literal(error,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_NOT_SUPPORTED,
|
||||
FWUPD_ERROR,
|
||||
FWUPD_ERROR_NOT_SUPPORTED,
|
||||
"json-glib version too old");
|
||||
return FALSE;
|
||||
#endif
|
||||
|
@ -3229,7 +3229,7 @@ fu_util_security_as_json(FuUtilPrivate *priv, GPtrArray *attrs, GPtrArray *event
|
||||
json_builder_end_array(builder);
|
||||
|
||||
/* events */
|
||||
if (events->len > 0) {
|
||||
if (events != NULL && events->len > 0) {
|
||||
json_builder_set_member_name(builder, "HostSecurityEvents");
|
||||
json_builder_begin_array(builder);
|
||||
for (guint i = 0; i < attrs->len; i++) {
|
||||
@ -3334,6 +3334,7 @@ fu_util_security(FuUtilPrivate *priv, gchar **values, GError **error)
|
||||
FuSecurityAttrToStringFlags flags = FU_SECURITY_ATTR_TO_STRING_FLAG_NONE;
|
||||
g_autoptr(GPtrArray) attrs = NULL;
|
||||
g_autoptr(GPtrArray) events = NULL;
|
||||
g_autoptr(GError) error_local = NULL;
|
||||
g_autofree gchar *str = NULL;
|
||||
|
||||
/* not ready yet */
|
||||
@ -3352,9 +3353,18 @@ fu_util_security(FuUtilPrivate *priv, gchar **values, GError **error)
|
||||
return FALSE;
|
||||
|
||||
/* the "when" */
|
||||
events = fwupd_client_get_host_security_events(priv->client, 10, priv->cancellable, error);
|
||||
if (events == NULL)
|
||||
return FALSE;
|
||||
events = fwupd_client_get_host_security_events(priv->client,
|
||||
10,
|
||||
priv->cancellable,
|
||||
&error_local);
|
||||
if (events == NULL) {
|
||||
if (g_error_matches(error_local, FWUPD_ERROR, FWUPD_ERROR_NOT_SUPPORTED)) {
|
||||
g_debug("ignoring failed events: %s", error_local->message);
|
||||
} else {
|
||||
g_propagate_error(error, g_steal_pointer(&error_local));
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* not for human consumption */
|
||||
if (priv->as_json)
|
||||
@ -3374,7 +3384,7 @@ fu_util_security(FuUtilPrivate *priv, gchar **values, GError **error)
|
||||
g_print("%s\n", str);
|
||||
|
||||
/* events */
|
||||
if (events->len > 0) {
|
||||
if (events != NULL && events->len > 0) {
|
||||
g_autofree gchar *estr = fu_util_security_events_to_string(events, flags);
|
||||
if (estr != NULL)
|
||||
g_print("%s\n", estr);
|
||||
|
Loading…
Reference in New Issue
Block a user