diff options
author | 2018-11-20 18:17:53 +0900 | |
---|---|---|
committer | 2018-11-20 18:40:02 +0100 | |
commit | 0166c42868813d5d96b500277f6f819eef498b95 (patch) | |
tree | e66e9bb3a5d0119eda6876fea7e2eb0ca008a265 /src/machine-id-setup/machine-id-setup-main.c | |
parent | loginctl: use static destructor and DEFINE_MAIN_FUNCTION() macro (diff) | |
download | systemd-0166c42868813d5d96b500277f6f819eef498b95.tar.gz systemd-0166c42868813d5d96b500277f6f819eef498b95.tar.bz2 systemd-0166c42868813d5d96b500277f6f819eef498b95.zip |
machine-id: use static destructor and DEFINE_MAIN_FUNCTION() macro
Diffstat (limited to 'src/machine-id-setup/machine-id-setup-main.c')
-rw-r--r-- | src/machine-id-setup/machine-id-setup-main.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/machine-id-setup/machine-id-setup-main.c b/src/machine-id-setup/machine-id-setup-main.c index ed2a84373..c6a77cc90 100644 --- a/src/machine-id-setup/machine-id-setup-main.c +++ b/src/machine-id-setup/machine-id-setup-main.c @@ -9,6 +9,7 @@ #include "id128-util.h" #include "log.h" #include "machine-id-setup.h" +#include "main-func.h" #include "path-util.h" #include "terminal-util.h" #include "util.h" @@ -17,6 +18,8 @@ static char *arg_root = NULL; static bool arg_commit = false; static bool arg_print = false; +STATIC_DESTRUCTOR_REGISTER(arg_root, freep); + static int help(void) { _cleanup_free_ char *link = NULL; int r; @@ -102,7 +105,7 @@ static int parse_argv(int argc, char *argv[]) { return 1; } -int main(int argc, char *argv[]) { +static int run(int argc, char *argv[]) { char buf[SD_ID128_STRING_MAX]; sd_id128_t id; int r; @@ -112,31 +115,29 @@ int main(int argc, char *argv[]) { r = parse_argv(argc, argv); if (r <= 0) - goto finish; + return r; if (arg_commit) { const char *etc_machine_id; r = machine_id_commit(arg_root); if (r < 0) - goto finish; + return r; etc_machine_id = prefix_roota(arg_root, "/etc/machine-id"); r = id128_read(etc_machine_id, ID128_PLAIN, &id); - if (r < 0) { - log_error_errno(r, "Failed to read machine ID back: %m"); - goto finish; - } + if (r < 0) + return log_error_errno(r, "Failed to read machine ID back: %m"); } else { r = machine_id_setup(arg_root, SD_ID128_NULL, &id); if (r < 0) - goto finish; + return r; } if (arg_print) puts(sd_id128_to_string(id, buf)); -finish: - free(arg_root); - return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; + return 0; } + +DEFINE_MAIN_FUNCTION(run); |