[systemd-commits] 7 commits - .gitignore Makefile-man.am Makefile.am TODO man/systemd-machine-id-commit.service.xml man/systemd-machine-id-commit.xml src/core src/machine-id-commit src/shared units/.gitignore units/systemd-machine-id-commit.service.in

Lennart Poettering lennart at kemper.freedesktop.org
Tue Dec 2 18:43:58 PST 2014


 .gitignore                                 |    1 
 Makefile-man.am                            |    2 
 Makefile.am                                |   17 +++
 TODO                                       |    2 
 man/systemd-machine-id-commit.service.xml  |  101 ++++++++++++++++++++++
 man/systemd-machine-id-commit.xml          |  125 +++++++++++++++++++++++++++
 src/core/machine-id-setup.c                |  133 +++++++++++++++++++++++++----
 src/core/machine-id-setup.h                |    1 
 src/machine-id-commit/Makefile             |    1 
 src/machine-id-commit/machine-id-commit.c  |  105 ++++++++++++++++++++++
 src/shared/util.c                          |    9 +
 src/shared/util.h                          |    2 
 units/.gitignore                           |    1 
 units/systemd-machine-id-commit.service.in |   21 ++++
 14 files changed, 507 insertions(+), 14 deletions(-)

New commits:
commit 2a5a41e86bd908b0182723805ce43a0fc8658899
Author: Didier Roche <didrocks at ubuntu.com>
Date:   Mon Nov 24 11:14:22 2014 +0100

    machine-id-commit: add man pages
    
    Add man pages for systemd-machine-id-commit.service and
    systemd-machine-id-commit.

diff --git a/Makefile-man.am b/Makefile-man.am
index e3c43b2..df40a63 100644
--- a/Makefile-man.am
+++ b/Makefile-man.am
@@ -75,6 +75,7 @@ MANPAGES += \
 	man/systemd-inhibit.1 \
 	man/systemd-initctl.service.8 \
 	man/systemd-journald.service.8 \
+	man/systemd-machine-id-commit.1 \
 	man/systemd-machine-id-setup.1 \
 	man/systemd-notify.1 \
 	man/systemd-nspawn.1 \
@@ -213,6 +214,7 @@ MANPAGES_ALIAS += \
 	man/systemd-journald.8 \
 	man/systemd-journald.socket.8 \
 	man/systemd-kexec.service.8 \
+	man/systemd-machine-id-commit.service.8 \
 	man/systemd-poweroff.service.8 \
 	man/systemd-reboot.service.8 \
 	man/systemd-remount-fs.8 \
