public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] elfcompress: fix exit status in case of an error
@ 2021-05-12 16:00 Dmitry V. Levin
  2021-05-12 20:29 ` Mark Wielaard
  0 siblings, 1 reply; 6+ messages in thread
From: Dmitry V. Levin @ 2021-05-12 16:00 UTC (permalink / raw)
  To: elfutils-devel

Exit status of 255 in case of an error is probably not what elfcompress
users expect, change it to 1.

Reported-by: Vitaly Chikunov <vt@altlinux.org>
Fixes: 92acb57eb046 ("elfcompress: New utility.")
---
 src/ChangeLog     | 2 ++
 src/elfcompress.c | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index de130f79..bc6ffc87 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,7 @@
 2021-05-12  Dmitry V. Levin  <ldv@altlinux.org>
 
+	* elfcompress.c (main): Return 1 instead of -1 in case of an error.
+
 	* elfcompress.c (process_file): Remove redundant assignment in case of
 	"Nothing to do".
 
diff --git a/src/elfcompress.c b/src/elfcompress.c
index 05f3bc2c..dacaff32 100644
--- a/src/elfcompress.c
+++ b/src/elfcompress.c
@@ -1358,5 +1358,5 @@ main (int argc, char **argv)
   while (++remaining < argc);
 
   free_patterns ();
-  return result;
+  return !!result;
 }
-- 
ldv

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] elfcompress: fix exit status in case of an error
  2021-05-12 16:00 [PATCH] elfcompress: fix exit status in case of an error Dmitry V. Levin
@ 2021-05-12 20:29 ` Mark Wielaard
  2021-05-12 20:35   ` Dmitry V. Levin
  0 siblings, 1 reply; 6+ messages in thread
From: Mark Wielaard @ 2021-05-12 20:29 UTC (permalink / raw)
  To: Dmitry V. Levin; +Cc: elfutils-devel

Hi Dmitry,

On Wed, May 12, 2021 at 04:00:00PM +0000, Dmitry V. Levin wrote:
> Exit status of 255 in case of an error is probably not what elfcompress
> users expect, change it to 1.
> 
> Reported-by: Vitaly Chikunov <vt@altlinux.org>
> Fixes: 92acb57eb046 ("elfcompress: New utility.")
> [...]  
> diff --git a/src/elfcompress.c b/src/elfcompress.c
> index 05f3bc2c..dacaff32 100644
> --- a/src/elfcompress.c
> +++ b/src/elfcompress.c
> @@ -1358,5 +1358,5 @@ main (int argc, char **argv)
>    while (++remaining < argc);
>  
>    free_patterns ();
> -  return result;
> +  return !!result;
>  }

The change to return 1 (or zero) is good.

But could we instead initialize res to 1 (or EXIT_FAILURE from
stdlib.h) at the top? That reads IMHO a little nicer than the !!
pattern.

Thanks,

Mark


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] elfcompress: fix exit status in case of an error
  2021-05-12 20:29 ` Mark Wielaard
@ 2021-05-12 20:35   ` Dmitry V. Levin
  2021-05-12 21:13     ` Mark Wielaard
  0 siblings, 1 reply; 6+ messages in thread
From: Dmitry V. Levin @ 2021-05-12 20:35 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: elfutils-devel

Hi Mark,

On Wed, May 12, 2021 at 10:29:33PM +0200, Mark Wielaard wrote:
> Hi Dmitry,
> 
> On Wed, May 12, 2021 at 04:00:00PM +0000, Dmitry V. Levin wrote:
> > Exit status of 255 in case of an error is probably not what elfcompress
> > users expect, change it to 1.
> > 
> > Reported-by: Vitaly Chikunov <vt@altlinux.org>
> > Fixes: 92acb57eb046 ("elfcompress: New utility.")
> > [...]  
> > diff --git a/src/elfcompress.c b/src/elfcompress.c
> > index 05f3bc2c..dacaff32 100644
> > --- a/src/elfcompress.c
> > +++ b/src/elfcompress.c
> > @@ -1358,5 +1358,5 @@ main (int argc, char **argv)
> >    while (++remaining < argc);
> >  
> >    free_patterns ();
> > -  return result;
> > +  return !!result;
> >  }
> 
> The change to return 1 (or zero) is good.
> 
> But could we instead initialize res to 1

That is, change process_file() to return 1 (or EXIT_FAILURE)
instead of -1 in case of an error?


