[systemd-commits] 7 commits - man/systemctl.xml shell-completion/bash shell-completion/systemd-zsh-completion.zsh src/core src/cryptsetup src/efi-boot-generator src/getty-generator src/journal src/libsystemd-bus src/locale src/rc-local-generator src/readahead src/shared src/systemctl src/system-update-generator src/test src/tmpfiles src/udev test/TEST-01-BASIC test/TEST-02-CRYPTSETUP test/TEST-03-JOBS TODO

Zbigniew Jędrzejewski-Szmek zbyszek at kemper.freedesktop.org
Tue Apr 23 21:27:46 PDT 2013


 TODO                                                  |    6 -
 man/systemctl.xml                                     |   23 ++++
 shell-completion/bash/systemctl                       |    4 
 shell-completion/systemd-zsh-completion.zsh           |    7 +
 src/core/dbus-manager.c                               |    6 -
 src/core/load-fragment.c                              |    6 -
 src/core/main.c                                       |   13 --
 src/core/manager.c                                    |    6 -
 src/core/mount-setup.c                                |  101 +++++-------------
 src/cryptsetup/cryptsetup-generator.c                 |    6 -
 src/efi-boot-generator/efi-boot-generator.c           |    2 
 src/getty-generator/getty-generator.c                 |    2 
 src/journal/coredumpctl.c                             |   12 --
 src/libsystemd-bus/sd-bus.c                           |   10 -
 src/locale/localectl.c                                |   22 +--
 src/rc-local-generator/rc-local-generator.c           |    2 
 src/readahead/readahead-collect.c                     |    5 
 src/readahead/readahead-common.c                      |   35 +++---
 src/shared/install.c                                  |    6 -
 src/shared/set.c                                      |    7 +
 src/shared/set.h                                      |    1 
 src/system-update-generator/system-update-generator.c |    7 -
 src/systemctl/systemctl.c                             |   53 +++++++--
 src/test/test-prioq.c                                 |    2 
 src/tmpfiles/tmpfiles.c                               |   10 -
 src/udev/udev-watch.c                                 |    2 
 test/TEST-01-BASIC/test.sh                            |    4 
 test/TEST-02-CRYPTSETUP/test.sh                       |    4 
 test/TEST-03-JOBS/test.sh                             |    4 
 29 files changed, 181 insertions(+), 187 deletions(-)

New commits:
commit afba41995de65d8f378b138ea6d9804be32625a3
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Tue Apr 23 23:49:46 2013 -0400

    systemctl: show reverse dependencies or before/after ordering
    
    Also update completion scripts a bit.

diff --git a/man/systemctl.xml b/man/systemctl.xml
index 96cd108..2739df6 100644
--- a/man/systemctl.xml
+++ b/man/systemctl.xml
@@ -143,6 +143,29 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>.
       </varlistentry>
 
       <varlistentry>
+        <term><option>--reverse</option></term>
+
+        <listitem>
+          <para>Show reverse dependencies between units with
+          <command>list-dependencies</command>, i.e. units with
+          dependencies of type <varname>Wants=</varname> or
+          <varname>Requires=</varname> on the given unit.
+          </para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term><option>--after</option></term>
+        <term><option>--before</option></term>
+
+        <listitem>
+          <para>Show which units are started after, resp. before
+          with <command>list-dependencies</command>.
+          </para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
         <term><option>--failed</option></term>
 
         <listitem>