diff --git a/man/systemd-machine-id-commit.service.xml b/man/systemd-machine-id-commit.service.xml
new file mode 100644
index 0000000..6da19b9
--- /dev/null
+++ b/man/systemd-machine-id-commit.service.xml
@@ -0,0 +1,101 @@
+<?xml version="1.0"?>
+<!--*-nxml-*-->
+<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
+<!--
+  This file is part of systemd.
+
+  Copyright 2014 Didier Roche
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+-->
+<refentry id="systemd-machine-id-commit.service">
+
+        <refentryinfo>
+                <title>systemd-machine-id-commit.service</title>
+                <productname>systemd</productname>
+
+                <authorgroup>
+                        <author>
+                                <contrib>Developer</contrib>
+                                <firstname>Didier</firstname>
+                                <surname>Roche</surname>
+                                <email>didrocks at ubuntu.com</email>
+                        </author>
+                </authorgroup>
+        </refentryinfo>
+
+        <refmeta>
+                <refentrytitle>systemd-machine-id-commit.service</refentrytitle>
+                <manvolnum>8</manvolnum>
+        </refmeta>
+
+        <refnamediv>
+                <refname>systemd-machine-id-commit.service</refname>
+                <refpurpose>Commit transient machine-id to disk</refpurpose>
+        </refnamediv>
+
+        <refsynopsisdiv>
+                <para><filename>systemd-machine-id-commit.service</filename></para>
+                <para><filename>/usr/lib/systemd/systemd-machine-id-commit</filename></para>
+        </refsynopsisdiv>
+
+        <refsect1>
+                <title>Description</title>
+
+                <para><filename>systemd-machine-id-commit.service</filename> is
+                a service responsible for commiting any transient
+                <filename>/etc/machine-id</filename> file to a writable file
+                system. See
+                <citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry>
+                for more information about this file.</para>
+
+                <para>This service is started shortly after
+                <filename>local-fs.target</filename> if
+                <filename>/etc/machine-id</filename> is an independent mount
+                point (probably a tmpfs one) and /etc is writable.
+                <command>systemd-machine-id-commit</command> will then
+                write current machine ID to disk and unmount the transient
+                <filename>/etc/machine-id</filename> file in a race-free
+                manner to ensure that file is always valid for other
+                processes.</para>
+
+                <para>Note that the traditional way to initialize the machine
+                ID in <filename>/etc/machine-id</filename> is to use
+                <command>systemd-machine-id-setup</command> by system
+                installer tools. You can also use
+                <citerefentry><refentrytitle>systemd-firstboot</refentrytitle><manvolnum>1</manvolnum></citerefentry>
+                to initialize the machine ID on mounted (but not
+                booted) system images. The main use case for that service is
+                <filename>/etc/machine-id</filename> being an empty file at
+                boot and initrd chaining to systemd giving it a read only file
+                system that will be turned read-write later during the boot
+                process.</para>
+
+                <para>There is no consequence if that service fails other than
+                a newer machine-id will be generated during next system boot.
+                </para>
+        </refsect1>
+
+        <refsect1>
+                <title>See Also</title>
+                <para>
+                        <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
+                        <citerefentry><refentrytitle>systemd-machine-id-commit</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
+                        <citerefentry><refentrytitle>systemd-machine-id-setup</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
+                        <citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
+                        <citerefentry><refentrytitle>systemd-firstboot</refentrytitle><manvolnum>1</manvolnum></citerefentry>
+                </para>
+        </refsect1>
+
+</refentry>
diff --git a/man/systemd-machine-id-commit.xml b/man/systemd-machine-id-commit.xml
new file mode 100644
index 0000000..ed2a6d0
--- /dev/null
+++ b/man/systemd-machine-id-commit.xml
@@ -0,0 +1,125 @@
+<?xml version='1.0'?> <!--*-nxml-*-->
+<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
+        "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
+
+<!--
+  This file is part of systemd.
+
+  Copyright 2014 Didier Roche
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+-->
+
+<refentry id="systemd-machine-id-commit"
+          xmlns:xi="http://www.w3.org/2001/XInclude">
+
+        <refentryinfo>
+                <title>systemd-machine-id-commit</title>
+                <productname>systemd</productname>
+
+                <authorgroup>
+                        <author>
+                                <contrib>Developer</contrib>
+                                <firstname>Didier</firstname>
+                                <surname>Roche</surname>
+                                <email>didrocks at ubuntu.com</email>
+                        </author>
+                </authorgroup>
+        </refentryinfo>
+
+        <refmeta>
+                <refentrytitle>systemd-machine-id-commit</refentrytitle>
+                <manvolnum>1</manvolnum>
+        </refmeta>
+
+        <refnamediv>
+                <refname>systemd-machine-id-commit</refname>
+                <refpurpose>Commit transient machine ID to /etc/machine-id</refpurpose>
+        </refnamediv>
+
+        <refsynopsisdiv>
+                <cmdsynopsis>
+                        <command>systemd-machine-id-commit</command>
+                </cmdsynopsis>
+        </refsynopsisdiv>
+
+        <refsect1>
+                <title>Description</title>
+
+                <para><command>systemd-machine-id-commit</command> may
+                be used to write on disk any transient machine ID
+                mounted as a temporary file system in
+                <filename>/etc/machine-id</filename> at boot time. See
+                <citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry>
+                for more information about this file.</para>
+
+                <para>This tool will execute no operation if
+                <filename>/etc/machine-id</filename> doesn't contain any
+                valid machine ID, isn't mounted as an independent temporary
+			    file system, of <filename>/etc</filename> is read-only. If
+                those conditions are met, it will then write current machine ID
+                to disk and unmount the transient
+                <filename>/etc/machine-id</filename> file in a race-free
+                manner to ensure that this file is always valid for other
+                processes.</para>
+
+                <para>Note that the traditional way to initialize the machine
+                ID in <filename>/etc/machine-id</filename> is to use
+                <command>systemd-machine-id-setup</command> by system
+                installer tools. You can also use
+                <citerefentry><refentrytitle>systemd-firstboot</refentrytitle><manvolnum>1</manvolnum></citerefentry>
+                to initialize the machine ID on mounted (but not
+                booted) system images.</para>
+        </refsect1>
+
+        <refsect1>
+                <title>Options</title>
+
+                <para>The following options are understood:</para>
+
+                <variablelist>
+                        <varlistentry>
+                                <term><option>--root=<replaceable>root</replaceable></option></term>
+                                <listitem><para>Takes a directory path
+                                as an argument. All paths will be
+                                prefixed with the given alternate
+                                <replaceable>root</replaceable> path,
+                                including config search paths.
+                                </para></listitem>
+                        </varlistentry>
+                        <xi:include href="standard-options.xml" xpointer="help" />
+                        <xi:include href="standard-options.xml" xpointer="version" />
+                </variablelist>
+
+        </refsect1>
+
+        <refsect1>
+                <title>Exit status</title>
+
+                <para>On success, 0 is returned, a non-zero failure
+                code otherwise.</para>
+        </refsect1>
+
+        <refsect1>
+                <title>See Also</title>
+                <para>
+                        <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
+                        <citerefentry><refentrytitle>systemd-machine-id-commit.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
+                        <citerefentry><refentrytitle>systemd-machine-id-setup</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
+                        <citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
+                        <citerefentry><refentrytitle>systemd-firstboot</refentrytitle><manvolnum>1</manvolnum></citerefentry>
+                </para>
+        </refsect1>
+
+</refentry>

