summaryrefslogtreecommitdiffstats
path: root/src/veritysetup
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-11-22 20:27:09 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2018-11-22 22:22:30 +0100
commitd850ad9a30ec92c3c4f2d9f1240eaa5672565443 (patch)
treedb1d371ef0f412e1c279525cd1c4849b1620ebe6 /src/veritysetup
parentveritysetup-generator: make arg_dest const (diff)
downloadsystemd-d850ad9a30ec92c3c4f2d9f1240eaa5672565443.tar.xz
systemd-d850ad9a30ec92c3c4f2d9f1240eaa5672565443.zip
veritysetup-generator: use static destructors and define main through macro
Diffstat (limited to 'src/veritysetup')
-rw-r--r--src/veritysetup/veritysetup-generator.c40
1 files changed, 17 insertions, 23 deletions
diff --git a/src/veritysetup/veritysetup-generator.c b/src/veritysetup/veritysetup-generator.c
index 338cad4228..0f5830a6e2 100644
--- a/src/veritysetup/veritysetup-generator.c
+++ b/src/veritysetup/veritysetup-generator.c
@@ -13,6 +13,7 @@
#include "generator.h"
#include "hexdecoct.h"
#include "id128-util.h"
+#include "main-func.h"
#include "mkdir.h"
#include "parse-util.h"
#include "proc-cmdline.h"
@@ -28,6 +29,10 @@ static char *arg_root_hash = NULL;
static char *arg_data_what = NULL;
static char *arg_hash_what = NULL;
+STATIC_DESTRUCTOR_REGISTER(arg_root_hash, freep);
+STATIC_DESTRUCTOR_REGISTER(arg_data_what, freep);
+STATIC_DESTRUCTOR_REGISTER(arg_hash_what, freep);
+
static int create_device(void) {
_cleanup_free_ char *u = NULL, *v = NULL, *d = NULL, *e = NULL, *u_escaped = NULL, *v_escaped = NULL, *root_hash_escaped = NULL;
_cleanup_fclose_ FILE *f = NULL;
@@ -199,13 +204,11 @@ static int determine_devices(void) {
return 1;
}
-int main(int argc, char *argv[]) {
+static int run(int argc, char *argv[]) {
int r;
- if (argc > 1 && argc != 4) {
- log_error("This program takes three or no arguments.");
- return EXIT_FAILURE;
- }
+ if (argc > 1 && argc != 4)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "This program takes three or no arguments.");
if (argc > 1)
arg_dest = argv[1];
@@ -213,33 +216,24 @@ int main(int argc, char *argv[]) {
log_setup_generator();
r = proc_cmdline_parse(parse_proc_cmdline_item, NULL, PROC_CMDLINE_STRIP_RD_PREFIX);
- if (r < 0) {
- log_warning_errno(r, "Failed to parse kernel command line: %m");
- goto finish;
- }
+ if (r < 0)
+ return log_warning_errno(r, "Failed to parse kernel command line: %m");
/* For now we only support the root device on verity. Later on we might want to add support for /etc/veritytab
* or similar to define additional mappings */
- if (!arg_enabled) {
- r = 0;
- goto finish;
- }
+ if (!arg_enabled)
+ return 0;
r = determine_devices();
if (r < 0)
- goto finish;
+ return r;
r = create_device();
if (r < 0)
- goto finish;
-
- r = 0;
-
-finish:
- free(arg_root_hash);
- free(arg_data_what);
- free(arg_hash_what);
+ return r;
- return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
+ return 0;
}
+
+DEFINE_MAIN_FUNCTION(run);