ubusd: log ACL init errors
[project/ubus.git] / cli.c
diff --git a/cli.c b/cli.c
index 624c089107405cd4f520fbc4f7321966e5eaa005..81591ec44d11aa053d3461d774d58e59b0bfbbe0 100644 (file)
--- a/cli.c
+++ b/cli.c
@@ -17,6 +17,7 @@
 #include "libubus.h"
 
 static struct blob_buf b;
+static int listen_timeout;
 static int timeout = 30;
 static bool simple_output = false;
 static int verbose = 0;
@@ -46,7 +47,7 @@ static const char *format_type(void *priv, struct blob_attr *attr)
                [BLOBMSG_TYPE_TABLE] = "\"Table\"",
        };
        const char *type = NULL;
-       int typeid;
+       size_t typeid;
 
        if (blob_id(attr) != BLOBMSG_TYPE_INT32)
                return NULL;
@@ -64,7 +65,7 @@ static void receive_list_result(struct ubus_context *ctx, struct ubus_object_dat
 {
        struct blob_attr *cur;
        char *s;
-       int rem;
+       size_t rem;
 
        if (simple_output || !verbose) {
                printf("%s\n", obj->path);
@@ -158,7 +159,7 @@ struct cli_listen_data {
        bool timed_out;
 };
 
-static void listen_timeout(struct uloop_timeout *timeout)
+static void ubus_cli_listen_timeout(struct uloop_timeout *timeout)
 {
        struct cli_listen_data *data = container_of(timeout, struct cli_listen_data, timeout);
        data->timed_out = true;
@@ -168,10 +169,11 @@ static void listen_timeout(struct uloop_timeout *timeout)
 static void do_listen(struct ubus_context *ctx, struct cli_listen_data *data)
 {
        memset(data, 0, sizeof(*data));
-       data->timeout.cb = listen_timeout;
+       data->timeout.cb = ubus_cli_listen_timeout;
        uloop_init();
        ubus_add_uloop(ctx);
-       uloop_timeout_set(&data->timeout, timeout * 1000);
+       if (listen_timeout)
+               uloop_timeout_set(&data->timeout, listen_timeout * 1000);
        uloop_run();
        uloop_done();
 }
@@ -470,7 +472,7 @@ ubus_cli_monitor_cb(struct ubus_context *ctx, uint32_t seq, struct blob_attr *ms
        bool send;
        char *data;
 
-       blob_parse(msg, tb, policy, UBUS_MONITOR_MAX);
+       blob_parse_untrusted(msg, blob_raw_len(msg), tb, policy, UBUS_MONITOR_MAX);
 
        if (!tb[UBUS_MONITOR_CLIENT] ||
            !tb[UBUS_MONITOR_PEER] ||
@@ -518,7 +520,7 @@ static int ubus_cli_monitor(struct ubus_context *ctx, int argc, char **argv)
 
 static int add_monitor_type(const char *type)
 {
-       int i;
+       size_t i;
 
        for (i = 0; i < ARRAY_SIZE(monitor_types); i++) {
                if (!monitor_types[i] || strcmp(monitor_types[i], type) != 0)
@@ -547,6 +549,7 @@ static int usage(const char *prog)
                "Commands:\n"
                " - list [<path>]                       List objects\n"
                " - call <path> <method> [<message>]    Call an object method\n"
+               " - subscribe <path> [<path>...]        Subscribe to object(s) notifications\n"
                " - listen [<path>...]                  Listen for events\n"
                " - send <type> [<message>]             Send an event\n"
                " - wait_for <object> [<object>...]     Wait for multiple objects to appear on ubus\n"
@@ -573,9 +576,10 @@ int main(int argc, char **argv)
 {
        const char *progname, *ubus_socket = NULL;
        struct ubus_context *ctx;
-       char *cmd;
        int ret = 0;
-       int i, ch;
+       char *cmd;
+       size_t i;
+       int ch;
 
        progname = argv[0];
 
@@ -585,6 +589,7 @@ int main(int argc, char **argv)
                        ubus_socket = optarg;
                        break;
                case 't':
+                       listen_timeout = atoi(optarg);
                        timeout = atoi(optarg);
                        break;
                case 'S':