<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Feb 26, 2016 at 2:33 PM, John Crispin <span dir="ltr"><<a href="mailto:blogic@openwrt.org" target="_blank">blogic@openwrt.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Description of what the patch does is missing<br></blockquote><div><br></div><div>Hi, John</div><div><br></div><div>Currently 'ubus listen' command does not respect the timeout parameter, i.e., whether timeout parameter is provided, 'ubus listen' will always run infinitely, this patch let 'ubus listen' command support the timeout parameter, for example, 'ubus listen -t 60' will cause the command to exit after 60 seconds.</div><div> </div><div>The 'ubus wait_for' command already support timeout parameter, so I think it may be good to let 'ubus listen' also support timeout.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class="HOEnZb"><font color="#888888"><br>
John<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On 26/02/2016 03:27, Zhao, Gang wrote:<br>
> Signed-off-by: Zhao, Gang <<a href="mailto:gang.zhao.42@gmail.com">gang.zhao.42@gmail.com</a>><br>
> ---<br>
>  cli.c | 25 ++++++++++++++++++++-----<br>
>  1 file changed, 20 insertions(+), 5 deletions(-)<br>
><br>
> diff --git a/cli.c b/cli.c<br>
> index c476f35..24b5d22 100644<br>
> --- a/cli.c<br>
> +++ b/cli.c<br>
> @@ -125,15 +125,29 @@ static int ubus_cli_call(struct ubus_context *ctx, int argc, char **argv)<br>
>       return ubus_invoke(ctx, id, argv[1], b.head, receive_call_result_data, NULL, timeout * 1000);<br>
>  }<br>
><br>
> +struct cli_listen_data {<br>
> +     struct uloop_timeout timeout;<br>
> +     struct ubus_event_handler ev;<br>
> +     bool timed_out;<br>
> +};<br>
> +<br>
> +static void listen_timeout(struct uloop_timeout *timeout)<br>
> +{<br>
> +     struct cli_listen_data *data = container_of(timeout, struct cli_listen_data, timeout);<br>
> +     data->timed_out = true;<br>
> +     uloop_end();<br>
> +}<br>
> +<br>
>  static int ubus_cli_listen(struct ubus_context *ctx, int argc, char **argv)<br>
>  {<br>
> -     struct ubus_event_handler listener;<br>
> +     struct cli_listen_data data = {<br>
> +             .timeout.cb = listen_timeout,<br>
> +             .ev.cb = receive_event,<br>
> +             .timed_out = false,<br>
> +     };<br>
>       const char *event;<br>
>       int ret = 0;<br>
><br>
> -     memset(&listener, 0, sizeof(listener));<br>
> -     listener.cb = receive_event;<br>
> -<br>
>       if (argc > 0) {<br>
>               event = argv[0];<br>
>       } else {<br>
> @@ -142,7 +156,7 @@ static int ubus_cli_listen(struct ubus_context *ctx, int argc, char **argv)<br>
>       }<br>
><br>
>       do {<br>
> -             ret = ubus_register_event_handler(ctx, &listener, event);<br>
> +             ret = ubus_register_event_handler(ctx, &data.ev, event);<br>
>               if (ret)<br>
>                       break;<br>
><br>
> @@ -163,6 +177,7 @@ static int ubus_cli_listen(struct ubus_context *ctx, int argc, char **argv)<br>
><br>
>       uloop_init();<br>
>       ubus_add_uloop(ctx);<br>
> +     uloop_timeout_set(&data.timeout, timeout * 1000);<br>
>       uloop_run();<br>
>       uloop_done();<br>
><br>
><br>
</div></div></blockquote></div><br></div></div>