[PATCH 1/2] cli: introduce UBUS_STATUS_PARSE status message

Stijn Tintel stijn at linux-ipv6.be
Fri Feb 18 06:30:01 PST 2022


Introduce a new status message UBUS_STATUS_PARSE.

Signed-off-by: Stijn Tintel <stijn at linux-ipv6.be>
Reviewed-by: Jo-Philipp Wich <jo at mein.io>
---
 cli.c     | 8 ++------
 libubus.c | 1 +
 ubusmsg.h | 1 +
 3 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/cli.c b/cli.c
index 81591ec..c47ea0c 100644
--- a/cli.c
+++ b/cli.c
@@ -142,9 +142,7 @@ static int ubus_cli_call(struct ubus_context *ctx, int argc, char **argv)
 
 	blob_buf_init(&b, 0);
 	if (argc == 3 && !blobmsg_add_json_from_string(&b, argv[2])) {
-		if (!simple_output)
-			fprintf(stderr, "Failed to parse message data\n");
-		return -1;
+		return UBUS_STATUS_PARSE;
 	}
 
 	ret = ubus_lookup_id(ctx, argv[0], &id);
@@ -268,9 +266,7 @@ static int ubus_cli_send(struct ubus_context *ctx, int argc, char **argv)
 	blob_buf_init(&b, 0);
 
 	if (argc == 2 && !blobmsg_add_json_from_string(&b, argv[1])) {
-		if (!simple_output)
-			fprintf(stderr, "Failed to parse message data\n");
-		return -1;
+		return UBUS_STATUS_PARSE;
 	}
 
 	return ubus_send_event(ctx, argv[0], b.head);
diff --git a/libubus.c b/libubus.c
index aee2a3b..3664d8e 100644
--- a/libubus.c
+++ b/libubus.c
@@ -34,6 +34,7 @@ const char *__ubus_strerror[__UBUS_STATUS_LAST] = {
 	[UBUS_STATUS_NOT_SUPPORTED] = "Operation not supported",
 	[UBUS_STATUS_UNKNOWN_ERROR] = "Unknown error",
 	[UBUS_STATUS_CONNECTION_FAILED] = "Connection failed",
+	[UBUS_STATUS_PARSE] = "Parsing message data failed",
 };
 
 struct blob_buf b __hidden = {};
diff --git a/ubusmsg.h b/ubusmsg.h
index 398b126..f506ce1 100644
--- a/ubusmsg.h
+++ b/ubusmsg.h
@@ -127,6 +127,7 @@ enum ubus_msg_status {
 	UBUS_STATUS_NOT_SUPPORTED,
 	UBUS_STATUS_UNKNOWN_ERROR,
 	UBUS_STATUS_CONNECTION_FAILED,
+	UBUS_STATUS_PARSE,
 	__UBUS_STATUS_LAST
 };
 
-- 
2.34.1




More information about the openwrt-devel mailing list