[systemd-commits] 4 commits - src/core src/journal src/shared src/test

Zbigniew Jędrzejewski-Szmek zbyszek at kemper.freedesktop.org
Sat Aug 30 14:42:15 PDT 2014


 src/core/dbus-manager.c     |    4 -
 src/journal/compress.c      |    6 +-
 src/journal/test-compress.c |   91 +++++++++++++++++++++++++++++++-------------
 src/shared/cgroup-util.c    |   12 +----
 src/test/test-cgroup-util.c |    3 -
 5 files changed, 76 insertions(+), 40 deletions(-)

New commits:
commit a13ee4c792cb5738c3dd13b2a4bb1a828e7994fd
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Fri Aug 29 07:48:33 2014 -0500

    cgroup-util: shorten cg_path_get_session

diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c
index e8cb9c7..00eac64 100644
--- a/src/shared/cgroup-util.c
+++ b/src/shared/cgroup-util.c
@@ -1306,9 +1306,8 @@ int cg_pid_get_machine_name(pid_t pid, char **machine) {
 }
 
 int cg_path_get_session(const char *path, char **session) {
-        const char *e, *n, *x;
+        const char *e, *n, *x, *y;
         char *s;
-        size_t l;
 
         assert(path);
 
@@ -1325,17 +1324,14 @@ int cg_path_get_session(const char *path, char **session) {
         x = startswith(s, "session-");
         if (!x)
                 return -ENOENT;
-        if (!endswith(x, ".scope"))
-                return -ENOENT;
-
-        l = strlen(x);
-        if (l <= 6)
+        y = endswith(x, ".scope");
+        if (!y || x == y)
                 return -ENOENT;
 
         if (session) {
                 char *r;
 
-                r = strndup(x, l - 6);
+                r = strndup(x, y - x);
                 if (!r)
                         return -ENOMEM;
 
diff --git a/src/test/test-cgroup-util.c b/src/test/test-cgroup-util.c
index fda8bcc..68c526a 100644
--- a/src/test/test-cgroup-util.c
+++ b/src/test/test-cgroup-util.c
@@ -106,7 +106,8 @@ static void check_p_g_s(const char *path, int code, const char *result) {
 static void test_path_get_session(void) {
         check_p_g_s("/user.slice/user-1000.slice/session-2.scope/foobar.service", 0, "2");
         check_p_g_s("/session-3.scope", 0, "3");
-        check_p_g_s("", -ENOENT, 0);
+        check_p_g_s("/session-.scope", -ENOENT, NULL);
+        check_p_g_s("", -ENOENT, NULL);
 }
 
 static void check_p_g_o_u(const char *path, int code, uid_t result) {

commit 6ad3b2b62cbe34cc02ee98deb5f48047f5e42d26
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Sat Aug 30 17:22:42 2014 -0400

    systemd: fix error message

diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
index 008cf6b..e792fe7 100644
--- a/src/core/dbus-manager.c
+++ b/src/core/dbus-manager.c
@@ -1241,7 +1241,7 @@ static int method_switch_root(sd_bus *bus, sd_bus_message *message, void *userda
                 return r;
 
         if (m->running_as != SYSTEMD_SYSTEM)
-                return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "KExec is only supported for system managers.");
+                return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Root switching is only supported by system manager.");
 
         r = sd_bus_message_read(message, "ss", &root, &init);
         if (r < 0)
@@ -1252,7 +1252,7 @@ static int method_switch_root(sd_bus *bus, sd_bus_message *message, void *userda
 
         /* Safety check */
         if (isempty(init)) {
-                if (! path_is_os_tree(root))
+                if (!path_is_os_tree(root))
                         return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Specified switch root path %s does not seem to be an OS tree. os-release file is missing.", root);
         } else {
                 _cleanup_free_ char *p = NULL;

commit c552d602ae784c0261ceeb46ace30e6189f38bb2
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Sat Aug 30 14:47:36 2014 -0400

    test-compress: also test with incompressible inputs

diff --git a/src/journal/test-compress.c b/src/journal/test-compress.c
index 026d630..78b3203 100644
--- a/src/journal/test-compress.c
+++ b/src/journal/test-compress.c
@@ -48,25 +48,31 @@ typedef int (decompress_stream_t)(int fdf, int fdt, off_t max_size);
 
 static void test_compress_decompress(int compression,
                                      compress_blob_t compress,
-                                     decompress_blob_t decompress) {
-        char text[] = "foofoofoofoo AAAA aaaaaaaaa ghost busters barbarbar FFF"
-                      "foofoofoofoo AAAA aaaaaaaaa ghost busters barbarbar FFF";
+                                     decompress_blob_t decompress,
+                                     const char *data,
+                                     size_t data_len,
+                                     bool may_fail) {
         char compressed[512];
         size_t csize = 512;
         size_t usize = 0;
         _cleanup_free_ char *decompressed = NULL;
         int r;
 
-        log_info("/* testing %s blob compression/decompression */",
-                 object_compressed_to_string(compression));
-
-        r = compress(text, sizeof(text), compressed, &csize);
-        assert(r == 0);
-        r = decompress(compressed, csize,
-                       (void **) &decompressed, &usize, &csize, 0);
-        assert(r == 0);
-        assert_se(decompressed);
-        assert_se(streq(decompressed, text));
+        log_info("/* testing %s %s blob compression/decompression */",
+                 object_compressed_to_string(compression), data);
+
+        r = compress(data, data_len, compressed, &csize);
+        if (r == -ENOBUFS) {
+                log_info("compression failed: %s", strerror(-r));
+                assert(may_fail);
+        } else {
+                assert(r == 0);
+                r = decompress(compressed, csize,
+                               (void **) &decompressed, &usize, &csize, 0);
+                assert(r == 0);
+                assert_se(decompressed);
+                assert_se(memcmp(decompressed, data, data_len) == 0);
+        }
 
         r = decompress("garbage", 7,
                        (void **) &decompressed, &usize, &csize, 0);
@@ -86,29 +92,38 @@ static void test_compress_decompress(int compression,
 
 static void test_decompress_startswith(int compression,
                                        compress_blob_t compress,
-                                       decompress_sw_t decompress_sw) {
+                                       decompress_sw_t decompress_sw,
+                                       const char *data,
+                                       size_t data_len,
+                                       bool may_fail) {
 
-        char text[] = "foofoofoofoo AAAA aaaaaaaaa ghost busters barbarbar FFF"
-                      "foofoofoofoo AAAA aaaaaaaaa ghost busters barbarbar FFF";
         char compressed[512];
         size_t csize = 512;
         size_t usize = 0;
         _cleanup_free_ char *decompressed = NULL;
+        int r;
 
-        log_info("/* testing decompress_startswith with %s */",
-                 object_compressed_to_string(compression));
+        log_info("/* testing decompress_startswith with %s on %s text*/",
+                 object_compressed_to_string(compression), data);
+
+        r = compress(data, data_len, compressed, &csize);
+        if (r == -ENOBUFS) {
+                log_info("compression failed: %s", strerror(-r));
+                assert(may_fail);
+                return;
+        }
+        assert(r == 0);
 
-        assert_se(compress(text, sizeof(text), compressed, &csize) == 0);
         assert_se(decompress_sw(compressed,
                                 csize,
                                 (void **) &decompressed,
                                 &usize,
-                                "foofoofoofoo", 12, ' ') > 0);
+                                data, strlen(data), '\0') > 0);
         assert_se(decompress_sw(compressed,
                                 csize,
                                 (void **) &decompressed,
                                 &usize,
-                                "foofoofoofoo", 12, 'w') == 0);
+                                data, strlen(data), 'w') == 0);
         assert_se(decompress_sw(compressed,
                                 csize,
                                 (void **) &decompressed,
@@ -118,7 +133,7 @@ static void test_decompress_startswith(int compression,
                                 csize,
                                 (void **) &decompressed,
                                 &usize,
-                                "foofoofoofoo", 12, ' ') > 0);
+                                data, strlen(data), '\0') > 0);
 }
 
 static void test_compress_stream(int compression,
@@ -181,20 +196,44 @@ static void test_compress_stream(int compression,
 }
 
 int main(int argc, char *argv[]) {
+        const char text[] =
+                "text\0foofoofoofoo AAAA aaaaaaaaa ghost busters barbarbar FFF"
+                "foofoofoofoo AAAA aaaaaaaaa ghost busters barbarbar FFF";
+
+        char data[512] = "random\0";
 
         log_set_max_level(LOG_DEBUG);
 
+        random_bytes(data + 7, sizeof(data) - 7);
+
 #ifdef HAVE_XZ
-        test_compress_decompress(OBJECT_COMPRESSED_XZ, compress_blob_xz, decompress_blob_xz);
-        test_decompress_startswith(OBJECT_COMPRESSED_XZ, compress_blob_xz, decompress_startswith_xz);
+        test_compress_decompress(OBJECT_COMPRESSED_XZ, compress_blob_xz, decompress_blob_xz,
+                                 text, sizeof(text), false);
+        test_compress_decompress(OBJECT_COMPRESSED_XZ, compress_blob_xz, decompress_blob_xz,
+                                 data, sizeof(data), true);
+        test_decompress_startswith(OBJECT_COMPRESSED_XZ,
+                                   compress_blob_xz, decompress_startswith_xz,
+                                   text, sizeof(text), false);
+        test_decompress_startswith(OBJECT_COMPRESSED_XZ,
+                                   compress_blob_xz, decompress_startswith_xz,
+                                   data, sizeof(data), true);
         test_compress_stream(OBJECT_COMPRESSED_XZ, "xzcat",
                              compress_stream_xz, decompress_stream_xz, argv[0]);
 #else
         log_info("/* XZ test skipped */");
 #endif
+
 #ifdef HAVE_LZ4
-        test_compress_decompress(OBJECT_COMPRESSED_LZ4, compress_blob_lz4, decompress_blob_lz4);
-        test_decompress_startswith(OBJECT_COMPRESSED_LZ4, compress_blob_lz4, decompress_startswith_lz4);
+        test_compress_decompress(OBJECT_COMPRESSED_LZ4, compress_blob_lz4, decompress_blob_lz4,
+                                 text, sizeof(text), false);
+        test_compress_decompress(OBJECT_COMPRESSED_LZ4, compress_blob_lz4, decompress_blob_lz4,
+                                 data, sizeof(data), true);
+        test_decompress_startswith(OBJECT_COMPRESSED_LZ4,
+                                   compress_blob_lz4, decompress_startswith_lz4,
+                                   text, sizeof(text), false);
+        test_decompress_startswith(OBJECT_COMPRESSED_LZ4,
+                                   compress_blob_lz4, decompress_startswith_lz4,
+                                   data, sizeof(data), true);
 
         /* Produced stream is not compatible with lz4 binary, skip lz4cat check. */
         test_compress_stream(OBJECT_COMPRESSED_LZ4, NULL,

commit b4232628f3d4b00c967310d56c0e95715c9d05cd
Author: Evangelos Foutras <evangelos at foutrelis.com>
Date:   Sat Aug 30 10:13:43 2014 +0300

    journal/compress: use LZ4_compress_continue()
    
    We can't use LZ4_compress_limitedOutput_continue() because in the
    worst-case scenario the compressed output can be slightly bigger than
    the input block. This generally affects very few blocks and is no reason
    to abort the compression process.
    
    I ran into this when I noticed that Chromium core dumps weren't being
    compressed. After switching to LZ4_compress_continue() a ~330MB Chromium
    core dump gets compressed to ~17M.

diff --git a/src/journal/compress.c b/src/journal/compress.c
index 52a4c10..c4c715b 100644
--- a/src/journal/compress.c
+++ b/src/journal/compress.c
@@ -460,10 +460,10 @@ int compress_stream_lz4(int fdf, int fdt, off_t max_bytes) {
 
                 total_in += n;
 
-                r = LZ4_compress_limitedOutput_continue(&lz4_data, buf, out, n, n);
+                r = LZ4_compress_continue(&lz4_data, buf, out, n);
                 if (r == 0) {
-                        log_debug("Compressed size exceeds original, aborting compression.");
-                        return -ENOBUFS;
+                        log_error("LZ4 compression failed.");
+                        return -EBADMSG;
                 }
 
                 header = htole32(r);



More information about the systemd-commits mailing list