commit a1405db67c9fa6e8d734933cc7dd208bdb703cae
Author: Didier Roche <didrocks at ubuntu.com>
Date:   Mon Nov 24 10:12:06 2014 +0100

    machine-id-commit: add unit file
    
    The unit file only active the machine-id-commit helper if /etc is mounted
    writable and /etc/machine-id is an independant mount point (should be a tmpfs).

diff --git a/Makefile.am b/Makefile.am
index 2efd033..5b46243 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -537,6 +537,7 @@ nodist_systemunit_DATA = \
 	units/systemd-kexec.service \
 	units/systemd-fsck at .service \
 	units/systemd-fsck-root.service \
+	units/systemd-machine-id-commit.service \
 	units/systemd-udevd.service \
 	units/systemd-udev-trigger.service \
 	units/systemd-udev-settle.service \
@@ -589,6 +590,7 @@ EXTRA_DIST += \
 	units/user/systemd-exit.service.in \
 	units/systemd-fsck at .service.in \
 	units/systemd-fsck-root.service.in \
+	units/systemd-machine-id-commit.service.in \
 	units/user at .service.in \
 	units/debug-shell.service.in \
 	units/systemd-suspend.service.in \
@@ -2227,6 +2229,9 @@ systemd_machine_id_commit_LDADD = \
 	libsystemd-internal.la \
 	libsystemd-shared.la
 
+SYSINIT_TARGET_WANTS += \
+	systemd-machine-id-commit.service
+
 # ------------------------------------------------------------------------------
 systemd_ac_power_SOURCES = \
 	src/ac-power/ac-power.c
diff --git a/units/.gitignore b/units/.gitignore
index a1276e5..e12d299 100644
--- a/units/.gitignore
+++ b/units/.gitignore
@@ -25,6 +25,7 @@
 /systemd-firstboot.service
 /systemd-fsck-root.service
 /systemd-fsck at .service
+/systemd-machine-id-commit.service
 /systemd-halt.service
 /systemd-hibernate.service
 /systemd-hostnamed.service
