machine-id-setup.c revision a5c32cff1f56afe6f0c6c70d91a88a7a8238b2d7
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen/***
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen This file is part of systemd.
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen Copyright 2010 Lennart Poettering
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen systemd is free software; you can redistribute it and/or modify it
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen under the terms of the GNU Lesser General Public License as published by
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen the Free Software Foundation; either version 2.1 of the License, or
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen (at your option) any later version.
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen systemd is distributed in the hope that it will be useful, but
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen WITHOUT ANY WARRANTY; without even the implied warranty of
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen Lesser General Public License for more details.
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen You should have received a copy of the GNU Lesser General Public License
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen along with systemd; If not, see <http://www.gnu.org/licenses/>.
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen***/
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include <unistd.h>
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include <stdio.h>
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include <errno.h>
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include <string.h>
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include <stdlib.h>
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include <fcntl.h>
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include <sys/mount.h>
f5be560181d092c5f52a2b819aedcd48220f36abTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include <systemd/sd-id128.h>
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include "machine-id-setup.h"
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include "macro.h"
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include "util.h"
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include "mkdir.h"
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen#include "log.h"
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include "virt.h"
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include "fileio.h"
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersenstatic int shorten_uuid(char destination[36], const char *source) {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen unsigned i, j;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen for (i = 0, j = 0; i < 36 && j < 32; i++) {
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen int t;
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen t = unhexchar(source[i]);
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen if (t < 0)
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen continue;
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen destination[j++] = hexchar(t);
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen }
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen if (i == 36 && j == 32) {
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen destination[32] = '\n';
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen destination[33] = 0;
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen return 0;
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen }
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen return -EINVAL;
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen}
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen
02b59d57e0c08231645120077f651151f5bb2babTom Gundersenstatic int generate(char id[34]) {
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen int fd, r;
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen unsigned char *p;
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen sd_id128_t buf;
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen char *q;
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen ssize_t k;
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen const char *vm_id;
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen assert(id);
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen /* First, try reading the D-Bus machine id, unless it is a symlink */
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen fd = open("/var/lib/dbus/machine-id", O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen if (fd >= 0) {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen k = loop_read(fd, id, 32, false);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen close_nointr_nofail(fd);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (k >= 32) {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen id[32] = '\n';
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen id[33] = 0;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen log_info("Initializing machine ID from D-Bus machine ID.");
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen return 0;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen }
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen }
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen
f5be560181d092c5f52a2b819aedcd48220f36abTom Gundersen /* If that didn't work, see if we are running in qemu/kvm and a
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen * machine ID was passed in via -uuid on the qemu/kvm command
f048a16b464295a4e0a4f4c1210f06343ad31231Tom Gundersen * line */
f048a16b464295a4e0a4f4c1210f06343ad31231Tom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen r = detect_vm(&vm_id);
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen if (r > 0 && streq(vm_id, "kvm")) {
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen char uuid[37];
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen fd = open("/sys/class/dmi/id/product_uuid", O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (fd >= 0) {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen k = loop_read(fd, uuid, 36, false);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen close_nointr_nofail(fd);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen if (k >= 36) {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen r = shorten_uuid(id, uuid);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (r >= 0) {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen log_info("Initializing machine ID from KVM UUID.");
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen return 0;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen }
8cd11a0f0f4ca05199e1166f6a07472b296f7455Tom Gundersen }
8cd11a0f0f4ca05199e1166f6a07472b296f7455Tom Gundersen }
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen }
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen /* If that didn't work either, see if we are running in a
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen * container, and a machine ID was passed in via
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen * $container_uuid the way libvirt/LXC does it */
f048a16b464295a4e0a4f4c1210f06343ad31231Tom Gundersen r = detect_container(NULL);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (r > 0) {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen char *e;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen r = getenv_for_pid(1, "container_uuid", &e);
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen if (r > 0) {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (strlen(e) >= 36) {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen r = shorten_uuid(id, e);
b3070dc0258831c7e2b13624f75fa3dbd80d9833Tom Gundersen if (r >= 0) {
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen log_info("Initializing machine ID from container UUID.");
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen free(e);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen return 0;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen }
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen }
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen free(e);
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen }
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen }
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen /* If that didn't work, generate a random machine id */
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen r = sd_id128_randomize(&buf);
f048a16b464295a4e0a4f4c1210f06343ad31231Tom Gundersen if (r < 0) {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen log_error("Failed to open /dev/urandom: %s", strerror(-r));
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen return r;
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersen }
ef1ba6065c6ccea94d4ee867f36df7bbc53a5224Tom Gundersen
ef1ba6065c6ccea94d4ee867f36df7bbc53a5224Tom Gundersen for (p = buf.bytes, q = id; p < buf.bytes + sizeof(buf); p++, q += 2) {
ef1ba6065c6ccea94d4ee867f36df7bbc53a5224Tom Gundersen q[0] = hexchar(*p >> 4);
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersen q[1] = hexchar(*p & 15);
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersen }
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersen
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersen id[32] = '\n';
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersen id[33] = 0;
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen log_info("Initializing machine ID from random generator.");
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen return 0;
0617ffabe86a6d366252477eafbe59a888b149d4Tom Gundersen}
c166a070553511e402de5ad216d3fb62b49bdacbTom Gundersen
8cd11a0f0f4ca05199e1166f6a07472b296f7455Tom Gundersenint machine_id_setup(void) {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen int fd, r;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen bool writable;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen struct stat st;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen char id[34]; /* 32 + \n + \0 */
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersen mode_t m;
f5be560181d092c5f52a2b819aedcd48220f36abTom Gundersen
f5be560181d092c5f52a2b819aedcd48220f36abTom Gundersen m = umask(0000);
f5be560181d092c5f52a2b819aedcd48220f36abTom Gundersen
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersen /* We create this 0444, to indicate that this isn't really
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersen * something you should ever modify. Of course, since the file
f5be560181d092c5f52a2b819aedcd48220f36abTom Gundersen * will be owned by root it doesn't matter much, but maybe
f5be560181d092c5f52a2b819aedcd48220f36abTom Gundersen * people look. */
f5be560181d092c5f52a2b819aedcd48220f36abTom Gundersen
f5be560181d092c5f52a2b819aedcd48220f36abTom Gundersen fd = open("/etc/machine-id", O_RDWR|O_CREAT|O_CLOEXEC|O_NOCTTY, 0444);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (fd >= 0)
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen writable = true;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen else {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen fd = open("/etc/machine-id", O_RDONLY|O_CLOEXEC|O_NOCTTY);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (fd < 0) {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen umask(m);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen log_error("Cannot open /etc/machine-id: %m");
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen return -errno;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen }
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen writable = false;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen }
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen umask(m);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (fstat(fd, &st) < 0) {
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmek log_error("fstat() failed: %m");
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmek r = -errno;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen goto finish;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen }
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (S_ISREG(st.st_mode)) {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (loop_read(fd, id, 32, false) >= 32) {
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen r = 0;
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen goto finish;
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen }
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen }
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen /* Hmm, so, the id currently stored is not useful, then let's
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersen * generate one */
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen r = generate(id);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (r < 0)
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen goto finish;
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen if (S_ISREG(st.st_mode) && writable) {
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen lseek(fd, 0, SEEK_SET);
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen if (loop_write(fd, id, 33, false) == 33) {
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen r = 0;
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen goto finish;
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen }
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen }
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen close_nointr_nofail(fd);
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen fd = -1;
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen /* Hmm, we couldn't write it? So let's write it to
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen * /run/machine-id as a replacement */
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen m = umask(0022);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen r = write_one_line_file("/run/machine-id", id);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen umask(m);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (r < 0) {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen log_error("Cannot write /run/machine-id: %s", strerror(-r));
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen unlink("/run/machine-id");
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen goto finish;
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen }
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen /* And now, let's mount it over */
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen r = mount("/run/machine-id", "/etc/machine-id", NULL, MS_BIND, NULL) < 0 ? -errno : 0;
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen if (r < 0) {
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen unlink("/run/machine-id");
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen log_error("Failed to mount /etc/machine-id: %s", strerror(-r));
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen } else {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen log_info("Installed transient /etc/machine-id file.");
f048a16b464295a4e0a4f4c1210f06343ad31231Tom Gundersen
f048a16b464295a4e0a4f4c1210f06343ad31231Tom Gundersen /* Mark the mount read-only */
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen mount(NULL, "/etc/machine-id", NULL, MS_BIND|MS_RDONLY|MS_REMOUNT, NULL);
f882c247ad59776c3a7753bb963c1f8e2386cb79Tom Gundersen }
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersenfinish:
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen if (fd >= 0)
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen close_nointr_nofail(fd);
71a6151083d842b2f5bf04e50239f0bf85d34d2eTom Gundersen
71a6151083d842b2f5bf04e50239f0bf85d34d2eTom Gundersen return r;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen}
6ae115c1fe95611b39d2f20cfcea3d385429f59eTom Gundersen