[systemd-commits] 12 commits - src/core src/libsystemd src/libsystemd-terminal src/login src/machine src/network src/nspawn src/shared src/systemctl src/udev

Zbigniew Jędrzejewski-Szmek zbyszek at kemper.freedesktop.org
Sat Mar 7 12:08:43 PST 2015


 src/core/dbus-manager.c                 |    3 ---
 src/core/load-fragment.c                |    3 +--
 src/libsystemd-terminal/idev-keyboard.c |    7 ++-----
 src/libsystemd/sd-bus/bus-message.c     |    9 ++++-----
 src/libsystemd/sd-bus/bus-util.c        |    1 -
 src/login/inhibit.c                     |    2 +-
 src/machine/machine-dbus.c              |    8 +++++---
 src/network/networkctl.c                |   12 ++++++------
 src/nspawn/nspawn.c                     |    4 ++--
 src/shared/machine-pool.c               |    3 +--
 src/systemctl/systemctl.c               |    4 ++--
 src/udev/v4l_id/v4l_id.c                |   19 +++++++++----------
 12 files changed, 33 insertions(+), 42 deletions(-)

New commits:
commit bcf88fc3f14867f1cabc911c27b661d738281df0
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Sat Mar 7 15:05:50 2015 -0500

    bus: fix leak in error path
    
    CID #1271349.

