[systemd-commits] 7 commits - shell-completion/zsh src/analyze src/core src/cryptsetup src/journal src/libsystemd src/run src/shared src/systemctl src/test src/tty-ask-password-agent src/update-done

Zbigniew Jędrzejewski-Szmek zbyszek at kemper.freedesktop.org
Sat Jul 26 12:13:30 PDT 2014


 shell-completion/zsh/_systemctl.in                  |   20 +++----
 src/analyze/analyze.c                               |    2 
 src/core/busname.c                                  |    9 ++-
 src/core/unit-printf.c                              |    8 +--
 src/cryptsetup/cryptsetup.c                         |   11 +++-
 src/journal/coredump.c                              |    6 +-
 src/journal/journalctl.c                            |   32 ++++++------
 src/libsystemd/sd-bus/bus-kernel.c                  |   15 ++++-
 src/libsystemd/sd-bus/bus-kernel.h                  |    2 
 src/run/run.c                                       |   16 +++---
 src/shared/install.c                                |   52 +++++---------------
 src/shared/path-util.c                              |   16 ++++++
 src/shared/path-util.h                              |    1 
 src/systemctl/systemctl.c                           |   48 +++++-------------
 src/test/test-path-util.c                           |   15 +++++
 src/tty-ask-password-agent/tty-ask-password-agent.c |    5 +
 src/update-done/update-done.c                       |    7 ++
 17 files changed, 141 insertions(+), 124 deletions(-)

New commits:
commit 8f077bf94e129fa1b6f0159e3140c4326f1066cf
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Sat Jul 26 14:59:52 2014 -0400

    Print kdbus path when opening fails
    
    This makes it easier to debug what is going on.

