summaryrefslogtreecommitdiff
path: root/src/machine-id-setup
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-07-22 12:21:21 +0200
committerLennart Poettering <lennart@poettering.net>2016-07-22 12:59:36 +0200
commit487ddeb8bc1a05816802adb2d5a9dc4416b386fe (patch)
treeb4924d26c0ff4f968c964c21909e25c8eef087f9 /src/machine-id-setup
parent4b1afed01f092a2c6903b69205ca2ba99ead0d1d (diff)
machine-id-setup: add new --print switch
If specified we'll simply output the used machine ID.
Diffstat (limited to 'src/machine-id-setup')
-rw-r--r--src/machine-id-setup/machine-id-setup-main.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/machine-id-setup/machine-id-setup-main.c b/src/machine-id-setup/machine-id-setup-main.c
index b0199f181d..cc9b1b38fe 100644
--- a/src/machine-id-setup/machine-id-setup-main.c
+++ b/src/machine-id-setup/machine-id-setup-main.c
@@ -29,6 +29,7 @@
static char *arg_root = NULL;
static bool arg_commit = false;
+static bool arg_print = false;
static void help(void) {
printf("%s [OPTIONS...]\n\n"
@@ -37,6 +38,7 @@ static void help(void) {
" --version Show package version\n"
" --root=ROOT Filesystem root\n"
" --commit Commit transient ID\n"
+ " --print Print used machine ID\n"
, program_invocation_short_name);
}
@@ -46,6 +48,7 @@ static int parse_argv(int argc, char *argv[]) {
ARG_VERSION = 0x100,
ARG_ROOT,
ARG_COMMIT,
+ ARG_PRINT,
};
static const struct option options[] = {
@@ -53,6 +56,7 @@ static int parse_argv(int argc, char *argv[]) {
{ "version", no_argument, NULL, ARG_VERSION },
{ "root", required_argument, NULL, ARG_ROOT },
{ "commit", no_argument, NULL, ARG_COMMIT },
+ { "print", no_argument, NULL, ARG_PRINT },
{}
};
@@ -82,6 +86,10 @@ static int parse_argv(int argc, char *argv[]) {
arg_commit = true;
break;
+ case ARG_PRINT:
+ arg_print = true;
+ break;
+
case '?':
return -EINVAL;
@@ -98,6 +106,8 @@ static int parse_argv(int argc, char *argv[]) {
}
int main(int argc, char *argv[]) {
+ char buf[SD_ID128_STRING_MAX];
+ sd_id128_t id;
int r;
log_parse_environment();
@@ -107,10 +117,24 @@ int main(int argc, char *argv[]) {
if (r <= 0)
goto finish;
- if (arg_commit)
+ if (arg_commit) {
r = machine_id_commit(arg_root);
- else
- r = machine_id_setup(arg_root, SD_ID128_NULL, NULL);
+ if (r < 0)
+ goto finish;
+
+ r = sd_id128_get_machine(&id);
+ if (r < 0) {
+ log_error_errno(r, "Failed to read machine ID back: %m");
+ goto finish;
+ }
+ } else {
+ r = machine_id_setup(arg_root, SD_ID128_NULL, &id);
+ if (r < 0)
+ goto finish;
+ }
+
+ if (arg_print)
+ puts(sd_id128_to_string(id, buf));
finish:
free(arg_root);