[2/2] ima-evm-utils: Never exit with -1 code
diff mbox series

Message ID 20190727031900.7140-2-vt@altlinux.org
State New
Headers show
Series
  • [1/2] ima-evm-utils: Fix ima_verify return value on multiple files
Related show

Commit Message

Vitaly Chikunov July 27, 2019, 3:19 a.m. UTC
Change main() return code from -1 to 125 as -1 is not really valid exit
code. 125 is choosen because exit codes for signals start from 126.

Signed-off-by: Vitaly Chikunov <vt@altlinux.org>
---
 src/evmctl.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Mimi Zohar July 30, 2019, 11:57 a.m. UTC | #1
On Sat, 2019-07-27 at 06:19 +0300, Vitaly Chikunov wrote:
> Change main() return code from -1 to 125 as -1 is not really valid exit
> code. 125 is choosen because exit codes for signals start from 126.
> 
> Signed-off-by: Vitaly Chikunov <vt@altlinux.org>
> ---
>  src/evmctl.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/src/evmctl.c b/src/evmctl.c
> index d33a91e..e0a835f 100644
> --- a/src/evmctl.c
> +++ b/src/evmctl.c
> @@ -2100,6 +2100,8 @@ int main(int argc, char *argv[])
>  				break;
>  			log_err("%s\n", ERR_error_string(error, NULL));
>  		}
> +		if (err < 0)
> +			err = 125;
>  	}
>  
>  	if (eng) {

Agreed we need to return better errors, but instead of always
returning 125, would it be better to return the first errno, if err is
-1?

Mimi
Vitaly Chikunov July 30, 2019, 12:29 p.m. UTC | #2
Mimi,

On Tue, Jul 30, 2019 at 07:57:10AM -0400, Mimi Zohar wrote:
> On Sat, 2019-07-27 at 06:19 +0300, Vitaly Chikunov wrote:
> > Change main() return code from -1 to 125 as -1 is not really valid exit
> > code. 125 is choosen because exit codes for signals start from 126.
> > 
> > Signed-off-by: Vitaly Chikunov <vt@altlinux.org>
> > ---
> >  src/evmctl.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/src/evmctl.c b/src/evmctl.c
> > index d33a91e..e0a835f 100644
> > --- a/src/evmctl.c
> > +++ b/src/evmctl.c
> > @@ -2100,6 +2100,8 @@ int main(int argc, char *argv[])
> >  				break;
> >  			log_err("%s\n", ERR_error_string(error, NULL));
> >  		}
> > +		if (err < 0)
> > +			err = 125;
> >  	}
> >  
> >  	if (eng) {
> 
> Agreed we need to return better errors, but instead of always
> returning 125, would it be better to return the first errno, if err is
> -1?

125 will be not always but only to avoid returning -1 (or any negative).

There is no practice to exit with errno, AFAIK. Plus, errno we have at
the end (and which is reported to user) frequently is bogus and that
should be fixed. (I may do this later maybe, don't know how much work
that would require).

We also wish to reserve some exit code as hard error for tests.

Thanks,

> 
> Mimi
Vitaly Chikunov July 30, 2019, 12:39 p.m. UTC | #3
On Tue, Jul 30, 2019 at 03:29:39PM +0300, Vitaly Chikunov wrote:
> On Tue, Jul 30, 2019 at 07:57:10AM -0400, Mimi Zohar wrote:
> > On Sat, 2019-07-27 at 06:19 +0300, Vitaly Chikunov wrote:
> > > +		if (err < 0)
> > > +			err = 125;
> > >  	}
> > >  
> > >  	if (eng) {
> > 
> > Agreed we need to return better errors, but instead of always
> > returning 125, would it be better to return the first errno, if err is
> > -1?
> 
> 125 will be not always but only to avoid returning -1 (or any negative).
> 
> There is no practice to exit with errno, AFAIK. Plus, errno we have at
> the end (and which is reported to user) frequently is bogus and that
> should be fixed. (I may do this later maybe, don't know how much work
> that would require).
> 
> We also wish to reserve some exit code as hard error for tests.

I meant 'we also may wish'... This needs to be thought over.

Patch
diff mbox series

diff --git a/src/evmctl.c b/src/evmctl.c
index d33a91e..e0a835f 100644
--- a/src/evmctl.c
+++ b/src/evmctl.c
@@ -2100,6 +2100,8 @@  int main(int argc, char *argv[])
 				break;
 			log_err("%s\n", ERR_error_string(error, NULL));
 		}
+		if (err < 0)
+			err = 125;
 	}
 
 	if (eng) {