Negative error codes are used as per the kernel coding style,
however userspace, especially the tests expect positive return
code compliant with sysexits.h.

So here we map EINVAL (Invalid argument) from errno.h to EX_USAGE
(command line usage error).

Without that fix we have:
     $  ./tools/nv_data-imei nv_data.bin bruteforce-imei  -i 12345
     The '12345' IMEI is invalid as it is composed of 5 digits instead of 15.
     errno_to_sysexit: error: unknown error code -1.
     errno_to_sysexit: error code -1 needs to be implemented
     lt-nv_data-imei: nv_data-imei.c:836: errno_to_sysexit: Assertion `false' 
failed.
     Aborted (core dumped)
instead of:
     $  ./tools/nv_data-imei nv_data.bin bruteforce-imei  -i 12345
     The '12345' IMEI is invalid as it is composed of 5 digits instead of 15.

Signed-off-by: Denis 'GNUtoo' Carikli <gnu...@cyberdimension.org>
---
 tools/nv_data-imei.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/nv_data-imei.c b/tools/nv_data-imei.c
index 6ec5adc..dfa3d86 100644
--- a/tools/nv_data-imei.c
+++ b/tools/nv_data-imei.c
@@ -164,19 +164,19 @@ static int get_imei(struct command *command, void *arg)
                                       " as it is composed of "
                                       "%d digits instead of %d.\n",
                                       len, IMEI_LENGTH);
-                               return -1;
+                               return -EINVAL;
                        } else if (!str_is_digit) {
                                printf("The '%s' "
                                       "IMEI is invalid"
                                       " as it does not only contains digits\n",
                                       imei->optarg);
-                               return -1;
+                               return -EINVAL;
                        } else if (!str_len_valid) {
                                printf("The '%s' "
                                       "IMEI is invalid as it is composed of "
                                       "%d digits instead of %d.\n",
                                       imei->optarg, len, IMEI_LENGTH);
-                               return -1;
+                               return -EINVAL;
                        }
 
                        /* imei.imei is IMEI_LENGTH + 1 */
-- 
2.29.0

_______________________________________________
Replicant mailing list
Replicant@osuosl.org
https://lists.osuosl.org/mailman/listinfo/replicant

Reply via email to