diff --git a/units/systemd-machine-id-commit.service.in b/units/systemd-machine-id-commit.service.in
new file mode 100644
index 0000000..dd765b6
--- /dev/null
+++ b/units/systemd-machine-id-commit.service.in
@@ -0,0 +1,21 @@
+#  This file is part of systemd.
+#
+#  systemd is free software; you can redistribute it and/or modify it
+#  under the terms of the GNU Lesser General Public License as published by
+#  the Free Software Foundation; either version 2.1 of the License, or
+#  (at your option) any later version.
+
+[Unit]
+Description=Commit a transient machine-id on disk
+Documentation=man:systemd-machine-id-commit.service(8)
+DefaultDependencies=no
+Conflicts=shutdown.target
+Before=sysinit.target shutdown.target
+After=local-fs.target
+ConditionPathIsReadWrite=/etc
+ConditionPathIsMountPoint=/etc/machine-id
+
+[Service]
+Type=oneshot
+RemainAfterExit=yes
+ExecStart=@rootlibexecdir@/systemd-machine-id-commit

commit 3fb394369ccd6787f8f883e0f81dc7f35cb1ec51
Author: Didier Roche <didrocks at ubuntu.com>
Date:   Mon Nov 24 09:54:18 2014 +0100

    machine-id-commit: Introduce machine-id-commit binary
    
    This binary enables to commit transient machine-id on disk if it becomes
    writable.

diff --git a/.gitignore b/.gitignore
index e5953d3..4e7ad2a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -90,6 +90,7 @@
 /systemd-kmsg-syslogd
 /systemd-localed
 /systemd-logind
+/systemd-machine-id-commit
 /systemd-machine-id-setup
 /systemd-machined
 /systemd-modeset
diff --git a/Makefile.am b/Makefile.am
index 46a838d..2efd033 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -385,6 +385,7 @@ rootlibexec_PROGRAMS = \
 	systemd-remount-fs \
 	systemd-reply-password \
 	systemd-fsck \
+	systemd-machine-id-commit \
 	systemd-ac-power \
 	systemd-sysctl \
 	systemd-sleep \
@@ -2216,6 +2217,17 @@ systemd_fsck_LDADD = \
 	libsystemd-shared.la
 
 # ------------------------------------------------------------------------------
+systemd_machine_id_commit_SOURCES = \
+	src/machine-id-commit/machine-id-commit.c \
+	src/core/machine-id-setup.c \
+	src/core/machine-id-setup.h
+
+systemd_machine_id_commit_LDADD = \
+	libsystemd-label.la \
+	libsystemd-internal.la \
+	libsystemd-shared.la
+
+# ------------------------------------------------------------------------------
 systemd_ac_power_SOURCES = \
 	src/ac-power/ac-power.c
 
