public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Stephen Hemminger <shemminger@vyatta•com>
To: Pavel Emelyanov <xemul@parallels•com>
Cc: Stephen Hemminger <shemminger@linux-foundation•org>,
	Linux Netdev List <netdev@vger•kernel.org>
Subject: Re: [PATCH] iproute: Fix errno propagation from rtnl_talk
Date: Mon, 20 Aug 2012 12:55:22 -0700	[thread overview]
Message-ID: <20120820125522.2e5eb519@nehalam.linuxnetplumber.net> (raw)
In-Reply-To: <5031F088.1030404@parallels.com>

On Mon, 20 Aug 2012 12:08:40 +0400
Pavel Emelyanov <xemul@parallels•com> wrote:

> Callers of rtnl_talk check errno value for their needs. In particular, the addrs
> and routes restoring code validly reports success if the EEXISTS is in there.
> 
> However, the errno value can be sometimes screwed up by the perror call. Thus
> we should only set it _after_ the message was emitted.
> 
> Signed-off-by: Pavel Emelyanov <xemul@parallels•com>
> 
> ---
> 
> diff --git a/lib/libnetlink.c b/lib/libnetlink.c
> index 878911e..8e8c8b9 100644
> --- a/lib/libnetlink.c
> +++ b/lib/libnetlink.c
> @@ -360,13 +360,14 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
>  				if (l < sizeof(struct nlmsgerr)) {
>  					fprintf(stderr, "ERROR truncated\n");
>  				} else {
> -					errno = -err->error;
> -					if (errno == 0) {
> +					if (!err->error) {
>  						if (answer)
>  							memcpy(answer, h, h->nlmsg_len);
>  						return 0;
>  					}
> -					perror("RTNETLINK answers");
> +
> +					fprintf(stderr, "RTNETLINK answers: %s\n", strerror(-err->error));
> +					errno = -err->error;
>  				}
>  				return -1;
>  			}

Applied

      reply	other threads:[~2012-08-20 19:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-20  8:08 [PATCH] iproute: Fix errno propagation from rtnl_talk Pavel Emelyanov
2012-08-20 19:55 ` Stephen Hemminger [this message]

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=20120820125522.2e5eb519@nehalam.linuxnetplumber.net \
    --to=shemminger@vyatta$(echo .)com \
    --cc=netdev@vger$(echo .)kernel.org \
    --cc=shemminger@linux-foundation$(echo .)org \
    --cc=xemul@parallels$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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