Skip to contentSkip to conversation

ksmbd-tools: Standardize exit codes

PATCH Superseded Guillaume Castagnino 2 participants 3 messages Nov 3, 2021 – Nov 4, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ksmbd-tools: Standardize exit codes

In case of success, EXIT_SUCCESS must be returned by the control binary This standard behaviour is expected for example for the unit file

---
 control/control.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
control/control.c +4 -4
index 5b86355..5ff2780 100644
@@ -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);
Signature · 1 line
2.33.1
maintainer
#1 lore raw

2021-11-04 0:10 GMT+09:00, Guillaume Castagnino <[email protected]>:

Quoted 13 lines

In case of success, EXIT_SUCCESS must be returned by the control binary This standard behaviour is expected for example for the unit file

---
 control/control.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
control/control.c +0 -0
index 5b86355..5ff2780 100644

control/control.c static int ksmbd_control_shutdown(void) · line 46

Quoted 5 lines
control/control.c +1 -1
@@ -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?

control/control.c static int ksmbd_control_show_version(void) · line 64

Quoted 9 lines
control/control.c +1 -1
 }
 
 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.

control/control.c static int ksmbd_control_debug(char *comp) · line 88

Quoted 9 lines
control/control.c +1 -1
 }
 
 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.

Quoted 16 lines
control/control.c +1 -2
 }
 
 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

#2 lore raw

Le jeudi 04 novembre 2021 à 08:26 +0900, Namjae Jeon a écrit :

Quoted 16 lines

2021-11-04 0:10 GMT+09:00, Guillaume Castagnino <[email protected]>:

Quoted 15 lines

In case of success, EXIT_SUCCESS must be returned by the control binary
This standard behaviour is expected for example for the unit file

---
 control/control.c | 8 ++++----

 1 file changed, 4 insertions(+), 4 deletions(-)
control/control.c +0 -0
index 5b86355..5ff2780 100644
@@ -43,7 +43,7 @@ static int ksmbd_control_shutdown(void)
 
Quoted 6 lines

control/control.c static int ksmbd_control_shutdown(void) · line 46

Quoted 4 lines
control/control.c +1 -1
         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,

Quoted 36 lines

control/control.c static int ksmbd_control_show_version(void) · line 64

Quoted 9 lines
control/control.c +1 -1
  }
 
  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.

Quoted 9 lines
control/control.c +0 -0
  }
 
  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.

Quoted 16 lines

 }

 int main(int argc, char *argv[])

control/control.c +0 -0
@@ -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