summaryrefslogtreecommitdiff
path: root/src/machine-id-setup
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-10-22 19:54:29 +0200
committerLennart Poettering <lennart@poettering.net>2015-10-24 23:03:49 +0200
commit0f03c2a4c093e3d44f4072144827e943c05c8904 (patch)
tree70232d1b14b4dfcd82983894d13963e2ca9f4fec /src/machine-id-setup
parent0f4743651081b5367ab06f238827ddfd4da74e74 (diff)
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.
Diffstat (limited to 'src/machine-id-setup')
-rw-r--r--src/machine-id-setup/machine-id-setup-main.c14
1 files changed, 9 insertions, 5 deletions
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;
}