]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/boot/bless-boot.c
coccinelle: make use of SYNTHETIC_ERRNO
[thirdparty/systemd.git] / src / boot / bless-boot.c
index 84ac9e39e48f5eaf60031d9ad53ff863f81d2dba..42b9618aa93bb9237cd17380012318edfb035213 100644 (file)
@@ -9,6 +9,7 @@
 #include "fd-util.h"
 #include "fs-util.h"
 #include "log.h"
+#include "main-func.h"
 #include "parse-util.h"
 #include "path-util.h"
 #include "util.h"
@@ -17,6 +18,8 @@
 
 static char *arg_path = NULL;
 
+STATIC_DESTRUCTOR_REGISTER(arg_path, freep);
+
 static int help(int argc, char *argv[], void *userdata) {
 
         printf("%s [COMMAND] [OPTIONS...]\n"
@@ -118,10 +121,10 @@ static int parse_counter(
         e++;
 
         k = strspn(e, DIGITS);
-        if (k == 0) {
-                log_error("Can't parse empty 'tries left' counter from LoaderBootCountPath: %s", path);
-                return -EINVAL;
-        }
+        if (k == 0)
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Can't parse empty 'tries left' counter from LoaderBootCountPath: %s",
+                                       path);
 
         z = strndupa(e, k);
         r = safe_atou64(z, &left);
@@ -134,10 +137,10 @@ static int parse_counter(
                 e++;
 
                 k = strspn(e, DIGITS);
-                if (k == 0) /* If there's a "-" there also needs to be at least one digit */
-                        log_error("Can't parse empty 'tries done' counter from LoaderBootCountPath: %s", path);
-                        return -EINVAL;
-                }
+                if (k == 0) /* If there's a "-" there also needs to be at least one digit */
+                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                               "Can't parse empty 'tries done' counter from LoaderBootCountPath: %s",
+                                               path);
 
                 z = strndupa(e, k);
                 r = safe_atou64(z, &done);
@@ -182,22 +185,22 @@ static int acquire_boot_count_path(
 
         efi_tilt_backslashes(path);
 
-        if (!path_is_normalized(path)) {
-                log_error("Path read from LoaderBootCountPath is not normalized, refusing: %s", path);
-                return -EINVAL;
-        }
+        if (!path_is_normalized(path))
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Path read from LoaderBootCountPath is not normalized, refusing: %s",
+                                       path);
 
-        if (!path_is_absolute(path)) {
-                log_error("Path read from LoaderBootCountPath is not absolute, refusing: %s", path);
-                return -EINVAL;
-        }
+        if (!path_is_absolute(path))
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Path read from LoaderBootCountPath is not absolute, refusing: %s",
+                                       path);
 
         last = last_path_component(path);
         e = strrchr(last, '+');
-        if (!e) {
-                log_error("Path read from LoaderBootCountPath does not contain a counter, refusing: %s", path);
-                return -EINVAL;
-        }
+        if (!e)
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Path read from LoaderBootCountPath does not contain a counter, refusing: %s",
+                                       path);
 
         if (ret_prefix) {
                 prefix = strndup(path, e - path);
@@ -435,7 +438,7 @@ exists:
         return 0;
 }
 
-int main(int argc, char *argv[]) {
+static int run(int argc, char *argv[]) {
 
         static const Verb verbs[] = {
                 { "help",          VERB_ANY, VERB_ANY, 0,                 help        },
@@ -453,24 +456,17 @@ int main(int argc, char *argv[]) {
 
         r = parse_argv(argc, argv);
         if (r <= 0)
-                goto finish;
-
-        if (detect_container() > 0) {
-                log_error("Marking a boot is not supported in containers.");
-                r = -EOPNOTSUPP;
-                goto finish;
-        }
-
-        if (!is_efi_boot()) {
-                log_error("Marking a boot is only supported on EFI systems.");
-                r = -EOPNOTSUPP;
-                goto finish;
-        }
+                return r;
 
-        r = dispatch_verb(argc, argv, verbs, NULL);
+        if (detect_container() > 0)
+                return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
+                                       "Marking a boot is not supported in containers.");
 
-finish:
-        free(arg_path);
+        if (!is_efi_boot())
+                return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
+                                       "Marking a boot is only supported on EFI systems.");
 
-        return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
+        return dispatch_verb(argc, argv, verbs, NULL);
 }
+
+DEFINE_MAIN_FUNCTION(run);