From 0f03c2a4c093e3d44f4072144827e943c05c8904 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 22 Oct 2015 19:54:29 +0200 Subject: path-util: unify how we process paths specified on the command line Let's introduce a common function that makes relative paths absolute and warns about any errors while doing so. --- src/machine-id-setup/machine-id-setup-main.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/machine-id-setup') diff --git a/src/machine-id-setup/machine-id-setup-main.c b/src/machine-id-setup/machine-id-setup-main.c index a9c4e3fadf..f1165ea09c 100644 --- a/src/machine-id-setup/machine-id-setup-main.c +++ b/src/machine-id-setup/machine-id-setup-main.c @@ -27,8 +27,9 @@ #include "log.h" #include "machine-id-setup.h" #include "util.h" +#include "path-util.h" -static const char *arg_root = NULL; +static char *arg_root = NULL; static bool arg_commit = false; static void help(void) { @@ -57,7 +58,7 @@ static int parse_argv(int argc, char *argv[]) { {} }; - int c; + int c, r; assert(argc >= 0); assert(argv); @@ -74,7 +75,9 @@ static int parse_argv(int argc, char *argv[]) { return version(); case ARG_ROOT: - arg_root = optarg; + r = parse_path_argument_and_warn(optarg, true, &arg_root); + if (r < 0) + return r; break; case ARG_COMMIT: @@ -104,13 +107,14 @@ int main(int argc, char *argv[]) { r = parse_argv(argc, argv); if (r <= 0) - return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; + goto finish; if (arg_commit) r = machine_id_commit(arg_root); else r = machine_id_setup(arg_root); - +finish: + free(arg_root); return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; } -- cgit v1.2.3-54-g00ecf