X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fmachine-id-setup.c;h=98e288e1b5c01e64690eed40800c4b910d0cc29e;hp=0ec61924492e3060321f4e745243264f29de0c8c;hb=7a41c61168632501489a4d054619b86f529a02e7;hpb=9b4f818bd8dd45029992f844d07a61c9977da720 diff --git a/src/machine-id-setup.c b/src/machine-id-setup.c index 0ec619244..98e288e1b 100644 --- a/src/machine-id-setup.c +++ b/src/machine-id-setup.c @@ -91,7 +91,12 @@ int machine_id_setup(void) { m = umask(0000); - if ((fd = open("/etc/machine-id", O_RDWR|O_CREAT|O_CLOEXEC|O_NOCTTY, 0644)) >= 0) + /* We create this 0444, to indicate that this isn't really + * something you should ever modify. Of course, since the file + * will be owned by root it doesn't matter much, but maybe + * people look. */ + + if ((fd = open("/etc/machine-id", O_RDWR|O_CREAT|O_CLOEXEC|O_NOCTTY, 0444)) >= 0) writable = true; else { if ((fd = open("/etc/machine-id", O_RDONLY|O_CLOEXEC|O_NOCTTY)) < 0) { @@ -137,20 +142,20 @@ int machine_id_setup(void) { fd = -1; /* Hmm, we couldn't write it? So let's write it to - * /dev/.systemd/machine-id as a replacement */ + * /run/systemd/machine-id as a replacement */ - mkdir_p("/dev/.systemd", 0755); + mkdir_p("/run/systemd", 0755); - if ((r = write_one_line_file("/dev/.systemd/machine-id", id)) < 0) { - log_error("Cannot write /dev/.systemd/machine-id: %s", strerror(-r)); + if ((r = write_one_line_file("/run/systemd/machine-id", id)) < 0) { + log_error("Cannot write /run/systemd/machine-id: %s", strerror(-r)); - unlink("/dev/.systemd/machine-id"); + unlink("/run/systemd/machine-id"); goto finish; } /* And now, let's mount it over */ - r = mount("/dev/.systemd/machine-id", "/etc/machine-id", "bind", MS_BIND|MS_RDONLY, NULL) < 0 ? -errno : 0; - unlink("/dev/.systemd/machine-id"); + r = mount("/run/systemd/machine-id", "/etc/machine-id", "bind", MS_BIND|MS_RDONLY, NULL) < 0 ? -errno : 0; + unlink("/run/systemd/machine-id"); if (r < 0) log_error("Failed to mount /etc/machine-id: %s", strerror(-r));