diff --git a/src/machine-id-commit/Makefile b/src/machine-id-commit/Makefile
new file mode 120000
index 0000000..d0b0e8e
--- /dev/null
+++ b/src/machine-id-commit/Makefile
@@ -0,0 +1 @@
+../Makefile
\ No newline at end of file
diff --git a/src/machine-id-commit/machine-id-commit.c b/src/machine-id-commit/machine-id-commit.c
new file mode 100644
index 0000000..c7e4de8
--- /dev/null
+++ b/src/machine-id-commit/machine-id-commit.c
@@ -0,0 +1,105 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+  This file is part of systemd.
+
+  Copyright 2014 Didier Roche
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <getopt.h>
+#include <errno.h>
+
+#include "machine-id-setup.h"
+#include "log.h"
+#include "build.h"
+
+static const char *arg_root = "";
+
+static void help(void) {
+        printf("%s [OPTIONS...]\n\n"
+               "Commit a transient /etc/machine-id on disk if writable.\n\n"
+               "  -h --help             Show this help\n"
+               "     --version          Show package version\n"
+               "     --root=ROOT        Filesystem root\n",
+               program_invocation_short_name);
+}
+
+static int parse_argv(int argc, char *argv[]) {
+
+        enum {
+                ARG_VERSION = 0x100,
+                ARG_ROOT,
+        };
+
+        static const struct option options[] = {
+                { "help",      no_argument,       NULL, 'h'           },
+                { "version",   no_argument,       NULL, ARG_VERSION   },
+                { "root",      required_argument, NULL, ARG_ROOT      },
+                {}
+        };
+
+        int c;
+
+        assert(argc >= 0);
+        assert(argv);
+
+        while ((c = getopt_long(argc, argv, "hqcv", options, NULL)) >= 0)
+                switch (c) {
+
+                case 'h':
+                        help();
+                        return 0;
+
+                case ARG_VERSION:
+                        puts(PACKAGE_STRING);
+                        puts(SYSTEMD_FEATURES);
+                        return 0;
+
+                case ARG_ROOT:
+                        arg_root = optarg;
+                        break;
+
+                case '?':
+                        return -EINVAL;
+
+                default:
+                        assert_not_reached("Unhandled option");
+                }
+
+        if (optind < argc) {
+                log_error("Extraneous arguments");
+                return -EINVAL;
+        }
+
+        return 1;
+}
+
+int main(int argc, char *argv[]) {
+        int r;
+
+        log_set_target(LOG_TARGET_AUTO);
+        log_parse_environment();
+        log_open();
+
+        r = parse_argv(argc, argv);
+        if (r <= 0)
+                return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
+
+        return machine_id_commit(arg_root) < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
+}

commit 979ef53a268d6f54a309fc5c6015df5d4accbbd5
Author: Didier Roche <didrocks at ubuntu.com>
Date:   Mon Nov 24 09:43:29 2014 +0100

    machine-id-setup: add a machine_id_commit call to commit on disk a transient machine-id
    
    If /etc was read only at boot time with an empty /etc/machine-id, the latter
    will be mounted as a tmpfs and get reset at each boot. If the system becomes rw
    later, this functionality enables to commit in a race-free manner the
    transient machine-id to disk.

diff --git a/src/core/machine-id-setup.c b/src/core/machine-id-setup.c
index d8600bd..74582a5 100644
--- a/src/core/machine-id-setup.c
+++ b/src/core/machine-id-setup.c
@@ -188,6 +188,85 @@ static int write_machine_id(int fd, char id[34]) {
         return -errno;
 }
 