diff --git a/src/libsystemd/sd-bus/bus-message.c b/src/libsystemd/sd-bus/bus-message.c
index 77216a6..7eac069 100644
--- a/src/libsystemd/sd-bus/bus-message.c
+++ b/src/libsystemd/sd-bus/bus-message.c
@@ -440,7 +440,7 @@ int bus_message_from_header(
                 size_t extra,
                 sd_bus_message **ret) {
 
-        sd_bus_message *m;
+        _cleanup_free_ sd_bus_message *m = NULL;
         struct bus_header *h;
         size_t a, label_sz;
 
@@ -459,15 +459,13 @@ int bus_message_from_header(
                 return -EBADMSG;
 
         h = header;
-        if (h->version != 1 &&
-            h->version != 2)
+        if (!IN_SET(h->version, 1, 2))
                 return -EBADMSG;
 
         if (h->type == _SD_BUS_MESSAGE_TYPE_INVALID)
                 return -EBADMSG;
 
-        if (h->endian != BUS_LITTLE_ENDIAN &&
-            h->endian != BUS_BIG_ENDIAN)
+        if (!IN_SET(h->endian, BUS_LITTLE_ENDIAN, BUS_BIG_ENDIAN))
                 return -EBADMSG;
 
         /* Note that we are happy with unknown flags in the flags header! */
@@ -556,6 +554,7 @@ int bus_message_from_header(
 
         m->bus = sd_bus_ref(bus);
         *ret = m;
+        m = NULL;
 
         return 0;
 }

commit 2558691285b2f7b3078b43b26736fcadf3c6d194
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Sat Mar 7 15:00:22 2015 -0500

    systemctl: remove dead check
    
    r could never be less than zero.
    
    CID #1271350.

diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index e915f6f..41f7b9f 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -4547,7 +4547,7 @@ static int cat(sd_bus *bus, char **args) {
         _cleanup_strv_free_ char **names = NULL;
         char **name;
         bool first = true, avoid_bus_cache;
-        int r = 0;
+        int r;
 
         assert(args);
 
@@ -4597,7 +4597,7 @@ static int cat(sd_bus *bus, char **args) {
                 }
         }
 
-        return r < 0 ? r : 0;
+        return 0;
 }
 
 static int set_property(sd_bus *bus, char **args) {

commit d4ad27a104af707b20651327d7a57dd9dc780f79
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Sat Mar 7 14:36:14 2015 -0500

    core/load-fragment: safe_close() protects errno

diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index 6d0192f..ea66ce0 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -3432,9 +3432,8 @@ static int open_follow(char **filename, FILE **_f, Set *names, char **_final) {
 
         f = fdopen(fd, "re");
         if (!f) {
-                r = -errno;
                 safe_close(fd);
-                return r;
+                return -errno;
         }
 
         *_f = f;

commit 33f1b0aeea5a2bc9100360f14f7da1a4f61c3c01
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Sat Mar 7 14:30:56 2015 -0500

    libsystemd-terminal: use at most LOG_ERR for XKB errors
    
    XKB errors aren't *that* important.
    
    Coverity complained that the same action is taken in multiple
    branches, which is semi-valid, so is fixed too (CID #1256582).

diff --git a/src/libsystemd-terminal/idev-keyboard.c b/src/libsystemd-terminal/idev-keyboard.c
index 1ee13ff..f90f1b5 100644
--- a/src/libsystemd-terminal/idev-keyboard.c
+++ b/src/libsystemd-terminal/idev-keyboard.c
@@ -506,12 +506,9 @@ static void kbdctx_log_fn(struct xkb_context *ctx, enum xkb_log_level lvl, const
                 sd_lvl = LOG_INFO;
         else if (lvl >= XKB_LOG_LEVEL_WARNING)
                 sd_lvl = LOG_INFO; /* most XKB warnings really are informational */
-        else if (lvl >= XKB_LOG_LEVEL_ERROR)
-                sd_lvl = LOG_ERR;
-        else if (lvl >= XKB_LOG_LEVEL_CRITICAL)
-                sd_lvl = LOG_CRIT;
         else
-                sd_lvl = LOG_CRIT;
+                /* XKB_LOG_LEVEL_ERROR and worse */
+                sd_lvl = LOG_ERR;
 
         snprintf(buf, sizeof(buf), "idev-xkb: %s", format);
         log_internalv(sd_lvl, 0, __FILE__, __LINE__, __func__, buf, args);

commit dcee01125dde502bd8108c36ddf2026c1348865f
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Sat Mar 7 14:23:38 2015 -0500

    login: fix copy-pasto in error path
    
    CID #1256583.

diff --git a/src/login/inhibit.c b/src/login/inhibit.c
index fcc8d72..9f349b7 100644
--- a/src/login/inhibit.c
+++ b/src/login/inhibit.c
@@ -259,7 +259,7 @@ int main(int argc, char *argv[]) {
 
                 fd = inhibit(bus, &error);
                 if (fd < 0) {
-                        log_error("Failed to inhibit: %s", bus_error_message(&error, -r));
+                        log_error("Failed to inhibit: %s", bus_error_message(&error, fd));
                         return EXIT_FAILURE;
                 }
 

commit 8a16a7b4e7f6702a7e6edaead80ecf04be7d3ba2
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Sat Mar 7 14:19:20 2015 -0500

    nspawn: fix use-after-free and leak in error paths
    
    CID #1257765.

diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 8833704..c851fdd 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -3735,7 +3735,7 @@ int main(int argc, char *argv[]) {
                 }
 
                 if (arg_ephemeral) {
-                        char *np;
+                        _cleanup_free_ char *np = NULL;
 
                         /* If the specified path is a mount point we
                          * generate the new snapshot immediately
@@ -3765,13 +3765,13 @@ int main(int argc, char *argv[]) {
 
                         r = btrfs_subvol_snapshot(arg_directory, np, arg_read_only, true);
                         if (r < 0) {
-                                free(np);
                                 log_error_errno(r, "Failed to create snapshot %s from %s: %m", np, arg_directory);
                                 goto finish;
                         }
 
                         free(arg_directory);
                         arg_directory = np;
+                        np = NULL;
 
                         remove_subvol = true;
 

commit 5eed9d0d85be0767fe6a4d19c7abacb1f09e4b75
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Sat Mar 7 14:16:18 2015 -0500

    core/dbus-manager: remove dead check
    
    CID #1257766.

diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
index feca6e8..76901c7 100644
--- a/src/core/dbus-manager.c
+++ b/src/core/dbus-manager.c
@@ -675,9 +675,6 @@ static int transient_aux_units_from_message(
                 return r;
 
         while ((r = sd_bus_message_enter_container(message, 'r', "sa(sv)")) > 0) {
-                if (r <= 0)
-                        return r;
-
                 r = sd_bus_message_read(message, "s", &name);
                 if (r < 0)
                         return r;

commit 42115af0c3f20b739b0c761858bd8dc0d3957709
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Sat Mar 7 14:09:50 2015 -0500

    bus-util: remove stray errno assignment

diff --git a/src/libsystemd/sd-bus/bus-util.c b/src/libsystemd/sd-bus/bus-util.c
index 3bd6b8d..28b33ab 100644
--- a/src/libsystemd/sd-bus/bus-util.c
+++ b/src/libsystemd/sd-bus/bus-util.c
@@ -1790,7 +1790,6 @@ int bus_wait_for_jobs(BusWaitForJobs *d, bool quiet) {
                         if (q < 0 && r == 0)
                                 r = q;
 
-                        errno = 0;
                         log_debug_errno(q, "Got result %s/%m for job %s", strna(d->result), strna(d->name));
                 }
 

commit b4e3d5e14cd5d33d808605892e471bb65640ae76
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Sat Mar 7 14:06:35 2015 -0500

    networkctl: avoid leak if a field was specified twice
    
    The input data would have to be borked, so this is unlikely to happen,
    but since we have a nice helper function to do it properly... why not?
    
    CID #1261390.

diff --git a/src/network/networkctl.c b/src/network/networkctl.c
index 0637513..3a6faa2 100644
--- a/src/network/networkctl.c
+++ b/src/network/networkctl.c
@@ -965,14 +965,14 @@ static int link_lldp_status(int argc, char *argv[], void *userdata) {
                                         continue;
 
                                 if (streq(a, "_Chassis")) {
-                                        chassis = strdup(b);
-                                        if (!chassis)
-                                                return -ENOMEM;
+                                        r = free_and_strdup(&chassis, b);
+                                        if (r < 0)
+                                                return r;
 
                                 } else if (streq(a, "_Port")) {
-                                        port = strdup(b);
-                                        if (!port)
-                                                return -ENOMEM;
+                                        r = free_and_strdup(&port, b);
+                                        if (r < 0)
+                                                return r;
 
                                 } else if (streq(a, "_TTL")) {
                                         long long unsigned x;

commit 2c07315225bef6be4830bce25a74da7f0ba4fcdc
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Sat Mar 7 14:01:45 2015 -0500

    machine: do not rely on asprintf setting arg on error
    
    Strictly speaking, the output variable is undefined if asprintf fails.
    We use the return value not the arg everywhere, and should we do here.

diff --git a/src/machine/machine-dbus.c b/src/machine/machine-dbus.c
index 9e78a67..d6b8c90 100644
--- a/src/machine/machine-dbus.c
+++ b/src/machine/machine-dbus.c
@@ -471,6 +471,7 @@ int bus_machine_method_open_login(sd_bus *bus, sd_bus_message *message, void *us
         _cleanup_close_ int master = -1;
         Machine *m = userdata;
         const char *p;
+        char *address;
         int r;
 
         if (m->class != MACHINE_CONTAINER)
@@ -509,13 +510,14 @@ int bus_machine_method_open_login(sd_bus *bus, sd_bus_message *message, void *us
                 return r;
 
 #ifdef ENABLE_KDBUS
-        asprintf(&container_bus->address, "x-machine-kernel:pid=" PID_FMT ";x-machine-unix:pid=" PID_FMT, m->leader, m->leader);
+#  define ADDRESS_FMT "x-machine-kernel:pid=%1$" PID_PRI ";x-machine-unix:pid=%1$" PID_PRI
 #else
-        asprintf(&container_bus->address, "x-machine-unix:pid=" PID_FMT, m->leader);
+#  define ADDRESS_FMT "x-machine-unix:pid=%1$" PID_PRI
 #endif
-        if (!container_bus->address)
+        if (asprintf(&address, ADDRESS_FMT, m->leader) < 0)
                 return log_oom();
 
+        container_bus->address = address;
         container_bus->bus_client = true;
         container_bus->trusted = false;
         container_bus->is_system = true;

commit fadce6caf57986dc941e5fe3c860998890d49fd2
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Sat Mar 7 13:54:32 2015 -0500

    v4l_id: use standard option parsing loop
    
    Not terribly important, but the loop wasn't an actual loop,
    making coverity unhappy.
    
    CID #1261725.

diff --git a/src/udev/v4l_id/v4l_id.c b/src/udev/v4l_id/v4l_id.c
index 0ebe434..5c57db4 100644
--- a/src/udev/v4l_id/v4l_id.c
+++ b/src/udev/v4l_id/v4l_id.c
@@ -36,29 +36,28 @@ int main(int argc, char *argv[]) {
         _cleanup_close_ int fd = -1;
         char *device;
         struct v4l2_capability v2cap;
+        int c;
 
-        for (;;) {
-                int option;
+        while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
 
-                option = getopt_long(argc, argv, "h", options, NULL);
-                if (option == -1)
-                        break;
-
-                switch (option) {
+                switch (c) {
                 case 'h':
                         printf("%s [-h,--help] <device file>\n\n"
                                "Video4Linux device identification.\n\n"
                                "  -h  Print this message\n"
                                , program_invocation_short_name);
                         return 0;
+                case '?':
+                        return -EINVAL;
+
                 default:
-                        return 1;
+                        assert_not_reached("Unhandled option");
                 }
-        }
-        device = argv[optind];
 
+        device = argv[optind];
         if (device == NULL)
                 return 2;
+
         fd = open(device, O_RDONLY);
         if (fd < 0)
                 return 3;

commit 132764a2236fd6a4acb0e8d698f135c186677ad4
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Sat Mar 7 13:40:48 2015 -0500

    shared/machine-pool: remove unnecessary check
    
    CID #128739.

diff --git a/src/shared/machine-pool.c b/src/shared/machine-pool.c
index 3eafb94..e7671a3 100644
--- a/src/shared/machine-pool.c
+++ b/src/shared/machine-pool.c
@@ -151,8 +151,7 @@ static int setup_machine_raw(uint64_t size, sd_bus_error *error) {
         return r;
 
 fail:
-        if (tmp)
-                unlink_noerrno(tmp);
+        unlink_noerrno(tmp);
 
         if (pid > 1)
                 kill_and_sigcont(pid, SIGKILL);



More information about the systemd-commits mailing list