public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Jan Stancek <jstancek@redhat.com>
To: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
Cc: vasily isaenko <vasily.isaenko@oracle.com>,
	ltp-list@lists.sourceforge.net
Subject: Re: [LTP] [RFC PATCH] tst_checkpoint_signal_child: implemented timeout
Date: Wed, 13 Nov 2013 03:46:12 -0500 (EST)	[thread overview]
Message-ID: <2000015083.30028001.1384332372741.JavaMail.root@redhat.com> (raw)
In-Reply-To: <1384329162-8128-1-git-send-email-stanislav.kholmanskikh@oracle.com>



----- Original Message -----
> From: "Stanislav Kholmanskikh" <stanislav.kholmanskikh@oracle.com>
> To: ltp-list@lists.sourceforge.net
> Cc: "vasily isaenko" <vasily.isaenko@oracle.com>
> Sent: Wednesday, 13 November, 2013 8:52:42 AM
> Subject: [LTP] [RFC PATCH] 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.kholmanskikh@oracle.com>
> ---
>  lib/tst_checkpoint.c |   56
>  ++++++++++++++++++++++++++++++++++++++++++++++++-
>  1 files changed, 54 insertions(+), 2 deletions(-)

Hi,

I would go with just 2 return values:
  -1 - for error/timeout
  fd - otherwise

fd == 0 is a valid descriptor
we can tell if it was timeout or error by errno code 

Why do we need "saved_errno"?

Regards,
Jan

> 
> diff --git a/lib/tst_checkpoint.c b/lib/tst_checkpoint.c
> index 56c86b5..a7936da 100644
> --- a/lib/tst_checkpoint.c
> +++ b/lib/tst_checkpoint.c
> @@ -30,9 +30,54 @@
>  #include <sys/stat.h>
>  #include <fcntl.h>
>  #include <poll.h>
> +#include <time.h>
>  
>  #include "tst_checkpoint.h"
>  
> +/*
> + * Issue open() on 'path' fifo with O_WRONLY flag and wait for
> + * a reader up to 'timeout' ms.
> + *
> + * Returns:
> + *   0   - timeout has happened
> + *   > 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 interval_ms = 1; /* how often issue open(O_NONBLOCK) */
> +	long timeleft = timeout;
> +	int saved_errno = errno;
> +
> +	struct timespec interval;
> +	interval.tv_sec = 0;
> +	interval.tv_nsec = interval_ms * 1000000; /* in ns */
> +
> +	for (;;) {
> +		fd = open(path, O_WRONLY | O_NONBLOCK);
> +		if (fd < 0) {
> +			if ((errno == ENXIO) || (errno == EINTR)) {
> +				if (timeleft <= 0) {
> +					errno = saved_errno;
> +
> +				return 0;
> +				}
> +
> +				timeleft -= interval_ms;
> +				nanosleep(&interval, NULL);
> +
> +				continue;
> +			}
> +
> +			return -1;
> +		}
> +
> +		return fd;
> +	}
> +}
> +
>  void tst_checkpoint_init(const char *file, const int lineno,
>                           struct tst_checkpoint *self)
>  {
> @@ -195,12 +240,19 @@ 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) {
> +	switch (fd) {
> +	case 0:
> +		tst_brkm(TBROK, cleanup_fn,
> +			"Checkpoint timeouted after %u msecs at %s:%d",
> +			self->timeout, file, lineno);
> +	break;
> +	case -1:
>  		tst_brkm(TBROK | TERRNO, cleanup_fn,
>  		         "Failed to open fifo '%s' at %s:%d",
>  		         TST_CHECKPOINT_FIFO, file, lineno);
> +	break;
>  	}
>  
>  	ret = write(fd, "p", 1);
> --
> 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	other threads:[~2013-11-13  8:46 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-29  7:55 [LTP] [PATCH] setpgid03: use SIGUSR1 instead of sleep Stanislav Kholmanskikh
2013-10-29 10:30 ` Jan Stancek
2013-10-29 11:54   ` Stanislav Kholmanskikh
2013-10-30  9:07   ` [LTP] [PATCH SERIES V2] " Stanislav Kholmanskikh
2013-10-30  9:07   ` [LTP] [PATCH V2 1/2] setpgid03: handle children errors and cleanup Stanislav Kholmanskikh
2013-10-30  9:07   ` [LTP] [PATCH V2 2/2] setpgid03: use SIGUSR1 instead of sleep Stanislav Kholmanskikh
2013-10-30 13:45     ` Jan Stancek
2013-10-31  7:54       ` Stanislav Kholmanskikh
2013-10-31 15:06         ` chrubis
     [not found]           ` <52727305.5070806@oracle.com>
2013-10-31 16:29             ` chrubis
     [not found]               ` <527B7485.2030809@oracle.com>
2013-11-07 11:30                 ` chrubis
2013-11-13  7:52                   ` [LTP] [RFC PATCH] tst_checkpoint_signal_child: implemented timeout Stanislav Kholmanskikh
2013-11-13  8:46                     ` Jan Stancek [this message]
2013-11-13  8:58                       ` Stanislav Kholmanskikh
2013-11-13  9:15                         ` [LTP] [RFC PATCH V2] " Stanislav Kholmanskikh
2013-11-13 17:50                           ` chrubis
2013-11-14  6:37                             ` [LTP] [PATCH V3 1/2] tst_res: added ETIME, ETIMEDOUT errno values Stanislav Kholmanskikh
2013-11-14 14:19                               ` chrubis
2013-11-14  6:37                             ` [LTP] [PATCH V3 2/2] tst_checkpoint_signal_child: implemented timeout Stanislav Kholmanskikh
2013-11-14  9:05                               ` Jan Stancek
2013-11-14 14:33                               ` chrubis
2013-12-12  9:21     ` [LTP] [PATCH V3 1/2] setpgid03: handle children errors and cleanup Stanislav Kholmanskikh
2013-12-12  9:21     ` [LTP] [PATCH V3 2/2] setpgid03: use tst_checkpoint interface Stanislav Kholmanskikh
2014-01-20 16:09       ` chrubis
     [not found]         ` <52DE7063.8070305@oracle.com>
2014-01-21 13:20           ` chrubis
2013-10-30  2:25 ` [LTP] [PATCH] setpgid03: use SIGUSR1 instead of sleep Wanlong Gao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2000015083.30028001.1384332372741.JavaMail.root@redhat.com \
    --to=jstancek@redhat.com \
    --cc=ltp-list@lists.sourceforge.net \
    --cc=stanislav.kholmanskikh@oracle.com \
    --cc=vasily.isaenko@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox