All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony PERARD <anthony.perard@vates.tech>
To: Matthew Barnes <matthew.barnes@cloud.com>
Cc: Xen-devel <xen-devel@lists.xenproject.org>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Jan Beulich <jbeulich@suse.com>, Julien Grall <julien@xen.org>,
	Stefano Stabellini <sstabellini@kernel.org>
Subject: Re: [XEN PATCH v6] tools/lsevtchn: Use errno macro to handle hypercall error cases
Date: Mon, 29 Jul 2024 16:02:19 +0000	[thread overview]
Message-ID: <Zqe9CYQ7ODXMSJfo@l14> (raw)
In-Reply-To: <cbb751a7fab10d228513bb163c85c83d025330c9.1722265284.git.matthew.barnes@cloud.com>

On Mon, Jul 29, 2024 at 04:02:41PM +0100, Matthew Barnes wrote:
> diff --git a/tools/xcutils/lsevtchn.c b/tools/xcutils/lsevtchn.c
> index d1710613ddc5..29504c9d2077 100644
> --- a/tools/xcutils/lsevtchn.c
> +++ b/tools/xcutils/lsevtchn.c
> @@ -24,7 +25,28 @@ int main(int argc, char **argv)
>          status.port = port;
>          rc = xc_evtchn_status(xch, &status);
>          if ( rc < 0 )
> -            break;
> +        {
> +            switch ( errno )
> +            {
> +            case EACCES: /* Xen-owned evtchn */
> +                continue;
> +
> +            case EINVAL: /* Port enumeration has ended */
> +                rc = 0;
> +                break;
> +
> +            case ESRCH:
> +                perror("Domain ID does not correspond to valid domain");

I think this is going to print:
    "Domain ID does not correspond to valid domain: No such process"

> +                rc = ESRCH;

So, `rc` is going to be the value returned by main(), that is the exit
value of the program `lsevtchn`. Having different exit value might
be useful sometime to distinguish between different errors but that
would at least need to be written in some document. Can we just return
"1" here on error? (I mean "rc = 1")

> +                break;
> +
> +            default:
> +                perror(NULL);

It would be slightly more useful to print which function fails, simply
with:
    perror("xc_evtchn_status");


> +                rc = errno;

Same here, just "rc=1" should be good enough. Then if someone want to
know why `lsevtchn` failed, they can read the error messages.

At least, errno is likely to be between 0 and 255, but still, usually
not very useful as an exit value for a program.

> +                break;
> +            }
> +            goto out;
> +        }
>  
>          if ( status.status == EVTCHNSTAT_closed )
>              continue;
> @@ -58,7 +80,8 @@ int main(int argc, char **argv)
>          printf("\n");
>      }
>  
> + out:
>      xc_interface_close(xch);
>  
> -    return 0;
> +    return rc;
>  }

Thanks,

-- 

Anthony Perard | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech


      reply	other threads:[~2024-07-29 16:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-29 15:02 [XEN PATCH v6] tools/lsevtchn: Use errno macro to handle hypercall error cases Matthew Barnes
2024-07-29 16:02 ` Anthony PERARD [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=Zqe9CYQ7ODXMSJfo@l14 \
    --to=anthony.perard@vates.tech \
    --cc=andrew.cooper3@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=matthew.barnes@cloud.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.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.