All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
To: Michael Welling <mwelling@ieee.org>
Cc: Jan Kiszka <jan.kiszka@siemens.com>, xenomai@xenomai.org
Subject: Re: [Xenomai] [PATCH] demo/alchemy/cross-link: Properly handle syscall errors
Date: Tue, 23 Feb 2016 00:49:18 +0100	[thread overview]
Message-ID: <20160222234918.GJ7398@hermes.click-hack.org> (raw)
In-Reply-To: <1456184548-30058-1-git-send-email-mwelling@ieee.org>

On Mon, Feb 22, 2016 at 05:42:28PM -0600, Michael Welling wrote:
> Update cross link demo to properly handle errors returned from syscalls.
> 
> Signed-off-by: Michael Welling <mwelling@ieee.org>
> ---
>  demo/alchemy/cobalt/cross-link.c | 25 +++++++++++++------------
>  1 file changed, 13 insertions(+), 12 deletions(-)
> 
> diff --git a/demo/alchemy/cobalt/cross-link.c b/demo/alchemy/cobalt/cross-link.c
> index 8c0f53f..dceb928 100644
> --- a/demo/alchemy/cobalt/cross-link.c
> +++ b/demo/alchemy/cobalt/cross-link.c
> @@ -23,6 +23,7 @@
>  #include <stdio.h>
>  #include <signal.h>
>  #include <unistd.h>
> +#include <errno.h>
>  #include <sys/mman.h>
>  #include <alchemy/task.h>
>  #include <alchemy/timer.h>
> @@ -78,8 +79,8 @@ static int close_file( int fd, char *name)
>  	do {
>  		i++;
>  		err = close(fd);
> -		switch (err) {
> -		case -EAGAIN:
> +		switch (errno) {
> +		case EAGAIN:

This looks incorrect. errno has a meaningful value only if err is
-1. You could get away with setting errno to 0 before calling close,
this would probably work, but for a more complex service which calls
several syscalls under the hoold, this would not even work.

So, you should probably just add:
err = err < 0 ? -errno : 0;

-- 
					    Gilles.
https://click-hack.org


  reply	other threads:[~2016-02-22 23:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-22 23:42 [Xenomai] [PATCH] demo/alchemy/cross-link: Properly handle syscall errors Michael Welling
2016-02-22 23:49 ` Gilles Chanteperdrix [this message]
2016-02-22 23:51   ` Michael Welling
2016-02-22 23:50 ` Michael Welling

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=20160222234918.GJ7398@hermes.click-hack.org \
    --to=gilles.chanteperdrix@xenomai.org \
    --cc=jan.kiszka@siemens.com \
    --cc=mwelling@ieee.org \
    --cc=xenomai@xenomai.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.