summaryrefslogtreecommitdiff
path: root/random-seed.c
diff options
context:
space:
mode:
authorAlex Xu (Hello71) <alex_y_xu@yahoo.ca>2018-08-08 17:19:34 -0400
committerAlex Xu (Hello71) <alex_y_xu@yahoo.ca>2018-08-08 17:22:16 -0400
commitca2637e4ddd64a85d7e0300b27b3765906265d7f (patch)
treeb23339c31712bd5180434db3cfb45dfa0f3a2d46 /random-seed.c
parente6f6b0f854e531ce2a96de8b7fa827cbd924da5e (diff)
downloadrandom-seed-ca2637e4ddd64a85d7e0300b27b3765906265d7f.tar.xz
random-seed-ca2637e4ddd64a85d7e0300b27b3765906265d7f.zip
Fix stuff.
Diffstat (limited to 'random-seed.c')
-rw-r--r--random-seed.c36
1 files changed, 11 insertions, 25 deletions
diff --git a/random-seed.c b/random-seed.c
index bc0952f..f33bf02 100644
--- a/random-seed.c
+++ b/random-seed.c
@@ -65,37 +65,24 @@ static inline void usage() {
}
static bool get_machine_id(unsigned char **machine_id) {
-#ifdef HAVE_SYSTEMD
- sd_id128_t raw_machine_id;
- int r = sd_id128_get_machine(&raw_machine_id);
- if (r) {
- fprintf(stderr, "error getting machine id: %s\n", strerror(-r));
- *machine_id = NULL;
- return false;
- }
- *machine_id = malloc(33);
- /* convert to string to be compatible with non-hex machine IDs */
- sd_id128_to_string(raw_machine_id, (char *)*machine_id);
- /* match /etc/machine-id format */
- (*machine_id)[32] = '\n';
-
- return true;
+#ifdef MACHINE_ID_PATH
+ FILE *machine_id_file = fopen(MACHINE_ID_PATH, "r");
#else
- const char *etc_machine_id = SYSCONFDIR "/machine-id";
- const char *var_lib_dbus_machine_id = LOCALSTATEDIR "/lib/dbus/machine-id";
+ const char *etc_machine_id = "/etc/machine-id";
+ const char *var_lib_dbus_machine_id = "/var/lib/dbus/machine-id";
FILE *machine_id_file = fopen(etc_machine_id, "r");
if (!machine_id_file) {
if (errno != ENOENT)
fprintf(stderr, "error opening %s: %s, trying %s\n",
etc_machine_id, strerror(errno), var_lib_dbus_machine_id);
machine_id_file = fopen(var_lib_dbus_machine_id, "r");
- if (!machine_id_file) {
- fprintf(stderr, "couldn't open any machine-id file, last error: "
- "%s; tried: %s, %s\n", strerror(errno), etc_machine_id,
- var_lib_dbus_machine_id);
- *machine_id = NULL;
- return false;
- }
+ }
+#endif
+
+ if (!machine_id_file) {
+ perror("couldn't open any machine-id file, last error");
+ *machine_id = NULL;
+ return false;
}
size_t machine_id_len = 0;
@@ -106,7 +93,6 @@ static bool get_machine_id(unsigned char **machine_id) {
}
return true;
-#endif
}
static bool get_machine_id_hash(const unsigned char salt[static SALT_LEN], unsigned char machine_id_digest[static HASH_LEN]) {