From: Yu Watanabe Date: Tue, 20 Nov 2018 08:52:57 +0000 (+0900) Subject: firstboot: use static destructor and DEFINE_MAIN_FUNCTION() macro X-Git-Tag: v240~258^2~16 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=45f394187a9e2a016c15755a5b17d6796f42509f;p=thirdparty%2Fsystemd.git firstboot: use static destructor and DEFINE_MAIN_FUNCTION() macro --- diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c index 314c8a37908..5b08f34fecf 100644 --- a/src/firstboot/firstboot.c +++ b/src/firstboot/firstboot.c @@ -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);