[systemd-commits] 4 commits - man/systemd-machine-id-setup.xml man/systemd-tmpfiles.xml src/binfmt src/core src/machine-id-setup src/modules-load src/network src/shared src/sysctl src/tmpfiles

Zbigniew Jędrzejewski-Szmek zbyszek at kemper.freedesktop.org
Fri Mar 14 06:23:21 PDT 2014


 man/systemd-machine-id-setup.xml             |    7 ++++---
 man/systemd-tmpfiles.xml                     |   12 ++++++++++--
 src/binfmt/binfmt.c                          |    2 +-
 src/core/machine-id-setup.c                  |   12 ++++++------
 src/core/socket.c                            |    8 +++-----
 src/machine-id-setup/machine-id-setup-main.c |    4 ++--
 src/modules-load/modules-load.c              |    2 +-
 src/network/networkd-link.c                  |   12 ++++++------
 src/shared/util.c                            |   12 ++++++------
 src/shared/util.h                            |    4 ++--
 src/sysctl/sysctl.c                          |    2 +-
 src/tmpfiles/tmpfiles.c                      |   27 ++++++++++++++++++++++++---
 12 files changed, 66 insertions(+), 38 deletions(-)

New commits:
commit cf9a4abdc24c43565d0890fcb88c00169057c0c4
Author: Michael Marineau <michael.marineau at coreos.com>
Date:   Thu Mar 13 21:32:13 2014 -0700

    tmpfiles: add --root option to operate on an alternate fs tree
    
    This makes it possible to initialize or cleanup an arbitrary filesystem
    hierarchy in the same way that it would be during system boot.

diff --git a/man/systemd-tmpfiles.xml b/man/systemd-tmpfiles.xml
index 0b62640..fad2cbb 100644
--- a/man/systemd-tmpfiles.xml
+++ b/man/systemd-tmpfiles.xml
@@ -139,19 +139,27 @@
                                 </para></listitem>
                         </varlistentry>
                         <varlistentry>
-                                <term><option>--prefix=PATH</option></term>
+                                <term><option>--prefix=<replaceable>path</replaceable></option></term>
                                 <listitem><para>Only apply rules that
                                 apply to paths with the specified
                                 prefix. This option can be specified
                                 multiple times.</para></listitem>
                         </varlistentry>
                         <varlistentry>
-                                <term><option>--exclude-prefix=PATH</option></term>
+                                <term><option>--exclude-prefix=<replaceable>path</replaceable></option></term>
                                 <listitem><para>Ignore rules that
                                 apply to paths with the specified
                                 prefix. This option can be specified
                                 multiple times.</para></listitem>
                         </varlistentry>
+                        <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" />
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index 3684289..52f8037 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -111,6 +111,7 @@ static bool arg_boot = false;
 
 static char **include_prefixes = NULL;
 static char **exclude_prefixes = NULL;
+static char *arg_root = NULL;
 
 static const char conf_file_dirs[] =
         "/etc/tmpfiles.d\0"
@@ -1188,6 +1189,15 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
         if (!should_include_path(i->path))
                 return 0;
 
