+static char *get_machine_id(void) {
+ int fd;
+ char buf[32];
+
+ fd = open("/etc/machine-id", O_RDONLY|O_CLOEXEC|O_NOCTTY);
+ if (fd == -1 && errno == ENOENT)
+ fd = open("/var/lib/dbus/machine-id", O_RDONLY|O_CLOEXEC|O_NOCTTY);
+ if (fd == -1)
+ return NULL;
+
+ /* File is on a filesystem so we never get EINTR or partial reads */
+ if (read(fd, buf, sizeof buf) != sizeof buf) {
+ close(fd);
+ return NULL;
+ }
+ close(fd);
+
+ /* Contents can be lower, upper and even mixed case so normalize */
+ avahi_strdown(buf);
+
+ return avahi_strndup(buf, sizeof buf);
+}
+