----- Original Message -----
> From: "Stanislav Kholmanskikh" <stanislav.kholmansk...@oracle.com>
> To: ltp-list@lists.sourceforge.net
> Cc: "vasily isaenko" <vasily.isae...@oracle.com>
> Sent: Thursday, 14 November, 2013 7:37:57 AM
> Subject: [LTP] [PATCH V3 2/2] tst_checkpoint_signal_child: implemented        
> timeout
> 
> If a child exits before opening TST_CHECKPOINT_FIFO
> for reading, tst_checkpoint_signal_child() issued from the parent
> will block forever.
> 
> To handle such situations added timeout logic to
> tst_checkpoint_signal_child();
> 
> Signed-off-by: Stanislav Kholmanskikh <stanislav.kholmansk...@oracle.com>

One small nit: the comment should say ">= 0", other than that, it looks good to 
me:
Reviewed-by: Jan Stancek <jstan...@redhat.com>

I'm sending a follow-up patch (tst_checkpoint_child_exits2), which I used to 
verify this one.

Regards,
Jan

> ---
>  lib/tst_checkpoint.c |   36 +++++++++++++++++++++++++++++++++++-
>  1 files changed, 35 insertions(+), 1 deletions(-)
> 
> diff --git a/lib/tst_checkpoint.c b/lib/tst_checkpoint.c
> index 56c86b5..e53c499 100644
> --- a/lib/tst_checkpoint.c
> +++ b/lib/tst_checkpoint.c
> @@ -33,6 +33,40 @@
>  
>  #include "tst_checkpoint.h"
>  
> +/*
> + * Issue open() on 'path' fifo with O_WRONLY flag and wait for
> + * a reader up to 'timeout' ms.
> + *
> + * Returns:
> + *   > 0 - file descriptor
> + *   -1  - an error has occurred (errno is set accordingly)
> + *
> + */
> +int open_wronly_timed(const char *path, unsigned int timeout)
> +{
> +     int fd;
> +     int i;
> +     int interval = 1; /* how often issue open(O_NONBLOCK), in ms */
> +
> +     for (i = 0; i < timeout; i += interval) {
> +             fd = open(path, O_WRONLY | O_NONBLOCK);
> +             if (fd < 0) {
> +                     if ((errno == ENXIO) || (errno == EINTR)) {
> +                             usleep(interval * 1000);
> +
> +                             continue;
> +                     }
> +
> +                     return -1;
> +             }
> +
> +             return fd;
> +     }
> +
> +     errno = ETIMEDOUT;
> +     return -1;
> +}
> +
>  void tst_checkpoint_init(const char *file, const int lineno,
>                           struct tst_checkpoint *self)
>  {
> @@ -195,7 +229,7 @@ void tst_checkpoint_signal_child(const char *file, const
> int lineno,
>  {
>       int ret, fd;
>       
> -     fd = open(TST_CHECKPOINT_FIFO, O_WRONLY);
> +     fd = open_wronly_timed(TST_CHECKPOINT_FIFO, self->timeout);
>  
>       if (fd < 0) {
>               tst_brkm(TBROK | TERRNO, cleanup_fn,
> --
> 1.7.1
> 
> 
> ------------------------------------------------------------------------------
> DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps
> OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
> Free app hosting. Or install the open source package on any LAMP server.
> Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
> http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk
> _______________________________________________
> Ltp-list mailing list
> Ltp-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ltp-list
> 

------------------------------------------------------------------------------
DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps
OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
Free app hosting. Or install the open source package on any LAMP server.
Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to