diff --git a/shell-completion/bash/systemctl b/shell-completion/bash/systemctl
index f5829b7..191b8d1 100644
--- a/shell-completion/bash/systemctl
+++ b/shell-completion/bash/systemctl
@@ -70,7 +70,7 @@ _systemctl () {
         local i verb comps mode
 
         local -A OPTS=(
-               [STANDALONE]='--all -a --defaults --fail --ignore-dependencies --failed --force -f --full --global
+               [STANDALONE]='--all -a --reverse --after --before --defaults --fail --ignore-dependencies --failed --force -f --full --global
                              --help -h --no-ask-password --no-block --no-legend --no-pager --no-reload --no-wall
                              --quiet -q --privileged -P --system --user --version --runtime'
                       [ARG]='--host -H --kill-mode --kill-who --property -p --signal -s --type -t --root'
@@ -117,7 +117,7 @@ _systemctl () {
         fi
 
         local -A VERBS=(
-                [ALL_UNITS]='is-active is-failed is-enabled status show mask preset help'
+                [ALL_UNITS]='is-active is-failed is-enabled status show mask preset help list-dependencies'
             [ENABLED_UNITS]='disable'
            [DISABLED_UNITS]='enable'
         [REENABLABLE_UNITS]='reenable'
diff --git a/shell-completion/systemd-zsh-completion.zsh b/shell-completion/systemd-zsh-completion.zsh
index 8b60859..73db378 100644
--- a/shell-completion/systemd-zsh-completion.zsh
+++ b/shell-completion/systemd-zsh-completion.zsh
@@ -12,6 +12,9 @@ _ctls()
                 {-t,--type=}'[List only units of a particular type]:unit type:(automount device mount path service snapshot socket swap target timer)' \
                 \*{-p,--property=}'[Show only properties by specific name]:unit property' \
                 {-a,--all}'[Show all units/properties, including dead/empty ones]' \
+                '--reverse[Show reverse dependencies]' \
+                '--after[Show units ordered after]' \
+                '--before[Show units ordered before]' \
                 '--failed[Show only failed units]' \
                 "--full[Don't ellipsize unit names on output]" \
                 '--fail[When queueing a new job, fail if conflicting jobs are pending]' \
@@ -348,6 +351,8 @@ _outputmodes() {
     "disable:Disable one or more unit files"
     "reenable:Reenable one or more unit files"
     "preset:Enable/disable one or more unit files based on preset configuration"
+    "help:Show documentation for specified units"
+    "list-dependencies:Show unit dependency tree"
     "mask:Mask one or more units"
     "unmask:Unmask one or more units"
     "link:Link one or more units files into the search path"
@@ -462,7 +467,7 @@ _systemctl_disabled_units(){_sys_disabled_units=($(__systemctl list-unit-files
 _systemctl_masked_units()  {_sys_masked_units=(  $(__systemctl list-unit-files     | { while read a b; do [[ $b == "masked" ]] && echo " $a"; done; }) )}
 
 # Completion functions for ALL_UNITS
-for fun in is-active is-failed is-enabled status show mask preset ; do
+for fun in is-active is-failed is-enabled status show mask preset help list-dependencies ; do
   (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
   {
     _systemctl_really_all_units
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index b94f7f7..6067781 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -72,6 +72,12 @@ static char **arg_types = NULL;
 static char **arg_load_states = NULL;
 static char **arg_properties = NULL;
 static bool arg_all = false;
+static enum dependency {
+        DEPENDENCY_FORWARD,
+        DEPENDENCY_REVERSE,
+        DEPENDENCY_AFTER,
+        DEPENDENCY_BEFORE,
+} arg_dependency = DEPENDENCY_FORWARD;
 static const char *arg_job_mode = "replace";
 static UnitFileScope arg_scope = UNIT_FILE_SYSTEM;
 static bool arg_no_block = false;
@@ -979,12 +985,19 @@ static int list_dependencies_print(const char *name, int level, unsigned int bra
 }
 
 static int list_dependencies_get_dependencies(DBusConnection *bus, const char *name, char ***deps) {
-        static const char dependencies[] =
-                "Requires\0"
-                "RequiresOverridable\0"
-                "Requisite\0"
-                "RequisiteOverridable\0"
-                "Wants\0";
+        static const char *dependencies[] = {
+                [DEPENDENCY_FORWARD] = "Requires\0"
+                                       "RequiresOverridable\0"
+                                       "Requisite\0"
+                                       "RequisiteOverridable\0"
+                                       "Wants\0",
+                [DEPENDENCY_REVERSE] = "RequiredBy\0"
+                                       "RequiredByOverridable\0"
+                                       "WantedBy\0"
+                                       "PartOf\0",
+                [DEPENDENCY_AFTER]   = "After\0",
+                [DEPENDENCY_BEFORE]  = "Before\0",
+        };
 
         _cleanup_free_ char *path;
         const char *interface = "org.freedesktop.systemd1.Unit";
@@ -1049,7 +1062,8 @@ static int list_dependencies_get_dependencies(DBusConnection *bus, const char *n
                 dbus_message_iter_recurse(&sub2, &sub3);
                 dbus_message_iter_next(&sub);
 
-                if (!nulstr_contains(dependencies, prop))
+                assert(arg_dependency < ELEMENTSOF(dependencies));
+                if (!nulstr_contains(dependencies[arg_dependency], prop))
                         continue;
 
                 if (dbus_message_iter_get_arg_type(&sub3) == DBUS_TYPE_ARRAY) {
@@ -4479,6 +4493,7 @@ static int systemctl_help(void) {
                "  -a --all            Show all loaded units/properties, including dead/empty\n"
                "                      ones. To list all units installed on the system, use\n"
                "                      the 'list-unit-files' command instead.\n"
+               "     --reverse        Show reverse dependencies with 'list-dependencies'\n"
                "     --failed         Show only failed units\n"
                "     --full           Don't ellipsize unit names on output\n"
                "     --fail           When queueing a new job, fail if conflicting jobs are\n"
@@ -4544,7 +4559,8 @@ static int systemctl_help(void) {
                "  unset-cgroup [NAME] [CGROUP...] Remove unit from a control group\n"
                "  load [NAME...]                  Load one or more units\n"
                "  list-dependencies [NAME]        Recursively show units which are required\n"
-               "                                  or wanted by this unit\n\n"
+               "                                  or wanted by this unit or by which this\n"
+               "                                  unit is required or wanted\n\n"
                "Unit File Commands:\n"
                "  list-unit-files                 List installed unit files\n"
                "  enable [NAME...]                Enable one or more unit files\n"
@@ -4680,6 +4696,9 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
 
         enum {
                 ARG_FAIL = 0x100,
+                ARG_REVERSE,
+                ARG_AFTER,
+                ARG_BEFORE,
                 ARG_SHOW_TYPES,
                 ARG_IRREVERSIBLE,
                 ARG_IGNORE_DEPENDENCIES,
@@ -4707,6 +4726,9 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
                 { "type",      required_argument, NULL, 't'           },
                 { "property",  required_argument, NULL, 'p'           },
                 { "all",       no_argument,       NULL, 'a'           },
+                { "reverse",   no_argument,       NULL, ARG_REVERSE   },
+                { "after",     no_argument,       NULL, ARG_AFTER     },
+                { "before",    no_argument,       NULL, ARG_BEFORE    },
                 { "show-types", no_argument,      NULL, ARG_SHOW_TYPES },
                 { "failed",    no_argument,       NULL, ARG_FAILED    },
                 { "full",      no_argument,       NULL, ARG_FULL      },
@@ -4829,6 +4851,18 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
                         arg_all = true;
                         break;
 
+                case ARG_REVERSE:
+                        arg_dependency = DEPENDENCY_REVERSE;
+                        break;
+
+                case ARG_AFTER:
+                        arg_dependency = DEPENDENCY_AFTER;
+                        break;
+
+                case ARG_BEFORE:
+                        arg_dependency = DEPENDENCY_BEFORE;
+                        break;
+
                 case ARG_SHOW_TYPES:
                         arg_show_types = true;
                         break;

commit a6b26d9011de60e1c41f51e8d2aab1d2f7bbf0f5
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Tue Apr 23 08:28:10 2013 -0400

    Small cleanup

diff --git a/src/core/main.c b/src/core/main.c
index 6a981a0..ab2ac00 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -522,9 +522,6 @@ static void strv_free_free(char ***l) {
 }
 
 static void free_join_controllers(void) {
-        if (!arg_join_controllers)
-                return;
-
         strv_free_free(arg_join_controllers);
         arg_join_controllers = NULL;
 }
@@ -1219,14 +1216,14 @@ static int initialize_join_controllers(void) {
                 return -ENOMEM;
 
         arg_join_controllers[0] = strv_new("cpu", "cpuacct", NULL);
-        if (!arg_join_controllers[0])
-                return -ENOMEM;
-
         arg_join_controllers[1] = strv_new("net_cls", "net_prio", NULL);
-        if (!arg_join_controllers[1])
+        arg_join_controllers[2] = NULL;
+
+        if (!arg_join_controllers[0] || !arg_join_controllers[1]) {
+                free_join_controllers();
                 return -ENOMEM;
+        }
 
-        arg_join_controllers[2] = NULL;
         return 0;
 }
 
diff --git a/src/core/mount-setup.c b/src/core/mount-setup.c
index b841f47..4629808 100644
--- a/src/core/mount-setup.c
+++ b/src/core/mount-setup.c
@@ -211,9 +211,9 @@ int mount_setup_early(void) {
 
 int mount_cgroup_controllers(char ***join_controllers) {
         int r;
-        FILE *f;
         char buf[LINE_MAX];
-        Set *controllers;
+        _cleanup_set_free_free_ Set *controllers = NULL;
+        _cleanup_fclose_ FILE *f;
 
         /* Mount all available cgroup controllers that are built into the kernel. */
 
@@ -224,10 +224,8 @@ int mount_cgroup_controllers(char ***join_controllers) {
         }
 
         controllers = set_new(string_hash_func, string_compare_func);
-        if (!controllers) {
-                r = log_oom();
-                goto finish;
-        }
+        if (!controllers)
+                return log_oom();
 
         /* Ignore the header line */
         (void) fgets(buf, sizeof(buf), f);
@@ -242,8 +240,7 @@ int mount_cgroup_controllers(char ***join_controllers) {
                                 break;
 
                         log_error("Failed to parse /proc/cgroups.");
-                        r = -EIO;
-                        goto finish;
+                        return -EIO;
                 }
 
                 if (!enabled) {
@@ -254,14 +251,19 @@ int mount_cgroup_controllers(char ***join_controllers) {
                 r = set_consume(controllers, controller);
                 if (r < 0) {
                         log_error("Failed to add controller to set.");
-                        goto finish;
+                        return r;
                 }
         }
 
         for (;;) {
-                MountPoint p;
-                char *controller, *where, *options;
+                MountPoint p = {
+                        .what = "cgroup",
+                        .type = "cgroup",
+                        .flags = MS_NOSUID|MS_NOEXEC|MS_NODEV,
+                        .mode = MNT_IN_CONTAINER,
+                };
                 char ***k = NULL;
+                _cleanup_free_ char *options = NULL, *controller;
 
                 controller = set_steal_first(controllers);
                 if (!controller)
@@ -278,14 +280,13 @@ int mount_cgroup_controllers(char ***join_controllers) {
                         for (i = *k, j = *k; *i; i++) {
 
                                 if (!streq(*i, controller)) {
-                                        char *t;
+                                        char _cleanup_free_ *t;
 
                                         t = set_remove(controllers, *i);
                                         if (!t) {
                                                 free(*i);
                                                 continue;
                                         }
-                                        free(t);
                                 }
 
                                 *(j++) = *i;
@@ -294,75 +295,36 @@ int mount_cgroup_controllers(char ***join_controllers) {
                         *j = NULL;
 
                         options = strv_join(*k, ",");
-                        if (!options) {
-                                free(controller);
-                                r = log_oom();
-                                goto finish;
-                        }
-
+                        if (!options)
+                                return log_oom();
                 } else {
                         options = controller;
                         controller = NULL;
                 }
 
-                where = strappend("/sys/fs/cgroup/", options);
-                if (!where) {
-                        free(options);
-                        r = log_oom();
-                        goto finish;
-                }
-
-                zero(p);
-                p.what = "cgroup";
-                p.where = where;
-                p.type = "cgroup";
+                p.where = strappenda("/sys/fs/cgroup/", options);
                 p.options = options;
-                p.flags = MS_NOSUID|MS_NOEXEC|MS_NODEV;
-                p.mode = MNT_IN_CONTAINER;
 
                 r = mount_one(&p, true);
-                free(controller);
-                free(where);
-
-                if (r < 0) {
-                        free(options);
-                        goto finish;
-                }
+                if (r < 0)
+                        return r;
 
                 if (r > 0 && k && *k) {
                         char **i;
 
                         for (i = *k; *i; i++) {
-                                _cleanup_free_ char *t;
-
-                                t = strappend("/sys/fs/cgroup/", *i);
-                                if (!t) {
-                                        r = log_oom();
-                                        free(options);
-                                        goto finish;
-                                }
+                                char *t = strappenda("/sys/fs/cgroup/", *i);
 
                                 r = symlink(options, t);
                                 if (r < 0 && errno != EEXIST) {
                                         log_error("Failed to create symlink %s: %m", t);
-                                        r = -errno;
-                                        free(options);
-                                        goto finish;
+                                        return -errno;
                                 }
                         }
                 }
-
-                free(options);
         }
 
-        r = 0;
-
-finish:
-        set_free_free(controllers);
-
-        fclose(f);
-
-        return r;
+        return 0;
 }
 
 static int nftw_cb(

commit 90ae6c0b822bbfd433c801d7945cadcabd1bc1c3
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Tue Apr 23 19:05:43 2013 -0400

    readahead: be more verbose about creation failures
    
    systemd-readahead reports "Failed to create shared memory segment:
    No such file or directory", but it's unclear how it can happen. Be
    more verbose about failures.

diff --git a/src/readahead/readahead-common.c b/src/readahead/readahead-common.c
index ed81c14..a234a89 100644
--- a/src/readahead/readahead-common.c
+++ b/src/readahead/readahead-common.c
@@ -216,16 +216,23 @@ bool enough_ram(void) {
         return si.totalram > 127 * 1024*1024 / si.mem_unit;
 }
 
+static void mkdirs(void) {
+        if (mkdir("/run/systemd", 0755) && errno != EEXIST)
+                log_warning("Failed to create /run/systemd: %m");
+        if (mkdir("/run/systemd/readahead", 0755) && errno != EEXIST)
+                log_warning("Failed to create /run/systemd: %m");
+}
+
 int open_inotify(void) {
         int fd;
 
-        if ((fd = inotify_init1(IN_CLOEXEC|IN_NONBLOCK)) < 0) {
+        fd = inotify_init1(IN_CLOEXEC|IN_NONBLOCK);
+        if (fd < 0) {
                 log_error("Failed to create inotify handle: %m");
                 return -errno;
         }
 
-        mkdir("/run/systemd", 0755);
-        mkdir("/run/systemd/readahead", 0755);
+        mkdirs();
 
         if (inotify_add_watch(fd, "/run/systemd/readahead", IN_CREATE) < 0) {
                 log_error("Failed to watch /run/systemd/readahead: %m");
@@ -237,32 +244,28 @@ int open_inotify(void) {
 }
 
 ReadaheadShared *shared_get(void) {
-        int fd;
+        int _cleanup_close_ fd = -1;
         ReadaheadShared *m = NULL;
 
-        mkdir("/run/systemd", 0755);
-        mkdir("/run/systemd/readahead", 0755);
+        mkdirs();
 
-        if ((fd = open("/run/systemd/readahead/shared", O_CREAT|O_RDWR|O_CLOEXEC, 0644)) < 0) {
+        fd = open("/run/systemd/readahead/shared", O_CREAT|O_RDWR|O_CLOEXEC, 0644);
+        if (fd < 0) {
                 log_error("Failed to create shared memory segment: %m");
-                goto finish;
+                return NULL;
         }
 
         if (ftruncate(fd, sizeof(ReadaheadShared)) < 0) {
                 log_error("Failed to truncate shared memory segment: %m");
-                goto finish;
+                return NULL;
         }
 
-        if ((m = mmap(NULL, sizeof(ReadaheadShared), PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) {
+        m = mmap(NULL, sizeof(ReadaheadShared), PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0);
+        if (m == MAP_FAILED) {
                 log_error("Failed to mmap shared memory segment: %m");
-                m = NULL;
-                goto finish;
+                return NULL;
         }
 
-finish:
-        if (fd >= 0)
-                close_nointr_nofail(fd);
-
         return m;
 }
 

commit ef42202ac8ed27e7ff1fc90ef8bc2590046dff25
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Mon Apr 22 23:12:15 2013 -0400

    Add set_consume which always takes ownership
    
    Freeing in error path is the common pattern with set_put().

diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
index d767dd5..1f5a7d9 100644
--- a/src/core/dbus-manager.c
+++ b/src/core/dbus-manager.c
@@ -1186,11 +1186,9 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
                 if (!client)
                         goto oom;
 
-                r = set_put(s, client);
-                if (r < 0) {
-                        free(client);
+                r = set_consume(s, client);
+                if (r < 0)
                         return bus_send_error_reply(connection, message, NULL, r);
-                }
 
                 reply = dbus_message_new_method_return(message);
                 if (!reply)
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index 0571d51..3d23372 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -2095,11 +2095,9 @@ static int open_follow(char **filename, FILE **_f, Set *names, char **_final) {
                                 if (!id)
                                         return -ENOMEM;
 
-                                r = set_put(names, id);
-                                if (r < 0) {
-                                        free(id);
+                                r = set_consume(names, id);
+                                if (r < 0)
                                         return r;
-                                }
                         }
                 }
 
diff --git a/src/core/manager.c b/src/core/manager.c
index 208b240..b1a2289 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -806,11 +806,9 @@ static void manager_build_unit_path_cache(Manager *m) {
                                 goto fail;
                         }
 
-                        r = set_put(m->unit_path_cache, p);
-                        if (r < 0) {
-                                free(p);
+                        r = set_consume(m->unit_path_cache, p);
+                        if (r < 0)
                                 goto fail;
-                        }
                 }
 
                 closedir(d);
diff --git a/src/core/mount-setup.c b/src/core/mount-setup.c
index 89adb0b..b841f47 100644
--- a/src/core/mount-setup.c
+++ b/src/core/mount-setup.c
@@ -251,10 +251,9 @@ int mount_cgroup_controllers(char ***join_controllers) {
                         continue;
                 }
 
-                r = set_put(controllers, controller);
+                r = set_consume(controllers, controller);
                 if (r < 0) {
                         log_error("Failed to add controller to set.");
-                        free(controller);
                         goto finish;
                 }
         }
diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c
index 0bbfff2..5652c2f 100644
--- a/src/journal/coredumpctl.c
+++ b/src/journal/coredumpctl.c
@@ -68,10 +68,9 @@ static Set *new_matches(void) {
                 return NULL;
         }
 
-        r = set_put(set, tmp);
+        r = set_consume(set, tmp);
         if (r < 0) {
                 log_error("failed to add to set: %s", strerror(-r));
-                free(tmp);
                 set_free(set);
                 return NULL;
         }
@@ -125,18 +124,17 @@ static int add_match(Set *set, const char *match) {
         if (!pattern)
                 goto fail;
 
-        r = set_put(set, pattern);
+        log_debug("Adding pattern: %s", pattern);
+        r = set_consume(set, pattern);
         if (r < 0) {
-                log_error("failed to add pattern '%s': %s",
+                log_error("Failed to add pattern '%s': %s",
                           pattern, strerror(-r));
                 goto fail;
         }
-        log_debug("Added pattern: %s", pattern);
 
         return 0;
 fail:
-        free(pattern);
-        log_error("failed to add match: %s", strerror(-r));
+        log_error("Failed to add match: %s", strerror(-r));
         return r;
 }
 
diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c
index c7511c3..7d6d848 100644
--- a/src/libsystemd-bus/sd-bus.c
+++ b/src/libsystemd-bus/sd-bus.c
@@ -1841,13 +1841,9 @@ static int process_introspect(sd_bus *bus, sd_bus_message *m) {
                 if (p)
                         *p = 0;
 
-                r = set_put(s, a);
-                if (r < 0) {
-                        free(a);
-
-                        if (r != -EEXIST)
-                                return r;
-                }
+                r = set_consume(s, a);
+                if (r < 0 && r != -EEXIST)
+                        return r;
         }
 
         f = open_memstream(&introspection, &size);
diff --git a/src/locale/localectl.c b/src/locale/localectl.c
index ea9187f..50250c4 100644
--- a/src/locale/localectl.c
+++ b/src/locale/localectl.c
@@ -369,9 +369,8 @@ static int add_locales_from_archive(Set *locales) {
                         goto finish;
                 }
 
-                r = set_put(locales, z);
+                r = set_consume(locales, z);
                 if (r < 0) {
-                        free(z);
                         log_error("Failed to add locale: %s", strerror(-r));
                         goto finish;
                 }
@@ -411,14 +410,10 @@ static int add_locales_from_libdir (Set *locales) {
                 if (!z)
                         return log_oom();
 
-                r = set_put(locales, z);
-                if (r < 0) {
-                        free(z);
-
-                        if (r != -EEXIST) {
-                                log_error("Failed to add locale: %s", strerror(-r));
-                                return r;
-                        }
+                r = set_consume(locales, z);
+                if (r < 0 && r != -EEXIST) {
+                        log_error("Failed to add locale: %s", strerror(-r));
+                        return r;
                 }
 
                 errno = 0;
@@ -526,12 +521,9 @@ static int nftw_cb(
         if (e)
                 *e = 0;
 
-        r = set_put(keymaps, p);
-        if (r == -EEXIST)
-                free(p);
-        else if (r < 0) {
+        r = set_consume(keymaps, p);
+        if (r < 0 && r != -EEXIST) {
                 log_error("Can't add keymap: %s", strerror(-r));
-                free(p);
                 return r;
         }
 
diff --git a/src/readahead/readahead-collect.c b/src/readahead/readahead-collect.c
index 75ec5b7..ccd8408 100644
--- a/src/readahead/readahead-collect.c
+++ b/src/readahead/readahead-collect.c
@@ -479,8 +479,9 @@ static int collect(const char *root) {
                                         }
                                         entry->bin = (entrytime - starttime) / 2000000;
 
-                                        if ((k = hashmap_put(files, p, entry)) < 0) {
-                                                log_warning("set_put() failed: %s", strerror(-k));
+                                        k = hashmap_put(files, p, entry);
+                                        if (k < 0) {
+                                                log_warning("hashmap_put() failed: %s", strerror(-k));
                                                 free(p);
                                         }
                                 }
diff --git a/src/shared/install.c b/src/shared/install.c
index 959de04..b22019d 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -178,11 +178,9 @@ static int mark_symlink_for_removal(
 
         path_kill_slashes(n);
 
-        r = set_put(*remove_symlinks_to, n);
-        if (r < 0) {
-                free(n);
+        r = set_consume(*remove_symlinks_to, n);
+        if (r < 0)
                 return r == -EEXIST ? 0 : r;
-        }
 
         return 0;
 }
diff --git a/src/shared/set.c b/src/shared/set.c
index 5f83c50..c338dc3 100644
--- a/src/shared/set.c
+++ b/src/shared/set.c
@@ -49,6 +49,13 @@ int set_put(Set *s, void *value) {
         return hashmap_put(MAKE_HASHMAP(s), value, value);
 }
 
+int set_consume(Set *s, void *value) {
+        int r = set_put(s, value);
+        if (r < 0)
+                free(value);
+        return r;
+}
+
 int set_replace(Set *s, void *value) {
         return hashmap_replace(MAKE_HASHMAP(s), value, value);
 }
diff --git a/src/shared/set.h b/src/shared/set.h
index 8864f7b..e5d46e9 100644
--- a/src/shared/set.h
+++ b/src/shared/set.h
@@ -46,6 +46,7 @@ Set* set_copy(Set *s);
 int set_ensure_allocated(Set **s, hash_func_t hash_func, compare_func_t compare_func);
 
 int set_put(Set *s, void *value);
+int set_consume(Set *s, void *value);
 int set_replace(Set *s, void *value);
 void *set_get(Set *s, void *value);
 bool set_contains(Set *s, void *value);
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index c2b1749..b94f7f7 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -1843,9 +1843,8 @@ static int start_unit_one(
                 if (!p)
                         return log_oom();
 
-                r = set_put(s, p);
+                r = set_consume(s, p);
                 if (r < 0) {
-                        free(p);
                         log_error("Failed to add path to set.");
                         return r;
                 }
diff --git a/src/test/test-prioq.c b/src/test/test-prioq.c
index 73c6408..aeac739 100644
--- a/src/test/test-prioq.c
+++ b/src/test/test-prioq.c
@@ -119,7 +119,7 @@ static void test_struct(void) {
                 assert_se(r >= 0);
 
                 if (i % 4 == 0) {
-                        r = set_put(s, t);
+                        r = set_consume(s, t);
                         assert_se(r >= 0);
                 }
         }
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index 535381c..f4885ec 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -186,13 +186,9 @@ static void load_unix_sockets(void) {
 
                 path_kill_slashes(s);
 
-                k = set_put(unix_sockets, s);
-                if (k < 0) {
-                        free(s);
-
-                        if (k != -EEXIST)
-                                goto fail;
-                }
+                k = set_consume(unix_sockets, s);
+                if (k < 0 && k != -EEXIST)
+                        goto fail;
         }
 
         return;

commit c79bb9e4e2e5b96b2ae2c432bf8b0ff9674fce60
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Mon Apr 22 20:51:29 2013 -0400

    Standarize on one spelling of symlink error message
    
    It's polite to print the name of the link that wasn't created,
    and it makes little sense to print the target.

diff --git a/src/core/mount-setup.c b/src/core/mount-setup.c
index a0fd7a0..89adb0b 100644
--- a/src/core/mount-setup.c
+++ b/src/core/mount-setup.c
@@ -334,7 +334,7 @@ int mount_cgroup_controllers(char ***join_controllers) {
                         char **i;
 
                         for (i = *k; *i; i++) {
-                                char *t;
+                                _cleanup_free_ char *t;
 
                                 t = strappend("/sys/fs/cgroup/", *i);
                                 if (!t) {
@@ -344,10 +344,8 @@ int mount_cgroup_controllers(char ***join_controllers) {
                                 }
 
                                 r = symlink(options, t);
-                                free(t);
-
                                 if (r < 0 && errno != EEXIST) {
-                                        log_error("Failed to create symlink: %m");
+                                        log_error("Failed to create symlink %s: %m", t);
                                         r = -errno;
                                         free(options);
                                         goto finish;
diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c
index b31329d..228039d 100644
--- a/src/cryptsetup/cryptsetup-generator.c
+++ b/src/cryptsetup/cryptsetup-generator.c
@@ -179,7 +179,7 @@ static int create_disk(
 
                 mkdir_parents_label(to, 0755);
                 if (symlink(from, to) < 0) {
-                        log_error("Failed to create symlink '%s' to '%s': %m", from, to);
+                        log_error("Failed to create symlink %s: %m", to);
                         return -errno;
                 }
 
@@ -193,7 +193,7 @@ static int create_disk(
 
                 mkdir_parents_label(to, 0755);
                 if (symlink(from, to) < 0) {
-                        log_error("Failed to create symlink '%s' to '%s': %m", from, to);
+                        log_error("Failed to create symlink %s: %m", to);
                         return -errno;
                 }
         }
@@ -209,7 +209,7 @@ static int create_disk(
 
         mkdir_parents_label(to, 0755);
         if (symlink(from, to) < 0) {
-                log_error("Failed to create symlink '%s' to '%s': %m", from, to);
+                log_error("Failed to create symlink %s: %m", to);
                 return -errno;
         }
 
diff --git a/src/efi-boot-generator/efi-boot-generator.c b/src/efi-boot-generator/efi-boot-generator.c
index 88fa220..4367c53 100644
--- a/src/efi-boot-generator/efi-boot-generator.c
+++ b/src/efi-boot-generator/efi-boot-generator.c
@@ -115,7 +115,7 @@ int main(int argc, char *argv[]) {
         mkdir_parents(name, 0755);
 
         if (symlink("../boot.automount", name) < 0) {
-                log_error("Failed to create symlink: %m");
+                log_error("Failed to create symlink %s: %m", name);
                 return EXIT_FAILURE;
         }
 
diff --git a/src/getty-generator/getty-generator.c b/src/getty-generator/getty-generator.c
index e811830..4b7a60a 100644
--- a/src/getty-generator/getty-generator.c
+++ b/src/getty-generator/getty-generator.c
@@ -55,7 +55,7 @@ static int add_symlink(const char *fservice, const char *tservice) {
                         /* In case console=hvc0 is passed this will very likely result in EEXIST */
                         r = 0;
                 else {
-                        log_error("Failed to create symlink from %s to %s: %m", from, to);
+                        log_error("Failed to create symlink %s: %m", to);
                         r = -errno;
                 }
         }
diff --git a/src/rc-local-generator/rc-local-generator.c b/src/rc-local-generator/rc-local-generator.c
index 448980b..9265501 100644
--- a/src/rc-local-generator/rc-local-generator.c
+++ b/src/rc-local-generator/rc-local-generator.c
@@ -59,7 +59,7 @@ static int add_symlink(const char *service, const char *where) {
                 if (errno == EEXIST)
                         r = 0;
                 else {
-                        log_error("Failed to create symlink from %s to %s: %m", from, to);
+                        log_error("Failed to create symlink %s: %m", to);
                         r = -errno;
                 }
         }
diff --git a/src/system-update-generator/system-update-generator.c b/src/system-update-generator/system-update-generator.c
index 6660192..13b8a0c 100644
--- a/src/system-update-generator/system-update-generator.c
+++ b/src/system-update-generator/system-update-generator.c
@@ -36,7 +36,7 @@ static const char *arg_dest = "/tmp";
 
 static int generate_symlink(void) {
         struct stat st;
-        char *p;
+        char _cleanup_free_ *p = NULL;
 
         if (lstat("/system-update", &st) < 0) {
                 if (errno == ENOENT)
@@ -51,13 +51,10 @@ static int generate_symlink(void) {
                 return log_oom();
 
         if (symlink(SYSTEM_DATA_UNIT_PATH "/system-update.target", p) < 0) {
-                free(p);
-                log_error("Failed to create symlink: %m");
+                log_error("Failed to create symlink %s: %m", p);
                 return -errno;
         }
 
-        free(p);
-
         return 0;
 }
 
diff --git a/src/udev/udev-watch.c b/src/udev/udev-watch.c
index 311f5bd..9b694c6 100644
--- a/src/udev/udev-watch.c
+++ b/src/udev/udev-watch.c
@@ -116,7 +116,7 @@ void udev_watch_begin(struct udev *udev, struct udev_device *dev)
         unlink(filename);
         r = symlink(udev_device_get_id_filename(dev), filename);
         if (r < 0)
-                log_error("Failed to create symlink: %m");
+                log_error("Failed to create symlink %s: %m", filename);
 
         udev_device_set_watch_handle(dev, wd);
 }

commit fff87a35d9e26c0d4ea41273a963c0eb20e18da4
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Mon Apr 22 20:39:40 2013 -0400

    test: make it easier to override kernel version

diff --git a/TODO b/TODO
index fe27d2b..aa2c1ce 100644
--- a/TODO
+++ b/TODO
@@ -72,8 +72,10 @@ Features:
 * explicitly disallow changing the cgroup path of units in the
   name=systemd hierarchy, unless it is outside of /system
 
-* add 'set -e' to scripts in test/
-* make test in test/ work with separate output dir
+* test/:
+  - add 'set -e' to scripts in test/
+  - make stuff in test/ work with separate output dir
+  - remove all the duplicated code in test/
 
 * suppress log output on shutdown when "quiet" is used
 
diff --git a/test/TEST-01-BASIC/test.sh b/test/TEST-01-BASIC/test.sh
index 9049207..e41ed9d 100755
--- a/test/TEST-01-BASIC/test.sh
+++ b/test/TEST-01-BASIC/test.sh
@@ -3,8 +3,7 @@
 # ex: ts=8 sw=4 sts=4 et filetype=sh
 TEST_DESCRIPTION="Basic systemd setup"
 
-KVERSION=${KVERSION-$(uname -r)}
-KERNEL_VER=$(uname -r)
+. $TEST_BASE_DIR/test-functions
 
 # Uncomment this to debug failures
 #DEBUGFAIL="systemd.unit=multi-user.target"
@@ -242,5 +241,4 @@ test_cleanup() {
     return 0
 }
 
-. $TEST_BASE_DIR/test-functions
 do_test "$@"
diff --git a/test/TEST-02-CRYPTSETUP/test.sh b/test/TEST-02-CRYPTSETUP/test.sh
index e094531..ec71430 100755
--- a/test/TEST-02-CRYPTSETUP/test.sh
+++ b/test/TEST-02-CRYPTSETUP/test.sh
@@ -3,8 +3,7 @@
 # ex: ts=8 sw=4 sts=4 et filetype=sh
 TEST_DESCRIPTION="cryptsetup systemd setup"
 
-KVERSION=${KVERSION-$(uname -r)}
-KERNEL_VER=$(uname -r)
+. $TEST_BASE_DIR/test-functions
 
 # Uncomment this to debug failures
 #DEBUGFAIL="systemd.unit=multi-user.target"
@@ -254,5 +253,4 @@ test_cleanup() {
     return 0
 }
 
-. $TEST_BASE_DIR/test-functions
 do_test "$@"
diff --git a/test/TEST-03-JOBS/test.sh b/test/TEST-03-JOBS/test.sh
index 6eaba72..6440d1f 100755
--- a/test/TEST-03-JOBS/test.sh
+++ b/test/TEST-03-JOBS/test.sh
@@ -3,8 +3,7 @@
 # ex: ts=8 sw=4 sts=4 et filetype=sh
 TEST_DESCRIPTION="Job-related tests"
 
-KVERSION=${KVERSION-$(uname -r)}
-KERNEL_VER=$(uname -r)
+. $TEST_BASE_DIR/test-functions
 
 # Uncomment this to debug failures
 #DEBUGFAIL="systemd.unit=multi-user.target"
@@ -247,5 +246,4 @@ test_cleanup() {
     return 0
 }
 
-. $TEST_BASE_DIR/test-functions
 do_test "$@"

commit 0ee679580e55b4b7fe6c68bf63d953017c489617
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Mon Apr 22 20:39:03 2013 -0400

    systemd: fall back to mounting /sys/fs/cgroup sans xattr
    
    xattrs on cgroup fs were added back in v3.6-rc3-3-g03b1cde. But we
    support kernels >= 2.6.39, and we should also support kernels compiled
    w/o xattr support, even if systemd is compiled with xattr support.
    Fall back to mounting without xattr support.
    
    Tested-by: Colin Walters <walters at verbum.org>

diff --git a/src/core/mount-setup.c b/src/core/mount-setup.c
index 56d358b..a0fd7a0 100644
--- a/src/core/mount-setup.c
+++ b/src/core/mount-setup.c
@@ -68,12 +68,6 @@ typedef struct MountPoint {
  * other ones we can delay until SELinux and IMA are loaded. */
 #define N_EARLY_MOUNT 5
 
-#ifdef HAVE_XATTR
-#  define FS_XATTR_OPT ",xattr"
-#else
-#  define FS_XATTR_OPT ""
-#endif
-
 static const MountPoint mount_table[] = {
         { "proc",       "/proc",                     "proc",       NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV,
           NULL,       MNT_FATAL|MNT_IN_CONTAINER },
@@ -93,7 +87,11 @@ static const MountPoint mount_table[] = {
           NULL,       MNT_FATAL|MNT_IN_CONTAINER },
         { "tmpfs",      "/sys/fs/cgroup",            "tmpfs",      "mode=755", MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_STRICTATIME,
           NULL,       MNT_IN_CONTAINER },
-        { "cgroup",     "/sys/fs/cgroup/systemd",    "cgroup",     "none,name=systemd" FS_XATTR_OPT, MS_NOSUID|MS_NOEXEC|MS_NODEV,
+#ifdef HAVE_XATTR
+        { "cgroup",     "/sys/fs/cgroup/systemd",    "cgroup",     "none,name=systemd,xattr", MS_NOSUID|MS_NOEXEC|MS_NODEV,
+          NULL,       MNT_IN_CONTAINER },
+#endif
+        { "cgroup",     "/sys/fs/cgroup/systemd",    "cgroup",     "none,name=systemd", MS_NOSUID|MS_NOEXEC|MS_NODEV,
           NULL,       MNT_IN_CONTAINER },
         { "pstore",     "/sys/fs/pstore",            "pstore",     NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV,
           NULL,       MNT_NONE },



More information about the systemd-commits mailing list