+int machine_id_commit(const char *root) {
+        _cleanup_close_ int fd = -1, initial_mntns_fd = -1;
+        const char *etc_machine_id;
+        char id[34]; /* 32 + \n + \0 */
+        int r;
+
+        if (isempty(root))
+                etc_machine_id = "/etc/machine-id";
+        else {
+                char *x;
+
+                x = strappenda(root, "/etc/machine-id");
+                etc_machine_id = path_kill_slashes(x);
+        }
+
+        r = path_is_mount_point(etc_machine_id, false);
+        if (r < 0)
+                return log_error_errno(r, "Failed to determine wether %s is a mount point: %m", etc_machine_id);
+        if (r == 0) {
+                log_debug("%s is is not a mount point. Nothing to do.", etc_machine_id);
+                return 0;
+        }
+
+        /* Read existing machine-id */
+        fd = open(etc_machine_id, O_RDONLY|O_CLOEXEC|O_NOCTTY);
+        if (fd < 0)
+                return log_error_errno(errno, "Cannot open %s: %m", etc_machine_id);
+
+        r = get_valid_machine_id(fd, id);
+        if (r < 0)
+                return log_error_errno(r, "We didn't find a valid machine ID in %s.", etc_machine_id);
+
+        r = is_fd_on_temporary_fs(fd);
+        if (r < 0)
+                return log_error_errno(r, "Failed to determine whether %s is on a temporary file system: %m", etc_machine_id);
+        if (r == 0) {
+                log_error("%s is not on a temporary file system.", etc_machine_id);
+                return -EROFS;
+        }
+
+        fd = safe_close(fd);
+
+        /* Store current mount namespace */
+        r = namespace_open(0, NULL, &initial_mntns_fd, NULL, NULL);
+        if (r < 0)
+                return log_error_errno(r, "Can't fetch current mount namespace: %m");
+
+        /* Switch to a new mount namespace, isolate ourself and unmount etc_machine_id in our new namespace */
+        if (unshare(CLONE_NEWNS) < 0)
+                return log_error_errno(errno, "Failed to enter new namespace: %m");
+
+        if (mount(NULL, "/", NULL, MS_SLAVE | MS_REC, NULL) < 0)
+                return log_error_errno(errno, "Couldn't make-rslave / mountpoint in our private namespace: %m");
+
+        if (umount(etc_machine_id) < 0)
+                return log_error_errno(errno, "Failed to unmount transient %s file in our private namespace: %m", etc_machine_id);
+
+        /* Update a persistent version of etc_machine_id */
+        fd = open(etc_machine_id, O_RDWR|O_CREAT|O_CLOEXEC|O_NOCTTY, 0444);
+        if (fd < 0)
+                return log_error_errno(errno, "Cannot open for writing %s. This is mandatory to get a persistent machine-id: %m", etc_machine_id);
+
+        r = write_machine_id(fd, id);
+        if (r < 0)
+                return log_error_errno(r, "Cannot write %s: %m", etc_machine_id);
+
+        fd = safe_close(fd);
+
+        /* Return to initial namespace and proceed a lazy tmpfs unmount */
+        r = namespace_enter(-1, initial_mntns_fd, -1, -1);
+        if (r < 0)
+                return log_warning_errno(r, "Failed to switch back to initial mount namespace: %m.\nWe'll keep transient %s file until next reboot.", etc_machine_id);
+
+        if (umount2(etc_machine_id, MNT_DETACH) < 0)
+                return log_warning_errno(errno, "Failed to unmount transient %s file: %m.\nWe keep that mount until next reboot.", etc_machine_id);
+
+        return 0;
+}
+
 int machine_id_setup(const char *root) {
         const char *etc_machine_id, *run_machine_id;
         _cleanup_close_ int fd = -1;
diff --git a/src/core/machine-id-setup.h b/src/core/machine-id-setup.h
index b0583ee..f7707c3 100644
--- a/src/core/machine-id-setup.h
+++ b/src/core/machine-id-setup.h
@@ -21,4 +21,5 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+int machine_id_commit(const char *root);
 int machine_id_setup(const char *root);
diff --git a/src/shared/util.c b/src/shared/util.c
index 2165170..4fcbab9 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -3052,6 +3052,15 @@ _pure_ static int is_temporary_fs(struct statfs *s) {
                F_TYPE_EQUAL(s->f_type, RAMFS_MAGIC);
 }
 
+int is_fd_on_temporary_fs(int fd) {
+        struct statfs s;
+
+        if (fstatfs(fd, &s) < 0)
+                return -errno;
+
+        return is_temporary_fs(&s);
+}
+
 int rm_rf_children(int fd, bool only_dirs, bool honour_sticky, struct stat *root_dev) {
         struct statfs s;
 
diff --git a/src/shared/util.h b/src/shared/util.h
index b53a45d..0b7c77b 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -454,6 +454,8 @@ int get_ctty(pid_t, dev_t *_devnr, char **r);
 int chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid);
 int fchmod_and_fchown(int fd, mode_t mode, uid_t uid, gid_t gid);
 
+int is_fd_on_temporary_fs(int fd);
+
 int rm_rf_children(int fd, bool only_dirs, bool honour_sticky, struct stat *root_dev);
 int rm_rf_children_dangerous(int fd, bool only_dirs, bool honour_sticky, struct stat *root_dev);
 int rm_rf(const char *path, bool only_dirs, bool delete_root, bool honour_sticky);

commit 3543f8218b732132dff6d0dccb2ce357e4154801
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Dec 3 03:13:34 2014 +0100

    machine-id-setup: casting const away is ugly, let's not do it if there's no reason to

diff --git a/src/core/machine-id-setup.c b/src/core/machine-id-setup.c
index 77f047d..d8600bd 100644
--- a/src/core/machine-id-setup.c
+++ b/src/core/machine-id-setup.c
@@ -200,11 +200,13 @@ int machine_id_setup(const char *root) {
                 etc_machine_id = "/etc/machine-id";
                 run_machine_id = "/run/machine-id";
         } else {
-                etc_machine_id = strappenda(root, "/etc/machine-id");
-                path_kill_slashes((char*) etc_machine_id);
+                char *x;
 
-                run_machine_id = strappenda(root, "/run/machine-id");
-                path_kill_slashes((char*) run_machine_id);
+                x = strappenda(root, "/etc/machine-id");
+                etc_machine_id = path_kill_slashes(x);
+
+                x = strappenda(root, "/run/machine-id");
+                run_machine_id = path_kill_slashes(x);
         }
 
         RUN_WITH_UMASK(0000) {

commit 41114e81b562bcee52be1ef94c684ace2362ca54
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Dec 3 03:13:14 2014 +0100

    update TODO

diff --git a/TODO b/TODO
index 20591e3..39a9840 100644
--- a/TODO
+++ b/TODO
@@ -35,6 +35,8 @@ External:
 
 Features:
 
+* set $REMOTE_IP (or $REMOTE_ADDR/$REMOTE_PORT) environment variable when doing per-connection socket activation. use format introduced by xinetd or CGI for this
+
 * the install state probably shouldn't get confused by generated units, think dbus1/kdbus compat!
 
 * revisit rfkill. the rfkill device names are counted up, and not stable. instead: store per kind of device together with PCI path, ignore the device name.

commit 9496e375f7274e7d0f61f8e9d6a001b9f2dc579b
Author: Didier Roche <didrocks at ubuntu.com>
Date:   Mon Nov 24 09:40:57 2014 +0100

    machine-id-setup: Factorize some machine-id-setup functions to be reused

diff --git a/src/core/machine-id-setup.c b/src/core/machine-id-setup.c
index 6710038..77f047d 100644
--- a/src/core/machine-id-setup.c
+++ b/src/core/machine-id-setup.c
@@ -157,6 +157,37 @@ static int generate(char id[34], const char *root) {
         return 0;
 }
 
+static int get_valid_machine_id(int fd, char id[34]) {
+        char id_to_validate[34];
+
+        assert(fd >= 0);
+        assert(id);
+
+        if (loop_read(fd, id_to_validate, 33, false) == 33 && id_to_validate[32] == '\n') {
+                id_to_validate[32] = 0;
+
+                if (id128_is_valid(id_to_validate)) {
+                        memcpy(id, id_to_validate, 32);
+                        id[32] = '\n';
+                        id[33] = 0;
+                        return 0;
+                }
+        }
+
+        return -EINVAL;
+}
+
+static int write_machine_id(int fd, char id[34]) {
+        assert(fd >= 0);
+        assert(id);
+        lseek(fd, 0, SEEK_SET);
+
+        if (loop_write(fd, id, 33, false) == 33)
+                return 0;
+
+        return -errno;
+}
+
 int machine_id_setup(const char *root) {
         const char *etc_machine_id, *run_machine_id;
         _cleanup_close_ int fd = -1;
@@ -207,13 +238,8 @@ int machine_id_setup(const char *root) {
         if (fstat(fd, &st) < 0)
                 return log_error_errno(errno, "fstat() failed: %m");
 
-        if (S_ISREG(st.st_mode))
-                if (loop_read(fd, id, 33, false) == 33 && id[32] == '\n') {
-                        id[32] = 0;
-
-                        if (id128_is_valid(id))
-                                return 0;
-                }
+        if (S_ISREG(st.st_mode) && get_valid_machine_id(fd, id) == 0)
+                return 0;
 
         /* Hmm, so, the id currently stored is not useful, then let's
          * generate one */
@@ -223,9 +249,7 @@ int machine_id_setup(const char *root) {
                 return r;
 
         if (S_ISREG(st.st_mode) && writable) {
-                lseek(fd, 0, SEEK_SET);
-
-                if (loop_write(fd, id, 33, false) == 33)
+                if (write_machine_id(fd, id) == 0)
                         return 0;
         }
 



More information about the systemd-commits mailing list