diff --git a/src/core/busname.c b/src/core/busname.c
index b3f7e0d..39ea6a0 100644
--- a/src/core/busname.c
+++ b/src/core/busname.c
@@ -290,14 +290,19 @@ static int busname_watch_fd(BusName *n) {
 }
 
 static int busname_open_fd(BusName *n) {
+        _cleanup_free_ char *path = NULL;
+        const char *mode;
+
         assert(n);
 
         if (n->starter_fd >= 0)
                 return 0;
 
-        n->starter_fd = bus_kernel_open_bus_fd(UNIT(n)->manager->running_as == SYSTEMD_SYSTEM ? "system" : "user");
+        mode = UNIT(n)->manager->running_as == SYSTEMD_SYSTEM ? "system" : "user";
+        n->starter_fd = bus_kernel_open_bus_fd(mode, &path);
         if (n->starter_fd < 0) {
-                log_warning_unit(UNIT(n)->id, "Failed to create starter fd: %s", strerror(-n->starter_fd));
+                log_warning_unit(UNIT(n)->id, "Failed to open %s: %s",
+                                 path ?: "kdbus", strerror(-n->starter_fd));
                 return n->starter_fd;
         }
 
diff --git a/src/libsystemd/sd-bus/bus-kernel.c b/src/libsystemd/sd-bus/bus-kernel.c
index f49fb5b..8b961c3 100644
--- a/src/libsystemd/sd-bus/bus-kernel.c
+++ b/src/libsystemd/sd-bus/bus-kernel.c
@@ -1402,11 +1402,20 @@ static int bus_kernel_translate_policy(const BusNamePolicy *policy, struct kdbus
         return 0;
 }
 
-int bus_kernel_open_bus_fd(const char *bus) {
+int bus_kernel_open_bus_fd(const char *bus, char **path) {
         char *p;
         int fd;
+        size_t len;
 
-        p = alloca(strlen("/dev/kdbus/") + DECIMAL_STR_MAX(uid_t) + 1 + strlen(bus) + strlen("/bus") + 1);
+        len = strlen("/dev/kdbus/") + DECIMAL_STR_MAX(uid_t) + 1 + strlen(bus) + strlen("/bus") + 1;
+
+        if (path) {
+                p = malloc(len);
+                if (!p)
+                        return -ENOMEM;
+                *path = p;
+        } else
+                p = alloca(len);
         sprintf(p, "/dev/kdbus/" UID_FMT "-%s/bus", getuid(), bus);
 
         fd = open(p, O_RDWR|O_NOCTTY|O_CLOEXEC);
@@ -1549,7 +1558,7 @@ int bus_kernel_create_monitor(const char *bus) {
 
         assert(bus);
 
-        fd = bus_kernel_open_bus_fd(bus);
+        fd = bus_kernel_open_bus_fd(bus, NULL);
         if (fd < 0)
                 return fd;
 
diff --git a/src/libsystemd/sd-bus/bus-kernel.h b/src/libsystemd/sd-bus/bus-kernel.h
index 2fe2495..87f98c5 100644
--- a/src/libsystemd/sd-bus/bus-kernel.h
+++ b/src/libsystemd/sd-bus/bus-kernel.h
@@ -65,7 +65,7 @@ int bus_kernel_take_fd(sd_bus *b);
 int bus_kernel_write_message(sd_bus *bus, sd_bus_message *m, bool hint_sync_call);
 int bus_kernel_read_message(sd_bus *bus, bool hint_priority, int64_t priority);
 
-int bus_kernel_open_bus_fd(const char *bus);
+int bus_kernel_open_bus_fd(const char *bus, char **path);
 int bus_kernel_make_starter(int fd, const char *name, bool activating, bool accept_fd, BusNamePolicy *policy, BusNamePolicyAccess world_policy);
 
 int bus_kernel_create_bus(const char *name, bool world, char **s);

commit 4aa4d2ae9717d0f8656528a3197bbc0c256380b1
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Sat Jul 26 15:01:49 2014 -0400

    update-done: include a short description in .updated
    
    People might be confused where the file comes from, since the name is not
    at all specific.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1121301#c8

diff --git a/src/update-done/update-done.c b/src/update-done/update-done.c
index b199a68..db106b5 100644
--- a/src/update-done/update-done.c
+++ b/src/update-done/update-done.c
@@ -22,6 +22,11 @@
 #include "util.h"
 #include "label.h"
 
+#define MESSAGE                                                         \
+        "This file was created by systemd-update-done. Its only \n"     \
+        "purpose is to hold a timestamp of the time this directory\n"   \
+        "was updated. See systemd-update-done.service(8).\n"
+
 static int apply_timestamp(const char *path, struct timespec *ts) {
         struct timespec twice[2];
         struct stat st;
@@ -77,6 +82,8 @@ static int apply_timestamp(const char *path, struct timespec *ts) {
                         return -errno;
                 }
 
+                (void) loop_write(fd, MESSAGE, strlen(MESSAGE), false);
+
                 twice[0] = *ts;
                 twice[1] = *ts;
 

commit 0c6ea3a4e2ac3f350dcb58e8f08bb74b030cd624
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Sat Jul 26 14:47:31 2014 -0400

    Add utility function to append root to path

diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 5a59a3a..78495f8 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -1614,16 +1614,12 @@ int main(int argc, char *argv[]) {
             arg_action == ACTION_LIST_CATALOG ||
             arg_action == ACTION_DUMP_CATALOG) {
 
-                const char* database = CATALOG_DATABASE;
-                _cleanup_free_ char *copy = NULL;
-                if (arg_root) {
-                        copy = strjoin(arg_root, "/", CATALOG_DATABASE, NULL);
-                        if (!copy) {
-                                r = log_oom();
-                                goto finish;
-                        }
-                        path_kill_slashes(copy);
-                        database = copy;
+                _cleanup_free_ char *database;
+
+                database = path_join(arg_root, CATALOG_DATABASE, NULL);
+                if (!database) {
+                        r = log_oom();
+                        goto finish;
                 }
 
                 if (arg_action == ACTION_UPDATE_CATALOG) {
diff --git a/src/shared/install.c b/src/shared/install.c
index e957c33..cc61c01 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -88,18 +88,10 @@ static int get_config_path(UnitFileScope scope, bool runtime, const char *root_d
 
         case UNIT_FILE_SYSTEM:
 
-                if (root_dir && runtime) {
-                        if (asprintf(&p, "%s/run/systemd/system", root_dir) < 0)
-                                return -ENOMEM;
-                } else if (runtime)
-                        p = strdup("/run/systemd/system");
-                else if (root_dir) {
-                        if (asprintf(&p, "%s/%s", root_dir,
-                                     SYSTEM_CONFIG_UNIT_PATH) < 0)
-                                return -ENOMEM;
-                } else
-                        p = strdup(SYSTEM_CONFIG_UNIT_PATH);
-
+                if (runtime)
+                        p = path_join(root_dir, "/run/systemd/system", NULL);
+                else
+                        p = path_join(root_dir, SYSTEM_CONFIG_UNIT_PATH, NULL);
                 break;
 
         case UNIT_FILE_GLOBAL:
@@ -1664,11 +1656,7 @@ int unit_file_get_default(
                 _cleanup_free_ char *path = NULL, *tmp = NULL;
                 char *n;
 
-                if (isempty(root_dir))
-                        path = strappend(*p, "/" SPECIAL_DEFAULT_TARGET);
-                else
-                        path = strjoin(root_dir, "/", *p, "/" SPECIAL_DEFAULT_TARGET, NULL);
-
+                path = path_join(root_dir, *p, SPECIAL_DEFAULT_TARGET);
                 if (!path)
                         return -ENOMEM;
 
@@ -1725,15 +1713,12 @@ UnitFileState unit_file_get_state(
                 free(path);
                 path = NULL;
 
-                if (root_dir)
-                        asprintf(&path, "%s/%s/%s", root_dir, *i, name);
-                else
-                        asprintf(&path, "%s/%s", *i, name);
+                path = path_join(root_dir, *i, name);
                 if (!path)
                         return -ENOMEM;
 
                 if (root_dir)
-                        partial = path + strlen(root_dir) + 1;
+                        partial = path + strlen(root_dir);
                 else
                         partial = path;
 
@@ -1960,17 +1945,11 @@ int unit_file_preset_all(
 
         STRV_FOREACH(i, paths.unit_path) {
                 _cleanup_closedir_ DIR *d = NULL;
-                _cleanup_free_ char *buf = NULL;
-                const char *units_dir;
-
-                if (!isempty(root_dir)) {
-                        buf = strjoin(root_dir, "/", *i, NULL);
-                        if (!buf)
-                                return -ENOMEM;
+                _cleanup_free_ char *units_dir;
 
-                        units_dir = buf;
-                } else
-                        units_dir = *i;
+                units_dir = path_join(root_dir, *i, NULL);
+                if (!units_dir)
+                        return -ENOMEM;
 
                 d = opendir(units_dir);
                 if (!d) {
@@ -2069,17 +2048,11 @@ int unit_file_get_list(
 
         STRV_FOREACH(i, paths.unit_path) {
                 _cleanup_closedir_ DIR *d = NULL;
-                _cleanup_free_ char *buf = NULL;
-                const char *units_dir;
+                _cleanup_free_ char *units_dir;
 
-                if (!isempty(root_dir)) {
-                        buf = strjoin(root_dir, "/", *i, NULL);
-                        if (!buf)
-                                return -ENOMEM;
-
-                        units_dir = buf;
-                } else
-                        units_dir = *i;
+                units_dir = path_join(root_dir, *i, NULL);
+                if (!units_dir)
+                        return -ENOMEM;
 
                 d = opendir(units_dir);
                 if (!d) {
diff --git a/src/shared/path-util.c b/src/shared/path-util.c
index 6b13f02..5bc5012 100644
--- a/src/shared/path-util.c
+++ b/src/shared/path-util.c
@@ -435,6 +435,22 @@ bool path_equal(const char *a, const char *b) {
         }
 }
 
+char* path_join(const char *root, const char *path, const char *rest) {
+        assert(path);
+
+        if (!isempty(root))
+                return strjoin(root, "/",
+                               path[0] == '/' ? path+1 : path,
+                               rest ? "/" : NULL,
+                               rest && rest[0] == '/' ? rest+1 : rest,
+                               NULL);
+        else
+                return strjoin(path,
+                               rest ? "/" : NULL,
+                               rest && rest[0] == '/' ? rest+1 : rest,
+                               NULL);
+}
+
 int path_is_mount_point(const char *t, bool allow_symlink) {
 
         union file_handle_union h = {
diff --git a/src/shared/path-util.h b/src/shared/path-util.h
index 976d2b2..d85291b 100644
--- a/src/shared/path-util.h
+++ b/src/shared/path-util.h
@@ -45,6 +45,7 @@ int path_make_relative(const char *from_dir, const char *to_path, char **_r);
 char* path_kill_slashes(char *path);
 char* path_startswith(const char *path, const char *prefix) _pure_;
 bool path_equal(const char *a, const char *b) _pure_;
+char* path_join(const char *root, const char *path, const char *rest);
 
 char** path_strv_make_absolute_cwd(char **l);
 char** path_strv_resolve(char **l, const char *prefix);
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 0631190..599d590 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -4998,11 +4998,8 @@ static int enable_sysv_units(const char *verb, char **args) {
                 STRV_FOREACH(k, paths.unit_path) {
                         _cleanup_free_ char *path = NULL;
 
-                        if (!isempty(arg_root))
-                                j = asprintf(&path, "%s/%s/%s", arg_root, *k, name);
-                        else
-                                j = asprintf(&path, "%s/%s", *k, name);
-                        if (j < 0)
+                        path = path_join(arg_root, *k, name);
+                        if (!path)
                                 return log_oom();
 
                         found_native = access(path, F_OK) >= 0;
@@ -5013,11 +5010,8 @@ static int enable_sysv_units(const char *verb, char **args) {
                 if (found_native)
                         continue;
 
-                if (!isempty(arg_root))
-                        j = asprintf(&p, "%s/" SYSTEM_SYSVINIT_PATH "/%s", arg_root, name);
-                else
-                        j = asprintf(&p, SYSTEM_SYSVINIT_PATH "/%s", name);
-                if (j < 0)
+                p = path_join(arg_root, SYSTEM_SYSVINIT_PATH, name);
+                if (!p)
                         return log_oom();
 
                 p[strlen(p) - strlen(".service")] = 0;
diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c
index 19462c3..c8dcd85 100644
--- a/src/test/test-path-util.c
+++ b/src/test/test-path-util.c
@@ -162,6 +162,20 @@ static void test_prefixes(void) {
         }
 }
 
+static void test_path_join(void) {
+        assert_se(streq(path_join("/root", "/a/b", "/c"), "/root/a/b/c"));
+        assert_se(streq(path_join("/root", "a/b", "c"), "/root/a/b/c"));
+        assert_se(streq(path_join("/root", "/a/b", "c"), "/root/a/b/c"));
+        assert_se(streq(path_join("/root", "/", "c"), "/root//c"));
+        assert_se(streq(path_join("/root", "/", NULL), "/root/"));
+
+        assert_se(streq(path_join(NULL, "/a/b", "/c"), "/a/b/c"));
+        assert_se(streq(path_join(NULL, "a/b", "c"), "a/b/c"));
+        assert_se(streq(path_join(NULL, "/a/b", "c"), "/a/b/c"));
+        assert_se(streq(path_join(NULL, "/", "c"), "//c"));
+        assert_se(streq(path_join(NULL, "/", NULL), "/"));
+}
+
 static void test_fsck_exists(void) {
         /* Ensure we use a sane default for PATH. */
         unsetenv("PATH");
@@ -225,6 +239,7 @@ int main(int argc, char **argv) {
         test_path();
         test_find_binary(argv[0]);
         test_prefixes();
+        test_path_join();
         test_fsck_exists();
         test_make_relative();
         test_strv_resolve();

commit 60731f32f1d25070ed7559bdd64d65e7462a4df6
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Sat Jul 26 14:03:11 2014 -0400

    systemctl: do not bother to mutate state on error
    
    We will abort anyway.

diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index f3d7fc8..0631190 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -5002,10 +5002,8 @@ static int enable_sysv_units(const char *verb, char **args) {
                                 j = asprintf(&path, "%s/%s/%s", arg_root, *k, name);
                         else
                                 j = asprintf(&path, "%s/%s", *k, name);
-                        if (j < 0) {
-                                r = log_oom();
-                                goto finish;
-                        }
+                        if (j < 0)
+                                return log_oom();
 
                         found_native = access(path, F_OK) >= 0;
                         if (found_native)
@@ -5019,10 +5017,8 @@ static int enable_sysv_units(const char *verb, char **args) {
                         j = asprintf(&p, "%s/" SYSTEM_SYSVINIT_PATH "/%s", arg_root, name);
                 else
                         j = asprintf(&p, SYSTEM_SYSVINIT_PATH "/%s", name);
-                if (j < 0) {
-                        r = log_oom();
-                        goto finish;
-                }
+                if (j < 0)
+                        return log_oom();
 
                 p[strlen(p) - strlen(".service")] = 0;
                 found_sysv = access(p, F_OK) >= 0;
@@ -5044,18 +5040,15 @@ static int enable_sysv_units(const char *verb, char **args) {
                 argv[c] = NULL;
 
                 l = strv_join((char**)argv, " ");
-                if (!l) {
-                        r = log_oom();
-                        goto finish;
-                }
+                if (!l)
+                        return log_oom();
 
                 log_info("Executing %s", l);
 
                 pid = fork();
                 if (pid < 0) {
                         log_error("Failed to fork: %m");
-                        r = -errno;
-                        goto finish;
+                        return -errno;
                 } else if (pid == 0) {
                         /* Child */
 
@@ -5066,8 +5059,7 @@ static int enable_sysv_units(const char *verb, char **args) {
                 j = wait_for_terminate(pid, &status);
                 if (j < 0) {
                         log_error("Failed to wait for child: %s", strerror(-r));
-                        r = j;
-                        goto finish;
+                        return j;
                 }
 
                 if (status.si_code == CLD_EXITED) {
@@ -5081,17 +5073,12 @@ static int enable_sysv_units(const char *verb, char **args) {
                                                 puts("disabled");
                                 }
 
-                        } else if (status.si_status != 0) {
-                                r = -EINVAL;
-                                goto finish;
-                        }
-                } else {
-                        r = -EPROTO;
-                        goto finish;
-                }
+                        } else if (status.si_status != 0)
+                                return -EINVAL;
+                } else
+                        return -EPROTO;
         }
 
-finish:
         /* Drop all SysV units */
         for (f = 0, t = 0; args[f]; f++) {
 

commit 5b6f6ebd63a0d212738ee50e9bc357120af6d3ce
Author: Daniel Buch <boogiewasthere at gmail.com>
Date:   Thu Jul 24 23:29:40 2014 +0200

    analyze: fix seg-fault with no cl-argument
    
    We need to check if argv[1] is set before compare

diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c
index 66e2aab..453ad33 100644
--- a/src/analyze/analyze.c
+++ b/src/analyze/analyze.c
@@ -1349,7 +1349,7 @@ int main(int argc, char *argv[]) {
         if (r <= 0)
                 goto finish;
 
-        if (streq(argv[optind], "verify"))
+        if (streq_ptr(argv[optind], "verify"))
                 r = verify_units(argv+optind+1,
                                  arg_user ? SYSTEMD_USER : SYSTEMD_SYSTEM,
                                  arg_man);

commit 7de80bfe2e61d5818601ccfddbadad3b7703ed70
Author: Karel Zak <kzak at redhat.com>
Date:   Fri Jul 25 15:38:31 2014 +0200

    Always check asprintf return code
    
    There is a small number of the places in sources where we don't check
    asprintf() return code and assume that after error the function
    returns NULL pointer via the first argument. That's wrong, after
    error the content of pointer is undefined.

diff --git a/src/core/unit-printf.c b/src/core/unit-printf.c
index 5bd30f0..62599d0 100644
--- a/src/core/unit-printf.c
+++ b/src/core/unit-printf.c
@@ -182,7 +182,7 @@ static int specifier_user_name(char specifier, void *data, void *userdata, char
         char *printed = NULL;
         Unit *u = userdata;
         ExecContext *c;
-        int r;
+        int r = 0;
 
         assert(u);
 
@@ -208,7 +208,7 @@ static int specifier_user_name(char specifier, void *data, void *userdata, char
                                 if (r < 0)
                                         return -ENODATA;
 
-                                asprintf(&printed, UID_FMT, uid);
+                                r = asprintf(&printed, UID_FMT, uid);
                         }
                 }
 
@@ -231,10 +231,10 @@ static int specifier_user_name(char specifier, void *data, void *userdata, char
                 if (specifier == 'u')
                         printed = strdup(username);
                 else
-                        asprintf(&printed, UID_FMT, uid);
+                        r = asprintf(&printed, UID_FMT, uid);
         }
 
-        if (!printed)
+        if (r < 0 || !printed)
                 return -ENOMEM;
 
         *ret = printed;
diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c
index a67d85e..67dc88f 100644
--- a/src/cryptsetup/cryptsetup.c
+++ b/src/cryptsetup/cryptsetup.c
@@ -549,13 +549,18 @@ int main(int argc, char *argv[]) {
                         description = NULL;
                 }
 
+                k = 0;
                 if (mount_point && description)
-                        asprintf(&name_buffer, "%s (%s) on %s", description, argv[2], mount_point);
+                        k = asprintf(&name_buffer, "%s (%s) on %s", description, argv[2], mount_point);
                 else if (mount_point)
-                        asprintf(&name_buffer, "%s on %s", argv[2], mount_point);
+                        k = asprintf(&name_buffer, "%s on %s", argv[2], mount_point);
                 else if (description)
-                        asprintf(&name_buffer, "%s (%s)", description, argv[2]);
+                        k = asprintf(&name_buffer, "%s (%s)", description, argv[2]);
 
+                if (k < 0) {
+                        log_oom();
+                        goto finish;
+                }
                 name = name_buffer ? name_buffer : argv[2];
 
                 k = crypt_init(&cd, argv[3]);
diff --git a/src/journal/coredump.c b/src/journal/coredump.c
index 182c2b1..fee0a90 100644
--- a/src/journal/coredump.c
+++ b/src/journal/coredump.c
@@ -591,9 +591,9 @@ int main(int argc, char* argv[]) {
         }
 
         if (sd_pid_get_owner_uid(pid, &owner_uid) >= 0) {
-                asprintf(&core_owner_uid, "COREDUMP_OWNER_UID=" UID_FMT, owner_uid);
-
-                if (core_owner_uid)
+                r = asprintf(&core_owner_uid,
+                             "COREDUMP_OWNER_UID=" UID_FMT, owner_uid);
+                if (r > 0)
                         IOVEC_SET_STRING(iovec[j++], core_owner_uid);
         }
 
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 7aedbf0..5a59a3a 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -746,11 +746,17 @@ static int add_matches(sd_journal *j, char **args) {
                                         }
                                 } else
                                         t = strappend("_EXE=", path);
-                        } else if (S_ISCHR(st.st_mode))
-                                asprintf(&t, "_KERNEL_DEVICE=c%u:%u", major(st.st_rdev), minor(st.st_rdev));
-                        else if (S_ISBLK(st.st_mode))
-                                asprintf(&t, "_KERNEL_DEVICE=b%u:%u", major(st.st_rdev), minor(st.st_rdev));
-                        else {
+                        } else if (S_ISCHR(st.st_mode)) {
+                                if (asprintf(&t, "_KERNEL_DEVICE=c%u:%u",
+                                             major(st.st_rdev),
+                                             minor(st.st_rdev)) < 0)
+                                        return -ENOMEM;
+                        } else if (S_ISBLK(st.st_mode)) {
+                                if (asprintf(&t, "_KERNEL_DEVICE=b%u:%u",
+                                             major(st.st_rdev),
+                                             minor(st.st_rdev)) < 0)
+                                        return -ENOMEM;
+                        } else {
                                 log_error("File is neither a device node, nor regular file, nor executable: %s", *i);
                                 return -EINVAL;
                         }
diff --git a/src/run/run.c b/src/run/run.c
index 9d5527b..b9be145 100644
--- a/src/run/run.c
+++ b/src/run/run.c
@@ -335,11 +335,11 @@ static int start_transient_service(
         _cleanup_free_ char *name = NULL;
         int r;
 
-        if (arg_unit)
+        if (arg_unit) {
                 name = unit_name_mangle_with_suffix(arg_unit, MANGLE_NOGLOB, ".service");
-        else
-                asprintf(&name, "run-"PID_FMT".service", getpid());
-        if (!name)
+                if (!name)
+                        return log_oom();
+        } else if (asprintf(&name, "run-"PID_FMT".service", getpid()) < 0)
                 return log_oom();
 
         r = message_start_transient_unit_new(bus, name, &m);
@@ -471,11 +471,11 @@ static int start_transient_scope(
 
         assert(bus);
 
-        if (arg_unit)
+        if (arg_unit) {
                 name = unit_name_mangle_with_suffix(arg_unit, MANGLE_NOGLOB, ".scope");
-        else
-                asprintf(&name, "run-"PID_FMT".scope", getpid());
-        if (!name)
+                if (!name)
+                        return log_oom();
+        } else if (asprintf(&name, "run-"PID_FMT".scope", getpid()) < 0)
                 return log_oom();
 
         r = message_start_transient_unit_new(bus, name, &m);
diff --git a/src/shared/install.c b/src/shared/install.c
index a2f84f8..e957c33 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -88,13 +88,16 @@ static int get_config_path(UnitFileScope scope, bool runtime, const char *root_d
 
         case UNIT_FILE_SYSTEM:
 
-                if (root_dir && runtime)
-                        asprintf(&p, "%s/run/systemd/system", root_dir);
-                else if (runtime)
+                if (root_dir && runtime) {
+                        if (asprintf(&p, "%s/run/systemd/system", root_dir) < 0)
+                                return -ENOMEM;
+                } else if (runtime)
                         p = strdup("/run/systemd/system");
-                else if (root_dir)
-                        asprintf(&p, "%s/%s", root_dir, SYSTEM_CONFIG_UNIT_PATH);
-                else
+                else if (root_dir) {
+                        if (asprintf(&p, "%s/%s", root_dir,
+                                     SYSTEM_CONFIG_UNIT_PATH) < 0)
+                                return -ENOMEM;
+                } else
                         p = strdup(SYSTEM_CONFIG_UNIT_PATH);
 
                 break;
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index fc32509..f3d7fc8 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -4999,11 +4999,10 @@ static int enable_sysv_units(const char *verb, char **args) {
                         _cleanup_free_ char *path = NULL;
 
                         if (!isempty(arg_root))
-                                asprintf(&path, "%s/%s/%s", arg_root, *k, name);
+                                j = asprintf(&path, "%s/%s/%s", arg_root, *k, name);
                         else
-                                asprintf(&path, "%s/%s", *k, name);
-
-                        if (!path) {
+                                j = asprintf(&path, "%s/%s", *k, name);
+                        if (j < 0) {
                                 r = log_oom();
                                 goto finish;
                         }
@@ -5017,10 +5016,10 @@ static int enable_sysv_units(const char *verb, char **args) {
                         continue;
 
                 if (!isempty(arg_root))
-                        asprintf(&p, "%s/" SYSTEM_SYSVINIT_PATH "/%s", arg_root, name);
+                        j = asprintf(&p, "%s/" SYSTEM_SYSVINIT_PATH "/%s", arg_root, name);
                 else
-                        asprintf(&p, SYSTEM_SYSVINIT_PATH "/%s", name);
-                if (!p) {
+                        j = asprintf(&p, SYSTEM_SYSVINIT_PATH "/%s", name);
+                if (j < 0) {
                         r = log_oom();
                         goto finish;
                 }
diff --git a/src/tty-ask-password-agent/tty-ask-password-agent.c b/src/tty-ask-password-agent/tty-ask-password-agent.c
index a7fce51..2c540ba 100644
--- a/src/tty-ask-password-agent/tty-ask-password-agent.c
+++ b/src/tty-ask-password-agent/tty-ask-password-agent.c
@@ -102,8 +102,9 @@ static int ask_password_plymouth(
         if (accept_cached) {
                 packet = strdup("c");
                 n = 1;
-        } else
-                asprintf(&packet, "*\002%c%s%n", (int) (strlen(message) + 1), message, &n);
+        } else if (asprintf(&packet, "*\002%c%s%n", (int) (strlen(message) + 1),
+                            message, &n) < 0)
+                packet = NULL;
 
         if (!packet) {
                 r = -ENOMEM;

commit 6d314eca15f6cbda38d82774b210f784d3d4f52a
Author: Eric Cook <llua at gmx.com>
Date:   Sat Jul 26 11:15:52 2014 -0400

    shell-completion: prevent mangling unit names
    
    Units with literal hex '\xFF' in their names has to be read
    and printed properly.
    dev-disk-byx2dlabel-root.device != dev-disk-by\x2dlabel-root.device

diff --git a/shell-completion/zsh/_systemctl.in b/shell-completion/zsh/_systemctl.in
index d364d17..e681ec6 100644
--- a/shell-completion/zsh/_systemctl.in
+++ b/shell-completion/zsh/_systemctl.in
@@ -100,7 +100,7 @@ _systemctl_all_units()
   if ( [[ ${+_sys_all_units} -eq 0 ]] || _cache_invalid SYS_ALL_UNITS ) &&
     ! _retrieve_cache SYS_ALL_UNITS;
   then
-    _sys_all_units=( $(__systemctl list-units --all | { while read a b; do echo " $a"; done; }) )
+    _sys_all_units=( $(__systemctl list-units --all | { while read -r a b; do echo -E - " $a"; done; }) )
     _store_cache SYS_ALL_UNITS _sys_all_units
   fi
 }
@@ -113,7 +113,7 @@ _systemctl_really_all_units()
   if ( [[ ${+_sys_really_all_units} -eq 0 ]] || _cache_invalid SYS_REALLY_ALL_UNITS ) &&
     ! _retrieve_cache SYS_REALLY_ALL_UNITS;
   then
-    all_unit_files=( $(__systemctl list-unit-files | { while read a b; do echo " $a"; done; }) )
+    all_unit_files=( $(__systemctl list-unit-files | { while read -r a b; do echo -E - " $a"; done; }) )
     _systemctl_all_units
     really_all_units=($_sys_all_units $all_unit_files)
     _sys_really_all_units=(${(u)really_all_units})
@@ -138,12 +138,12 @@ _filter_units_by_property() {
   done
 }
 
-_systemctl_active_units()  {_sys_active_units=(  $(__systemctl list-units          | { while read a b; do echo " $a"; done; }) )}
-_systemctl_inactive_units(){_sys_inactive_units=($(__systemctl list-units --all    | { while read a b c d; do [[ $c == "inactive" || $c == "failed" ]] && echo " $a"; done; }) )}
-_systemctl_failed_units()  {_sys_failed_units=(  $(__systemctl list-units --failed | { while read a b; do echo " $a"; done; }) )}
-_systemctl_enabled_units() {_sys_enabled_units=( $(__systemctl list-unit-files     | { while read a b; do [[ $b == "enabled" ]] && echo " $a"; done; }) )}
-_systemctl_disabled_units(){_sys_disabled_units=($(__systemctl list-unit-files     | { while read a b; do [[ $b == "disabled" ]] && echo " $a"; done; }) )}
-_systemctl_masked_units()  {_sys_masked_units=(  $(__systemctl list-unit-files     | { while read a b; do [[ $b == "masked" ]] && echo " $a"; done; }) )}
+_systemctl_active_units()  {_sys_active_units=(  $(__systemctl list-units          | { while read -r a b; do echo -E - " $a"; done; }) )}
+_systemctl_inactive_units(){_sys_inactive_units=($(__systemctl list-units --all    | { while read -r a b c d; do [[ $c == "inactive" || $c == "failed" ]] && echo -E - " $a"; done; }) )}
+_systemctl_failed_units()  {_sys_failed_units=(  $(__systemctl list-units --failed | { while read -r a b; do echo -E - " $a"; done; }) )}
+_systemctl_enabled_units() {_sys_enabled_units=( $(__systemctl list-unit-files     | { while read -r a b; do [[ $b == "enabled" ]] && echo -E - " $a"; done; }) )}
+_systemctl_disabled_units(){_sys_disabled_units=($(__systemctl list-unit-files     | { while read -r a b; do [[ $b == "disabled" ]] && echo -E - " $a"; done; }) )}
+_systemctl_masked_units()  {_sys_masked_units=(  $(__systemctl list-unit-files     | { while read -r a b; do [[ $b == "masked" ]] && echo -E - " $a"; done; }) )}
 
 # Completion functions for ALL_UNITS
 for fun in is-active is-failed is-enabled status show cat mask preset help list-dependencies ; do
@@ -219,8 +219,8 @@ for fun in restart reload-or-restart ; do
   {
     _systemctl_all_units
     compadd "$@" - $( _filter_units_by_property CanStart yes \
-      ${_sys_all_units[*]} | while read line; do \
-      [[ "$line" =~ \.device$ ]] || echo " $line"; \
+      ${_sys_all_units[*]} | while read -r line; do \
+      [[ "$line" =~ \.device$ ]] || echo -E - " $line"; \
       done )
   }
 done



More information about the systemd-commits mailing list