]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
firstboot: use static destructor and DEFINE_MAIN_FUNCTION() macro
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 20 Nov 2018 08:52:57 +0000 (17:52 +0900)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 20 Nov 2018 17:40:02 +0000 (18:40 +0100)
src/firstboot/firstboot.c

index 314c8a37908fdc4a71c6677b9ed909b056df0578..5b08f34fecf7f15f694ee303daa64311e65d9ed9 100644 (file)
@@ -27,6 +27,7 @@
 #include "fs-util.h"
 #include "hostname-util.h"
 #include "locale-util.h"
+#include "main-func.h"
 #include "mkdir.h"
 #include "os-util.h"
 #include "parse-util.h"
@@ -58,6 +59,14 @@ static bool arg_copy_keymap = false;
 static bool arg_copy_timezone = false;
 static bool arg_copy_root_password = false;
 
+STATIC_DESTRUCTOR_REGISTER(arg_root, freep);
+STATIC_DESTRUCTOR_REGISTER(arg_locale, freep);
+STATIC_DESTRUCTOR_REGISTER(arg_locale_messages, freep);
+STATIC_DESTRUCTOR_REGISTER(arg_keymap, freep);
+STATIC_DESTRUCTOR_REGISTER(arg_timezone, freep);
+STATIC_DESTRUCTOR_REGISTER(arg_hostname, freep);
+STATIC_DESTRUCTOR_REGISTER(arg_root_password, string_free_erasep);
+
 static bool press_any_key(void) {
         char k = 0;
         bool need_nl = true;
@@ -941,61 +950,49 @@ static int parse_argv(int argc, char *argv[]) {
         return 1;
 }
 
-int main(int argc, char *argv[]) {
+static int run(int argc, char *argv[]) {
         bool enabled;
         int r;
 
         r = parse_argv(argc, argv);
         if (r <= 0)
-                goto finish;
+                return r;
 
         log_setup_service();
 
         umask(0022);
 
         r = proc_cmdline_get_bool("systemd.firstboot", &enabled);
-        if (r < 0) {
-                log_error_errno(r, "Failed to parse systemd.firstboot= kernel command line argument, ignoring: %m");
-                goto finish;
-        }
-        if (r > 0 && !enabled) {
-                r = 0; /* disabled */
-                goto finish;
-        }
+        if (r < 0)
+                return log_error_errno(r, "Failed to parse systemd.firstboot= kernel command line argument, ignoring: %m");
+        if (r > 0 && !enabled)
+                return 0; /* disabled */
 
         r = process_locale();
         if (r < 0)
-                goto finish;
+                return r;
 
         r = process_keymap();
         if (r < 0)
-                goto finish;
+                return r;
 
         r = process_timezone();
         if (r < 0)
-                goto finish;
+                return r;
 
         r = process_hostname();
         if (r < 0)
-                goto finish;
+                return r;
 
         r = process_machine_id();
         if (r < 0)
-                goto finish;
+                return r;
 
         r = process_root_password();
         if (r < 0)
-                goto finish;
-
-finish:
-        free(arg_root);
-        free(arg_locale);
-        free(arg_locale_messages);
-        free(arg_keymap);
-        free(arg_timezone);
-        free(arg_hostname);
-        string_erase(arg_root_password);
-        free(arg_root_password);
-
-        return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
+                return r;
+
+        return 0;
 }
+
+DEFINE_MAIN_FUNCTION(run);