summaryrefslogtreecommitdiff
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
parent4b1afed01f092a2c6903b69205ca2ba99ead0d1d (diff)
machine-id-setup: add new --print switch
If specified we'll simply output the used machine ID.
-rw-r--r--man/systemd-machine-id-setup.xml6
-rw-r--r--src/machine-id-setup/machine-id-setup-main.c30
2 files changed, 33 insertions, 3 deletions
diff --git a/man/systemd-machine-id-setup.xml b/man/systemd-machine-id-setup.xml
index bfcd74f436..749987a937 100644
--- a/man/systemd-machine-id-setup.xml
+++ b/man/systemd-machine-id-setup.xml
@@ -151,6 +151,12 @@
early boot service.</para></listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>--print</option></term>
+
+ <listitem><para>Print the machine ID generated or commited after the operation is complete.</para></listitem>
+ </varlistentry>
+
<xi:include href="standard-options.xml" xpointer="help" />
<xi:include href="standard-options.xml" xpointer="version" />
</variablelist>
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);