-- 
ldv

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] elfcompress: fix exit status in case of an error
  2021-05-12 20:35   ` Dmitry V. Levin
@ 2021-05-12 21:13     ` Mark Wielaard
  2021-05-12 21:52       ` [PATCH v2] " Dmitry V. Levin
  0 siblings, 1 reply; 6+ messages in thread
From: Mark Wielaard @ 2021-05-12 21:13 UTC (permalink / raw)
  To: Dmitry V. Levin; +Cc: elfutils-devel

Hi Dmitry,

On Wed, May 12, 2021 at 11:35:27PM +0300, Dmitry V. Levin wrote:
> On Wed, May 12, 2021 at 10:29:33PM +0200, Mark Wielaard wrote:
> > On Wed, May 12, 2021 at 04:00:00PM +0000, Dmitry V. Levin wrote:
> > > Exit status of 255 in case of an error is probably not what elfcompress
> > > users expect, change it to 1.
> > > 
> > > Reported-by: Vitaly Chikunov <vt@altlinux.org>
> > > Fixes: 92acb57eb046 ("elfcompress: New utility.")
> > > [...]  
> > > diff --git a/src/elfcompress.c b/src/elfcompress.c
> > > index 05f3bc2c..dacaff32 100644
> > > --- a/src/elfcompress.c
> > > +++ b/src/elfcompress.c
> > > @@ -1358,5 +1358,5 @@ main (int argc, char **argv)
> > >    while (++remaining < argc);
> > >  
> > >    free_patterns ();
> > > -  return result;
> > > +  return !!result;
> > >  }
> > 
> > The change to return 1 (or zero) is good.
> > 
> > But could we instead initialize res to 1
> 
> That is, change process_file() to return 1 (or EXIT_FAILURE)
> instead of -1 in case of an error?

Yes. I admit I assumed this was already in process_file.  But this is
really just a nitpick because I always get confused when reading the
!! pattern. The important part returning zero or one from main.

Thanks,

Mark


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2] elfcompress: fix exit status in case of an error
  2021-05-12 21:13     ` Mark Wielaard
@ 2021-05-12 21:52       ` Dmitry V. Levin
  2021-05-13 13:44         ` Mark Wielaard
  0 siblings, 1 reply; 6+ messages in thread
From: Dmitry V. Levin @ 2021-05-12 21:52 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: elfutils-devel

Exit status of 255 in case of an error is probably not what elfcompress
users expect, change it to 1.

Reported-by: Vitaly Chikunov <vt@altlinux.org>
Fixes: 92acb57eb046 ("elfcompress: New utility.")
---
 src/ChangeLog     | 3 +++
 src/elfcompress.c | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index de130f79..2c7be185 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,8 @@
 2021-05-12  Dmitry V. Levin  <ldv@altlinux.org>
 
+	* elfcompress.c (process_file): Return 1 instead of -1 in case of an
+	error.
+
 	* elfcompress.c (process_file): Remove redundant assignment in case of
 	"Nothing to do".
 
diff --git a/src/elfcompress.c b/src/elfcompress.c
index 05f3bc2c..2c6d91ba 100644
--- a/src/elfcompress.c
+++ b/src/elfcompress.c
@@ -298,7 +298,7 @@ process_file (const char *fname)
 
   /* How many sections are we talking about?  */
   size_t shnum = 0;
-  int res = -1;
+  int res = 1;
 
   fd = open (fname, O_RDONLY);
   if (fd < 0)
-- 
ldv

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] elfcompress: fix exit status in case of an error
  2021-05-12 21:52       ` [PATCH v2] " Dmitry V. Levin
@ 2021-05-13 13:44         ` Mark Wielaard
  0 siblings, 0 replies; 6+ messages in thread
From: Mark Wielaard @ 2021-05-13 13:44 UTC (permalink / raw)
  To: Dmitry V. Levin; +Cc: elfutils-devel

Hi Dmitry,

On Thu, 2021-05-13 at 00:52 +0300, Dmitry V. Levin wrote:
> Exit status of 255 in case of an error is probably not what
> elfcompress users expect, change it to 1.

This looks good.

Thanks,

Mark

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-05-13 13:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-12 16:00 [PATCH] elfcompress: fix exit status in case of an error Dmitry V. Levin
2021-05-12 20:29 ` Mark Wielaard
2021-05-12 20:35   ` Dmitry V. Levin
2021-05-12 21:13     ` Mark Wielaard
2021-05-12 21:52       ` [PATCH v2] " Dmitry V. Levin
2021-05-13 13:44         ` Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).