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) {
fd = -1;
/* Hmm, we couldn't write it? So let's write it to
- * /dev/.systemd/machine-id as a replacement */
+ * /dev/.run/systemd/machine-id as a replacement */
- mkdir_p("/dev/.systemd", 0755);
+ mkdir_p("/dev/.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("/dev/.run/systemd/machine-id", id)) < 0) {
+ log_error("Cannot write /dev/.run/systemd/machine-id: %s", strerror(-r));
- unlink("/dev/.systemd/machine-id");
+ unlink("/dev/.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("/dev/.run/systemd/machine-id", "/etc/machine-id", "bind", MS_BIND|MS_RDONLY, NULL) < 0 ? -errno : 0;
+ unlink("/dev/.run/systemd/machine-id");
if (r < 0)
log_error("Failed to mount /etc/machine-id: %s", strerror(-r));
else
- log_info("Installed non-transient /etc/machine-id file.");
+ log_info("Installed transient /etc/machine-id file.");
finish: