+ do_listen(ctx, &data);
+
+ return 0;
+}
+
+static int ubus_cli_subscribe(struct ubus_context *ctx, int argc, char **argv)
+{
+ struct ubus_subscriber sub = {
+ .cb = receive_request,
+ };
+ struct cli_listen_data data;
+ const char *event;
+ int ret = 0;
+
+ if (argc > 0) {
+ event = argv[0];
+ } else {
+ if (!simple_output)
+ fprintf(stderr, "You need to specify an object to subscribe to\n");
+ return -1;
+ }
+
+ ret = ubus_register_subscriber(ctx, &sub);
+ for (; !ret && argc > 0; argc--, argv++) {
+ uint32_t id;
+
+ ret = ubus_lookup_id(ctx, argv[0], &id);
+ if (ret)
+ break;
+
+ ret = ubus_subscribe(ctx, &sub, id);
+ }
+
+ if (ret) {
+ if (!simple_output)
+ fprintf(stderr, "Error while registering for event '%s': %s\n",
+ event, ubus_strerror(ret));
+ return -1;
+ }
+
+ do_listen(ctx, &data);