diff mbox series

ksmbd-tools: Standardize exit codes

Message ID 20211103151018.172802-1-casta@xwing.info (mailing list archive)
State New, archived
Headers show
Series ksmbd-tools: Standardize exit codes | expand

Commit Message

Guillaume Castagnino Nov. 3, 2021, 3:10 p.m. UTC
In case of success, EXIT_SUCCESS must be returned by the control binary
This standard behaviour is expected for example for the unit file

Signed-off-by: Guillaume Castagnino <casta@xwing.info>
---
 control/control.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Namjae Jeon Nov. 3, 2021, 11:26 p.m. UTC | #1
2021-11-04 0:10 GMT+09:00, Guillaume Castagnino <casta@xwing.info>:
> In case of success, EXIT_SUCCESS must be returned by the control binary
> This standard behaviour is expected for example for the unit file
>
> Signed-off-by: Guillaume Castagnino <casta@xwing.info>
> ---
>  control/control.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/control/control.c b/control/control.c
> index 5b86355..5ff2780 100644
> --- a/control/control.c
> +++ b/control/control.c
> @@ -43,7 +43,7 @@ static int ksmbd_control_shutdown(void)
>
>  	ret = write(fd, "hard", 4);
>  	close(fd);
> -	return ret;
> +	return ret != -1 ? EXIT_SUCCESS : EXIT_FAILURE;
Shouldn't we also return such a return for open() failures?

>  }
>
>  static int ksmbd_control_show_version(void)
> @@ -61,7 +61,7 @@ static int ksmbd_control_show_version(void)
>  	close(fd);
>  	if (ret != -1)
>  		pr_info("ksmbd version : %s\n", ver);
> -	return ret;
> +	return ret != -1 ? EXIT_SUCCESS : EXIT_FAILURE;
Ditto.
>  }
>
>  static int ksmbd_control_debug(char *comp)
> @@ -85,7 +85,7 @@ static int ksmbd_control_debug(char *comp)
>  	pr_info("%s\n", buf);
>  out:
>  	close(fd);
> -	return ret;
> +	return ret != -1 ? EXIT_SUCCESS : EXIT_FAILURE;
Ditto.
>  }
>
>  int main(int argc, char *argv[])
> @@ -104,7 +104,7 @@ int main(int argc, char *argv[])
>  	while ((c = getopt(argc, argv, "sd:cVh")) != EOF)
>  		switch (c) {
>  		case 's':
> -			ksmbd_control_shutdown();
> +			ret = ksmbd_control_shutdown();
>  			break;
>  		case 'd':
>  			ret = ksmbd_control_debug(optarg);
> --
> 2.33.1
>
>
Guillaume Castagnino Nov. 4, 2021, 8:33 a.m. UTC | #2
Le jeudi 04 novembre 2021 à 08:26 +0900, Namjae Jeon a écrit :
> 2021-11-04 0:10 GMT+09:00, Guillaume Castagnino <casta@xwing.info>:
> > In case of success, EXIT_SUCCESS must be returned by the control
> > binary
> > This standard behaviour is expected for example for the unit file
> > 
> > Signed-off-by: Guillaume Castagnino <casta@xwing.info>
> > ---
> >  control/control.c | 8 ++++----
> >  1 file changed, 4 insertions(+), 4 deletions(-)
> > 
> > diff --git a/control/control.c b/control/control.c
> > index 5b86355..5ff2780 100644
> > --- a/control/control.c
> > +++ b/control/control.c
> > @@ -43,7 +43,7 @@ static int ksmbd_control_shutdown(void)
> > 
> >         ret = write(fd, "hard", 4);
> >         close(fd);
> > -       return ret;
> > +       return ret != -1 ? EXIT_SUCCESS : EXIT_FAILURE;
> Shouldn't we also return such a return for open() failures?
> 

In case of open error, it already returns something != 0 (-1) in every
cases. So for me it’s less an an issue. But it would probably be better
if it’s EXIT_FAILURE indeed.

I will submit a new patch

Regards,


> >  }
> > 
> >  static int ksmbd_control_show_version(void)
> > @@ -61,7 +61,7 @@ static int ksmbd_control_show_version(void)
> >         close(fd);
> >         if (ret != -1)
> >                 pr_info("ksmbd version : %s\n", ver);
> > -       return ret;
> > +       return ret != -1 ? EXIT_SUCCESS : EXIT_FAILURE;
> Ditto.
> >  }
> > 
> >  static int ksmbd_control_debug(char *comp)
> > @@ -85,7 +85,7 @@ static int ksmbd_control_debug(char *comp)
> >         pr_info("%s\n", buf);
> >  out:
> >         close(fd);
> > -       return ret;
> > +       return ret != -1 ? EXIT_SUCCESS : EXIT_FAILURE;
> Ditto.
> >  }
> > 
> >  int main(int argc, char *argv[])
> > @@ -104,7 +104,7 @@ int main(int argc, char *argv[])
> >         while ((c = getopt(argc, argv, "sd:cVh")) != EOF)
> >                 switch (c) {
> >                 case 's':
> > -                       ksmbd_control_shutdown();
> > +                       ret = ksmbd_control_shutdown();
> >                         break;
> >                 case 'd':
> >                         ret = ksmbd_control_debug(optarg);
> > --
> > 2.33.1
> > 
> >
diff mbox series

Patch

diff --git a/control/control.c b/control/control.c
index 5b86355..5ff2780 100644
--- a/control/control.c
+++ b/control/control.c
@@ -43,7 +43,7 @@  static int ksmbd_control_shutdown(void)
 
 	ret = write(fd, "hard", 4);
 	close(fd);
-	return ret;
+	return ret != -1 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
 static int ksmbd_control_show_version(void)
@@ -61,7 +61,7 @@  static int ksmbd_control_show_version(void)
 	close(fd);
 	if (ret != -1)
 		pr_info("ksmbd version : %s\n", ver);
-	return ret;
+	return ret != -1 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
 static int ksmbd_control_debug(char *comp)
@@ -85,7 +85,7 @@  static int ksmbd_control_debug(char *comp)
 	pr_info("%s\n", buf);
 out:
 	close(fd);
-	return ret;
+	return ret != -1 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
 int main(int argc, char *argv[])
@@ -104,7 +104,7 @@  int main(int argc, char *argv[])
 	while ((c = getopt(argc, argv, "sd:cVh")) != EOF)
 		switch (c) {
 		case 's':
-			ksmbd_control_shutdown();
+			ret = ksmbd_control_shutdown();
 			break;
 		case 'd':
 			ret = ksmbd_control_debug(optarg);