summaryrefslogtreecommitdiff
path: root/src/core/machine-id-setup.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-01-12 23:30:20 +0100
committerLennart Poettering <lennart@poettering.net>2016-01-12 23:30:20 +0100
commitd9a090b9957b04ec34a145a0a40f41abafe73917 (patch)
tree7441efface736722b60d637133d0e7b6fc80541d /src/core/machine-id-setup.c
parent7e48712407aaee1f5624c0cb2cc16d633cc314d9 (diff)
parentee48dbd55f544d9ee4a17497b5757be7e854c869 (diff)
Merge pull request #490 from pyssling/master
Add machine-id setting
Diffstat (limited to 'src/core/machine-id-setup.c')
-rw-r--r--src/core/machine-id-setup.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/core/machine-id-setup.c b/src/core/machine-id-setup.c
index 145ba2a28d..09b0449c80 100644
--- a/src/core/machine-id-setup.c
+++ b/src/core/machine-id-setup.c
@@ -198,7 +198,7 @@ static int generate_machine_id(char id[34], const char *root) {
return 0;
}
-int machine_id_setup(const char *root) {
+int machine_id_setup(const char *root, sd_id128_t machine_id) {
const char *etc_machine_id, *run_machine_id;
_cleanup_close_ int fd = -1;
bool writable = true;
@@ -248,15 +248,22 @@ int machine_id_setup(const char *root) {
}
}
- if (read_machine_id(fd, id) >= 0)
- return 0;
+ /* A machine id argument overrides all other machined-ids */
+ if (!sd_id128_is_null(machine_id)) {
+ sd_id128_to_string(machine_id, id);
+ id[32] = '\n';
+ id[33] = 0;
+ } else {
+ if (read_machine_id(fd, id) >= 0)
+ return 0;
- /* Hmm, so, the id currently stored is not useful, then let's
- * generate one */
+ /* Hmm, so, the id currently stored is not useful, then let's
+ * generate one */
- r = generate_machine_id(id, root);
- if (r < 0)
- return r;
+ r = generate_machine_id(id, root);
+ if (r < 0)
+ return r;
+ }
if (writable)
if (write_machine_id(fd, id) >= 0)