[systemd-commits] 8 commits - src/core src/journal src/libsystemd-id128 src/shared src/systemctl src/test src/timedate src/udev

Zbigniew Jędrzejewski-Szmek zbyszek at kemper.freedesktop.org
Thu Apr 4 21:36:28 PDT 2013


 src/core/load-dropin.c            |    1 
 src/journal/journald-rate-limit.c |   15 -----------
 src/journal/test-catalog.c        |    1 
 src/libsystemd-id128/sd-id128.c   |    3 ++
 src/shared/efivars.c              |   15 ++++++-----
 src/shared/util.h                 |    4 ++
 src/systemctl/systemctl.c         |   12 +++++---
 src/test/test-strv.c              |    2 -
 src/test/test-util.c              |   11 ++++++++
 src/timedate/timedated.c          |   51 +++++++++++---------------------------
 src/udev/udevadm-hwdb.c           |    3 +-
 11 files changed, 54 insertions(+), 64 deletions(-)

New commits:
commit 1e64bbc15671db861c811bdf63014eee826a6eca
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Fri Apr 5 00:31:59 2013 -0400

    test-strv: do not declare table to be sorted const
    
    Segmentation fault under clang.

diff --git a/src/test/test-strv.c b/src/test/test-strv.c
index 2a1c005..074e1bb 100644
--- a/src/test/test-strv.c
+++ b/src/test/test-strv.c
@@ -161,7 +161,7 @@ static void test_strv_overlap(void) {
 }
 
 static void test_strv_sort(void) {
-        const char * const input_table[] = {
+        const char* input_table[] = {
                 "durian",
                 "apple",
                 "citrus",

commit 737563e4bb1606cae1dd0e9484f9e82da466fe76
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Fri Apr 5 00:03:24 2013 -0400

    test-catalog,core/load-dropin: remove unused variables

diff --git a/src/core/load-dropin.c b/src/core/load-dropin.c
index 942ad02..95c4f89 100644
--- a/src/core/load-dropin.c
+++ b/src/core/load-dropin.c
@@ -173,7 +173,6 @@ char **unit_find_dropin_paths(Unit *u) {
 int unit_load_dropin(Unit *u) {
         Iterator i;
         char *t, **f;
-        _cleanup_strv_free_ char **strv = NULL;
         int r;
 
         assert(u);
diff --git a/src/journal/test-catalog.c b/src/journal/test-catalog.c
index 21149f1..c463035 100644
--- a/src/journal/test-catalog.c
+++ b/src/journal/test-catalog.c
@@ -89,7 +89,6 @@ static const char* database = NULL;
 
 static void test_catalog_update(void) {
         int r;
-        char _cleanup_free_ *path = NULL;
 
         static char name[] = "/tmp/test-catalog.XXXXXX";
         r = mkstemp(name);

commit 144e51eca20b72c8177314c225d8c15c1b0b9d6b
Author: Cristian Rodríguez <crrodriguez at opensuse.org>
Date:   Thu Apr 4 20:09:50 2013 -0300

    journal: u64log2 can be expressed just as __builtin_clzll(n) ^ 63U

diff --git a/src/journal/journald-rate-limit.c b/src/journal/journald-rate-limit.c
index 8bd6847..da3aed6 100644
--- a/src/journal/journald-rate-limit.c
+++ b/src/journal/journald-rate-limit.c
@@ -170,21 +170,6 @@ fail:
         return NULL;
 }
 
-static uint64_t u64log2(uint64_t n) {
-        unsigned r;
-
-        if (n <= 1)
-                return 0;
-
-        r = 0;
-        for (;;) {
-                n = n >> 1;
-                if (!n)
-                        return r;
-                r++;
-        }
-}
-
 static unsigned burst_modulate(unsigned burst, uint64_t available) {
         unsigned k;
 
diff --git a/src/shared/util.h b/src/shared/util.h
index 69a4765..7c3da08 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -635,3 +635,7 @@ static inline void _reset_umask_(struct umask_struct *s) {
         for (__attribute__((cleanup(_reset_umask_))) struct umask_struct _saved_umask_ = { umask(mask), false }; \
              !_saved_umask_.quit ;                                      \
              _saved_umask_.quit = true)
+
+static inline unsigned u64log2(uint64_t n) {
+        return (n > 1) ? __builtin_clzll(n) ^ 63U : 0;
+}
diff --git a/src/test/test-util.c b/src/test/test-util.c
index 08310c8..eaf7e22 100644
--- a/src/test/test-util.c
+++ b/src/test/test-util.c
@@ -338,6 +338,16 @@ static void test_hostname_is_valid(void) {
         assert(!hostname_is_valid("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"));
 }
 
+static void test_u64log2(void) {
+        assert(u64log2(0) == 0);
+        assert(u64log2(8) == 3);
+        assert(u64log2(9) == 3);
+        assert(u64log2(15) == 3);
+        assert(u64log2(16) == 4);
+        assert(u64log2(1024*1024) == 20);
+        assert(u64log2(1024*1024+5) == 20);
+}
+
 int main(int argc, char *argv[]) {
         test_streq_ptr();
         test_first_word();
@@ -363,6 +373,7 @@ int main(int argc, char *argv[]) {
         test_memdup_multiply();
         test_bus_path_escape();
         test_hostname_is_valid();
+        test_u64log2();
 
         return 0;
 }

commit e8853816bf197afc71819e28f1316a5d5ee4b4c3
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Thu Apr 4 21:14:32 2013 -0400

    systemctl: align cgroups to 'n' in 'name='
    
    Also drop ':' in repeated Docs lines.

diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index fe71085..a7c2eef 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -2387,7 +2387,7 @@ static void print_status_info(UnitStatusInfo *i) {
                 printf(" %*s: %s\n", maxlen, "What", i->what);
 
         STRV_FOREACH(t, i->documentation)
-                printf(" %*s: %s\n", maxlen, t == i->documentation ? "Docs" : "", *t);
+                printf(" %*s %s\n", maxlen+1, t == i->documentation ? "Docs:" : "", *t);
 
         STRV_FOREACH_PAIR(t, t2, i->listen)
                 printf(" %*s%s: %s\n", maxlen - (int)strlen(*t), "Listen", *t, *t2);
@@ -2494,10 +2494,13 @@ static void print_status_info(UnitStatusInfo *i) {
                 if (arg_transport != TRANSPORT_SSH) {
                         unsigned k = 0;
                         pid_t extra[2];
+                        char prefix[maxlen + 4];
+                        memset(prefix, ' ', sizeof(prefix) - 1);
+                        prefix[sizeof(prefix) - 1] = '\0';
 
                         c = columns();
-                        if (c > 18)
-                                c -= 18;
+                        if (c > sizeof(prefix) - 1)
+                                c -= sizeof(prefix) - 1;
                         else
                                 c = 0;
 
@@ -2507,7 +2510,8 @@ static void print_status_info(UnitStatusInfo *i) {
                         if (i->control_pid > 0)
                                 extra[k++] = i->control_pid;
 
-                        show_cgroup_and_extra_by_spec(i->default_control_group, "\t\t  ", c, false, extra, k, flags);
+                        show_cgroup_and_extra_by_spec(i->default_control_group, prefix,
+                                                      c, false, extra, k, flags);
                 }
         }
 

commit 54c7d1f454801d3053b99c16b2a371934deb0219
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Wed Apr 3 16:58:16 2013 -0400

    sd-id128: check that the kernel is feeding us proper data
    
    The characters are already checked, so we show that
    we don't trust the kernel. Make sure we don't overrun
    the buffer too.

diff --git a/src/libsystemd-id128/sd-id128.c b/src/libsystemd-id128/sd-id128.c
index 4286ae7..68c4987 100644
--- a/src/libsystemd-id128/sd-id128.c
+++ b/src/libsystemd-id128/sd-id128.c
@@ -170,6 +170,9 @@ _public_ int sd_id128_get_boot(sd_id128_t *ret) {
         for (j = 0, p = buf; j < 16; j++) {
                 int a, b;
 
+                if (p >= buf + k)
+                        return -EIO;
+
                 if (*p == '-')
                         p++;
 

commit ff03aed06a42235a87a3d33e7d812be1e9c8161d
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Wed Apr 3 16:48:46 2013 -0400

    udevadm-hwdb: avoid leak in error path

diff --git a/src/udev/udevadm-hwdb.c b/src/udev/udevadm-hwdb.c
index a2df291..1e80b0d 100644
--- a/src/udev/udevadm-hwdb.c
+++ b/src/udev/udevadm-hwdb.c
@@ -176,11 +176,11 @@ static int trie_insert(struct trie *trie, struct trie_node *node, const char *se
                        const char *key, const char *value) {
         size_t i = 0;
         int err = 0;
+        struct trie_node _cleanup_free_ *child = NULL;
 
         for (;;) {
                 size_t p;
                 uint8_t c;
-                struct trie_node *child;
 
                 for (p = 0; (c = trie->strings->buf[node->prefix_off + p]); p++) {
                         char *s;
@@ -254,6 +254,7 @@ static int trie_insert(struct trie *trie, struct trie_node *node, const char *se
                 }
 
                 node = child;
+                child = NULL; /* avoid cleanup */
                 i++;
         }
 out:

commit 5483a18693871e67cff6d85e43ca843cd976d019
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Wed Apr 3 16:32:01 2013 -0400

    efivars: un-leak a few strings

diff --git a/src/shared/efivars.c b/src/shared/efivars.c
index 06cf127..8d004ba 100644
--- a/src/shared/efivars.c
+++ b/src/shared/efivars.c
@@ -231,10 +231,12 @@ int efi_get_boot_option(
         if (title_size > l - offsetof(struct boot_option, title))
                 return -EINVAL;
 
-        s = utf16_to_utf8(header->title, title_size);
-        if (!s) {
-                err = -ENOMEM;
-                goto err;
+        if (title) {
+                s = utf16_to_utf8(header->title, title_size);
+                if (!s) {
+                        err = -ENOMEM;
+                        goto err;
+                }
         }
 
         if (header->path_len > 0) {
@@ -270,12 +272,13 @@ int efi_get_boot_option(
                                 if (dpath->drive.signature_type != 0x02)
                                         continue;
 
-                                efi_guid_to_id128(dpath->drive.signature, &p_uuid);
+                                if (part_uuid)
+                                        efi_guid_to_id128(dpath->drive.signature, &p_uuid);
                                 continue;
                         }
 
                         /* Sub-Type 4 – File Path */
-                        if (dpath->sub_type == 0x04) {
+                        if (dpath->sub_type == 0x04 && !p && path) {
                                 p = utf16_to_utf8(dpath->path, dpath->length-4);
                                 continue;
                         }

commit d257f05a5f9710c9e6ca558fbabc77e504ca8668
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Tue Apr 2 16:07:21 2013 -0400

    timedated: fix a few memory leaks
    
    Contents of /etc/adjtime and more.

diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
index e068724..4efa806 100644
--- a/src/timedate/timedated.c
+++ b/src/timedate/timedated.c
@@ -216,7 +216,7 @@ static int write_data_timezone(void) {
 
 static int write_data_local_rtc(void) {
         int r;
-        char *s, *w;
+        char _cleanup_free_ *s = NULL, *w = NULL;
 
         r = read_full_file("/etc/adjtime", &s, NULL);
         if (r < 0) {
@@ -234,55 +234,42 @@ static int write_data_local_rtc(void) {
                 size_t a, b;
 
                 p = strchr(s, '\n');
-                if (!p) {
-                        free(s);
+                if (!p)
                         return -EIO;
-                }
 
                 p = strchr(p+1, '\n');
-                if (!p) {
-                        free(s);
+                if (!p)
                         return -EIO;
-                }
 
                 p++;
                 e = strchr(p, '\n');
-                if (!e) {
-                        free(s);
+                if (!e)
                         return -EIO;
-                }
 
                 a = p - s;
                 b = strlen(e);
 
                 w = new(char, a + (tz.local_rtc ? 5 : 3) + b + 1);
-                if (!w) {
-                        free(s);
+                if (!w)
                         return -ENOMEM;
-                }
 
                 *(char*) mempcpy(stpcpy(mempcpy(w, s, a), tz.local_rtc ? "LOCAL" : "UTC"), e, b) = 0;
 
                 if (streq(w, NULL_ADJTIME_UTC)) {
-                        free(w);
-
-                        if (unlink("/etc/adjtime") < 0) {
+                        if (unlink("/etc/adjtime") < 0)
                                 if (errno != ENOENT)
                                         return -errno;
-                        }
 
                         return 0;
                 }
         }
         label_init("/etc");
-        r = write_string_file_atomic_label("/etc/adjtime", w);
-        free(w);
-
-        return r;
+        return write_string_file_atomic_label("/etc/adjtime", w);
 }
 
 static char** get_ntp_services(void) {
-        char **r = NULL, **files, **i;
+        char _cleanup_strv_free_ **r = NULL, **files;
+        char **i;
         int k;
 
         k = conf_files_list(&files, ".list", NULL,
@@ -295,14 +282,14 @@ static char** get_ntp_services(void) {
                 return NULL;
 
         STRV_FOREACH(i, files) {
-                FILE *f;
+                FILE _cleanup_fclose_ *f;
 
                 f = fopen(*i, "re");
                 if (!f)
                         continue;
 
                 for (;;) {
-                        char line[PATH_MAX], *l, **q;
+                        char line[PATH_MAX], *l;
 
                         if (!fgets(line, sizeof(line), f)) {
 
@@ -316,22 +303,16 @@ static char** get_ntp_services(void) {
                         if (l[0] == 0 || l[0] == '#')
                                 continue;
 
-                        q = strv_append(r, l);
-                        if (!q) {
+                        if (strv_extend(&r, l) < 0)
                                 log_oom();
-                                break;
-                        }
-
-                        strv_free(r);
-                        r = q;
+                        return NULL;
                 }
-
-                fclose(f);
         }
 
-        strv_free(files);
+        i = r;
+        r = NULL; /* avoid cleanup */
 
-        return strv_uniq(r);
+        return strv_uniq(i);
 }
 
 static int read_ntp(DBusConnection *bus) {



More information about the systemd-commits mailing list