+        if (arg_root) {
+                char *p = strappend(arg_root, i->path);
+                if (!p)
+                        return log_oom();
+
+                free(i->path);
+                i->path = p;
+        }
+
         if (user && !streq(user, "-")) {
                 const char *u = user;
 
@@ -1277,7 +1287,8 @@ static int help(void) {
                "     --remove               Remove marked files/directories\n"
                "     --boot                 Execute actions only safe at boot\n"
                "     --prefix=PATH          Only apply rules that apply to paths with the specified prefix\n"
-               "     --exclude-prefix=PATH  Ignore rules that apply to paths with the specified prefix\n",
+               "     --exclude-prefix=PATH  Ignore rules that apply to paths with the specified prefix\n"
+               "     --root=PATH            Operate on an alternate filesystem root\n",
                program_invocation_short_name);
 
         return 0;
@@ -1293,6 +1304,7 @@ static int parse_argv(int argc, char *argv[]) {
                 ARG_BOOT,
                 ARG_PREFIX,
                 ARG_EXCLUDE_PREFIX,
+                ARG_ROOT,
         };
 
         static const struct option options[] = {
@@ -1304,6 +1316,7 @@ static int parse_argv(int argc, char *argv[]) {
                 { "boot",           no_argument,         NULL, ARG_BOOT           },
                 { "prefix",         required_argument,   NULL, ARG_PREFIX         },
                 { "exclude-prefix", required_argument,   NULL, ARG_EXCLUDE_PREFIX },
+                { "root",           required_argument,   NULL, ARG_ROOT           },
                 {}
         };
 
@@ -1350,6 +1363,13 @@ static int parse_argv(int argc, char *argv[]) {
                                 return log_oom();
                         break;
 
+                case ARG_ROOT:
+                        arg_root = path_make_absolute_cwd(optarg);
+                        if (!arg_root)
+                                return log_oom();
+                        path_kill_slashes(arg_root);
+                        break;
+
                 case '?':
                         return -EINVAL;
 
@@ -1376,7 +1396,7 @@ static int read_config_file(const char *fn, bool ignore_enoent) {
 
         assert(fn);
 
-        r = search_and_fopen_nulstr(fn, "re", NULL, conf_file_dirs, &f);
+        r = search_and_fopen_nulstr(fn, "re", arg_root, conf_file_dirs, &f);
         if (r < 0) {
                 if (ignore_enoent && r == -ENOENT)
                         return 0;
@@ -1477,7 +1497,7 @@ int main(int argc, char *argv[]) {
                 _cleanup_strv_free_ char **files = NULL;
                 char **f;
 
-                r = conf_files_list_nulstr(&files, ".conf", NULL, conf_file_dirs);
+                r = conf_files_list_nulstr(&files, ".conf", arg_root, conf_file_dirs);
                 if (r < 0) {
                         log_error("Failed to enumerate tmpfiles.d files: %s", strerror(-r));
                         goto finish;
@@ -1508,6 +1528,7 @@ finish:
 
         free(include_prefixes);
         free(exclude_prefixes);
+        free(arg_root);
 
         set_free_free(unix_sockets);
 

commit 4cf7ea556aa1e74f9b34d4467f36d46a1bb25da3
Author: Michael Marineau <michael.marineau at coreos.com>
Date:   Thu Mar 13 21:32:12 2014 -0700

    shared: add root argument to search_and_fopen
    
    This adds the same root argument to search_and_fopen that
    conf_files_list already has. Tools that use those two functions as a
    pair can now be easily modified to load configuration files from an
    alternate root filesystem tree.

diff --git a/src/binfmt/binfmt.c b/src/binfmt/binfmt.c
index a1877c4..9fc5d4e 100644
--- a/src/binfmt/binfmt.c
+++ b/src/binfmt/binfmt.c
@@ -86,7 +86,7 @@ static int apply_file(const char *path, bool ignore_enoent) {
 
         assert(path);
 
-        r = search_and_fopen_nulstr(path, "re", conf_file_dirs, &f);
+        r = search_and_fopen_nulstr(path, "re", NULL, conf_file_dirs, &f);
         if (r < 0) {
                 if (ignore_enoent && r == -ENOENT)
                         return 0;
diff --git a/src/modules-load/modules-load.c b/src/modules-load/modules-load.c
index 49b153d..ecb84da 100644
--- a/src/modules-load/modules-load.c
+++ b/src/modules-load/modules-load.c
@@ -145,7 +145,7 @@ static int apply_file(struct kmod_ctx *ctx, const char *path, bool ignore_enoent
         assert(ctx);
         assert(path);
 
-        r = search_and_fopen_nulstr(path, "re", conf_file_dirs, &f);
+        r = search_and_fopen_nulstr(path, "re", NULL, conf_file_dirs, &f);
         if (r < 0) {
                 if (ignore_enoent && r == -ENOENT)
                         return 0;
diff --git a/src/shared/util.c b/src/shared/util.c
index 9e8cd54..8b8d2fb 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -5668,14 +5668,14 @@ int on_ac_power(void) {
         return found_online || !found_offline;
 }
 
-static int search_and_fopen_internal(const char *path, const char *mode, char **search, FILE **_f) {
+static int search_and_fopen_internal(const char *path, const char *mode, const char *root, char **search, FILE **_f) {
         char **i;
 
         assert(path);
         assert(mode);
         assert(_f);
 
-        if (!path_strv_canonicalize_absolute_uniq(search, NULL))
+        if (!path_strv_canonicalize_absolute_uniq(search, root))
                 return -ENOMEM;
 
         STRV_FOREACH(i, search) {
@@ -5699,7 +5699,7 @@ static int search_and_fopen_internal(const char *path, const char *mode, char **
         return -ENOENT;
 }
 
-int search_and_fopen(const char *path, const char *mode, const char **search, FILE **_f) {
+int search_and_fopen(const char *path, const char *mode, const char *root, const char **search, FILE **_f) {
         _cleanup_strv_free_ char **copy = NULL;
 
         assert(path);
@@ -5722,10 +5722,10 @@ int search_and_fopen(const char *path, const char *mode, const char **search, FI
         if (!copy)
                 return -ENOMEM;
 
-        return search_and_fopen_internal(path, mode, copy, _f);
+        return search_and_fopen_internal(path, mode, root, copy, _f);
 }
 
-int search_and_fopen_nulstr(const char *path, const char *mode, const char *search, FILE **_f) {
+int search_and_fopen_nulstr(const char *path, const char *mode, const char *root, const char *search, FILE **_f) {
         _cleanup_strv_free_ char **s = NULL;
 
         if (path_is_absolute(path)) {
@@ -5744,7 +5744,7 @@ int search_and_fopen_nulstr(const char *path, const char *mode, const char *sear
         if (!s)
                 return -ENOMEM;
 
-        return search_and_fopen_internal(path, mode, s, _f);
+        return search_and_fopen_internal(path, mode, root, s, _f);
 }
 
 char *strextend(char **x, ...) {
diff --git a/src/shared/util.h b/src/shared/util.h
index 81831e2..e99f8d1 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -696,8 +696,8 @@ char *strip_tab_ansi(char **p, size_t *l);
 
 int on_ac_power(void);
 
-int search_and_fopen(const char *path, const char *mode, const char **search, FILE **_f);
-int search_and_fopen_nulstr(const char *path, const char *mode, const char *search, FILE **_f);
+int search_and_fopen(const char *path, const char *mode, const char *root, const char **search, FILE **_f);
+int search_and_fopen_nulstr(const char *path, const char *mode, const char *root, const char *search, FILE **_f);
 
 #define FOREACH_LINE(line, f, on_error)                         \
         for (;;)                                                \
diff --git a/src/sysctl/sysctl.c b/src/sysctl/sysctl.c
index 76efacb..8868732 100644
--- a/src/sysctl/sysctl.c
+++ b/src/sysctl/sysctl.c
@@ -123,7 +123,7 @@ static int parse_file(Hashmap *sysctl_options, const char *path, bool ignore_eno
 
         assert(path);
 
-        r = search_and_fopen_nulstr(path, "re", conf_file_dirs, &f);
+        r = search_and_fopen_nulstr(path, "re", NULL, conf_file_dirs, &f);
         if (r < 0) {
                 if (ignore_enoent && r == -ENOENT)
                         return 0;
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index 6e36dc7..3684289 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -1376,7 +1376,7 @@ static int read_config_file(const char *fn, bool ignore_enoent) {
 
         assert(fn);
 
-        r = search_and_fopen_nulstr(fn, "re", conf_file_dirs, &f);
+        r = search_and_fopen_nulstr(fn, "re", NULL, conf_file_dirs, &f);
         if (r < 0) {
                 if (ignore_enoent && r == -ENOENT)
                         return 0;

commit 315db1a8aed226a51a4cf700172249cfd10ae115
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Fri Mar 14 09:05:56 2014 -0400

    Do not return -1 (EINVAL) on allocation error

diff --git a/src/core/socket.c b/src/core/socket.c
index 8ecc9f9..b39bec2 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -198,16 +198,14 @@ static int socket_instantiate_service(Socket *s) {
 
         assert(s->accept);
 
-        if (!(prefix = unit_name_to_prefix(UNIT(s)->id)))
+        prefix = unit_name_to_prefix(UNIT(s)->id);
+        if (!prefix)
                 return -ENOMEM;
 
-        r = asprintf(&name, "%s@%u.service", prefix, s->n_accepted);
-
-        if (r < 0)
+        if (asprintf(&name, "%s@%u.service", prefix, s->n_accepted) < 0)
                 return -ENOMEM;
 
         r = manager_load_unit(UNIT(s)->manager, name, NULL, NULL, &u);
-
         if (r < 0)
                 return r;
 
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 2650f86..275ad97 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -53,10 +53,10 @@ int link_new(Manager *manager, struct udev_device *device, Link **ret) {
         if (link->ifindex <= 0)
                 return -EINVAL;
 
-        r = asprintf(&link->state_file, "/run/systemd/network/links/%u",
-                     (unsigned) link->ifindex);
+        r = asprintf(&link->state_file, "/run/systemd/network/links/%"PRIu64,
+                     link->ifindex);
         if (r < 0)
-                return r;
+                return -ENOMEM;
 
         mac = udev_device_get_sysattr_value(device, "address");
         if (mac) {
@@ -1381,10 +1381,10 @@ int link_save(Link *link) {
         if (link->dhcp_lease) {
                 char *lease_file;
 
-                r = asprintf(&lease_file, "/run/systemd/network/leases/%u",
-                             (unsigned) link->ifindex);
+                r = asprintf(&lease_file, "/run/systemd/network/leases/%"PRIu64,
+                             link->ifindex);
                 if (r < 0)
-                        return r;
+                        return -ENOMEM;
 
                 r = dhcp_lease_save(link->dhcp_lease, lease_file);
                 if (r < 0)

commit fe970a8a30d611d454cb40025cfc32e29efa34e6
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Fri Mar 14 08:43:21 2014 -0400

    machine-id-setup: use path_kill_slashes and modernizations

diff --git a/man/systemd-machine-id-setup.xml b/man/systemd-machine-id-setup.xml
index b879b40..62630fb 100644
--- a/man/systemd-machine-id-setup.xml
+++ b/man/systemd-machine-id-setup.xml
@@ -97,11 +97,12 @@
 
                 <variablelist>
                         <varlistentry>
-                                <term><option>--root=ROOT</option></term>
+                                <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 ROOT
-                                path, including config search paths.
+                                prefixed with the given alternate
+                                <replaceable>root</replaceable> path,
+                                including config search paths.
                                 </para></listitem>
                         </varlistentry>
                         <xi:include href="standard-options.xml" xpointer="help" />
diff --git a/src/core/machine-id-setup.c b/src/core/machine-id-setup.c
index f3b1b31..43720d6 100644
--- a/src/core/machine-id-setup.c
+++ b/src/core/machine-id-setup.c
@@ -36,6 +36,7 @@
 #include "log.h"
 #include "virt.h"
 #include "fileio.h"
+#include "path-util.h"
 
 static int shorten_uuid(char destination[36], const char *source) {
         unsigned i, j;
@@ -160,14 +161,13 @@ int machine_id_setup(const char *root) {
         bool writable = false;
         struct stat st;
         char id[34]; /* 32 + \n + \0 */
-        _cleanup_free_ char *etc_machine_id = NULL;
-        _cleanup_free_ char *run_machine_id = NULL;
+        char *etc_machine_id, *run_machine_id;
 
-        if (asprintf(&etc_machine_id, "%s/etc/machine-id", root) < 0)
-                return log_oom();
+        etc_machine_id = strappenda(root, "/etc/machine-id");
+        path_kill_slashes(etc_machine_id);
 
-        if (asprintf(&run_machine_id, "%s/run/machine-id", root) < 0)
-                return log_oom();
+        run_machine_id = strappenda(root, "/run/machine-id");
+        path_kill_slashes(run_machine_id);
 
         RUN_WITH_UMASK(0000) {
                 /* We create this 0444, to indicate that this isn't really
diff --git a/src/machine-id-setup/machine-id-setup-main.c b/src/machine-id-setup/machine-id-setup-main.c
index a67d436..1c933ce 100644
--- a/src/machine-id-setup/machine-id-setup-main.c
+++ b/src/machine-id-setup/machine-id-setup-main.c
@@ -37,7 +37,7 @@ static int help(void) {
                "Initialize /etc/machine-id from a random source.\n\n"
                "  -h --help             Show this help\n"
                "     --version          Show package version\n"
-               "     --root             Filesystem root\n",
+               "     --root=ROOT        Filesystem root\n",
                program_invocation_short_name);
 
         return 0;
@@ -87,7 +87,7 @@ static int parse_argv(int argc, char *argv[]) {
         }
 
         if (optind < argc) {
-                help();
+                log_error("Extraneous arguments");
                 return -EINVAL;
         }
 



More information about the systemd-commits mailing list