2022-03-16 22:47:41

by Kornilios Kourtis

[permalink] [raw]
Subject: [PATCH 2/2] dwarves: cus__load_files: set errno if load fails

From: Kornilios Kourtis <[email protected]>

This patch improves the error seen by the user by setting errno in
cus__load_files(). Otherwise, we get a "No such file or directory" error
which might be confusing.

Before the patch, using a bogus file:
$ ./pahole -J ./vmlinux-5.3.18-24.102-default.debug
pahole: ./vmlinux-5.3.18-24.102-default.debug: No such file or directory
$ ls ./vmlinux-5.3.18-24.102-default.debug
/home/kkourt/src/hubble-fgs/vmlinux-5.3.18-24.102-default.debug

After the patch:
$ ./pahole -J ./vmlinux-5.3.18-24.102-default.debug
pahole: ./vmlinux-5.3.18-24.102-default.debug: Unknown error -22

Which is not very helpful, but less confusing.

Signed-off-by: Kornilios Kourtis <[email protected]>
---
dwarves.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/dwarves.c b/dwarves.c
index 89b58ef..5d0b420 100644
--- a/dwarves.c
+++ b/dwarves.c
@@ -2399,8 +2399,11 @@ int cus__load_files(struct cus *cus, struct conf_load *conf,
int i = 0;

while (filenames[i] != NULL) {
- if (cus__load_file(cus, conf, filenames[i]))
+ int err = cus__load_file(cus, conf, filenames[i]);
+ if (err) {
+ errno = err;
return -++i;
+ }
++i;
}

--
2.25.1


2022-03-17 04:49:21

by Kornilios Kourtis

[permalink] [raw]
Subject: Re: [PATCH 2/2] dwarves: cus__load_files: set errno if load fails

On Wed, Mar 16, 2022 at 05:51:03PM -0300, Arnaldo Carvalho de Melo wrote:
> Agreed? I'll fix it up here and apply if so.

Agreed, thanks!

cheers,
Kornilios.

2022-03-17 06:03:05

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH 2/2] dwarves: cus__load_files: set errno if load fails

Em Wed, Mar 16, 2022 at 02:23:54PM +0100, [email protected] escreveu:
> From: Kornilios Kourtis <[email protected]>
>
> This patch improves the error seen by the user by setting errno in
> cus__load_files(). Otherwise, we get a "No such file or directory" error
> which might be confusing.
>
> Before the patch, using a bogus file:
> $ ./pahole -J ./vmlinux-5.3.18-24.102-default.debug
> pahole: ./vmlinux-5.3.18-24.102-default.debug: No such file or directory
> $ ls ./vmlinux-5.3.18-24.102-default.debug
> /home/kkourt/src/hubble-fgs/vmlinux-5.3.18-24.102-default.debug
>
> After the patch:
> $ ./pahole -J ./vmlinux-5.3.18-24.102-default.debug
> pahole: ./vmlinux-5.3.18-24.102-default.debug: Unknown error -22
>
> Which is not very helpful, but less confusing.

Humm, because you should've set errno to -err back in cus__load_files(),
with this on top of your two patches we should get the:

#define EINVAL 22 /* Invalid argument */


"Invalid argument" or so from getting.

diff --git a/dwarves.c b/dwarves.c
index 5d0b420f0110452e..89609e96c46747ce 100644
--- a/dwarves.c
+++ b/dwarves.c
@@ -2401,7 +2401,7 @@ int cus__load_files(struct cus *cus, struct conf_load *conf,
while (filenames[i] != NULL) {
int err = cus__load_file(cus, conf, filenames[i]);
if (err) {
- errno = err;
+ errno = -err;
return -++i;
}
++i;



Agreed? I'll fix it up here and apply if so.

- Arnaldo

> Signed-off-by: Kornilios Kourtis <[email protected]>
> ---
> dwarves.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/dwarves.c b/dwarves.c
> index 89b58ef..5d0b420 100644
> --- a/dwarves.c
> +++ b/dwarves.c
> @@ -2399,8 +2399,11 @@ int cus__load_files(struct cus *cus, struct conf_load *conf,
> int i = 0;
>
> while (filenames[i] != NULL) {
> - if (cus__load_file(cus, conf, filenames[i]))
> + int err = cus__load_file(cus, conf, filenames[i]);
> + if (err) {
> + errno = err;
> return -++i;
> + }
> ++i;
> }
>
> --
> 2.25.1

--

- Arnaldo

2022-03-17 06:47:42

by John Fastabend

[permalink] [raw]
Subject: RE: [PATCH 2/2] dwarves: cus__load_files: set errno if load fails

kkourt@ wrote:
> From: Kornilios Kourtis <[email protected]>
>
> This patch improves the error seen by the user by setting errno in
> cus__load_files(). Otherwise, we get a "No such file or directory" error
> which might be confusing.
>
> Before the patch, using a bogus file:
> $ ./pahole -J ./vmlinux-5.3.18-24.102-default.debug
> pahole: ./vmlinux-5.3.18-24.102-default.debug: No such file or directory
> $ ls ./vmlinux-5.3.18-24.102-default.debug
> /home/kkourt/src/hubble-fgs/vmlinux-5.3.18-24.102-default.debug
>
> After the patch:
> $ ./pahole -J ./vmlinux-5.3.18-24.102-default.debug
> pahole: ./vmlinux-5.3.18-24.102-default.debug: Unknown error -22
>
> Which is not very helpful, but less confusing.
>
> Signed-off-by: Kornilios Kourtis <[email protected]>
> ---

With the err to -err fix Arnaldo proposed.

Acked-by: John Fastabend <[email protected]>

2022-03-17 18:10:36

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH 2/2] dwarves: cus__load_files: set errno if load fails

Em Wed, Mar 16, 2022 at 10:00:57PM -0700, John Fastabend escreveu:
> kkourt@ wrote:
> > From: Kornilios Kourtis <[email protected]>
> >
> > This patch improves the error seen by the user by setting errno in
> > cus__load_files(). Otherwise, we get a "No such file or directory" error
> > which might be confusing.
> >
> > Before the patch, using a bogus file:
> > $ ./pahole -J ./vmlinux-5.3.18-24.102-default.debug
> > pahole: ./vmlinux-5.3.18-24.102-default.debug: No such file or directory
> > $ ls ./vmlinux-5.3.18-24.102-default.debug
> > /home/kkourt/src/hubble-fgs/vmlinux-5.3.18-24.102-default.debug
> >
> > After the patch:
> > $ ./pahole -J ./vmlinux-5.3.18-24.102-default.debug
> > pahole: ./vmlinux-5.3.18-24.102-default.debug: Unknown error -22
> >
> > Which is not very helpful, but less confusing.
> >
> > Signed-off-by: Kornilios Kourtis <[email protected]>
> > ---
>
> With the err to -err fix Arnaldo proposed.
>
> Acked-by: John Fastabend <[email protected]>

Thanks, did the ammendment and collected your Acked-by,

- Arnaldo