[systemd-commits] 2 commits - src/libsystemd src/shared src/systemd src/test src/timedate

Zbigniew Jędrzejewski-Szmek zbyszek at kemper.freedesktop.org
Fri Oct 31 08:32:35 PDT 2014


 src/libsystemd/sd-bus/bus-error.c      |    4 ++--
 src/libsystemd/sd-bus/test-bus-error.c |   15 ++++++++++++++-
 src/shared/bus-errors.c                |    2 +-
 src/shared/bus-errors.h                |    4 ++++
 src/systemd/sd-bus.h                   |   16 +++++++++++++---
 src/test/test-engine.c                 |    6 +++---
 src/timedate/timedated.c               |    2 +-
 7 files changed, 38 insertions(+), 11 deletions(-)

New commits:
commit fedfcdee6f55c3f183752b7fac4879bf41eed60b
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Fri Oct 31 10:07:54 2014 -0400

    Make bus errno mappings non-static
    
    __attribute__((used)) is not enough to force static variables to
    be carried over to a compiled program from a library. Mappings defined
    in libsystemd-shared.a were not visible in the compiled binaries.
    To ensure that the mappings are present in the final binary, the
    tables are made non-static and are given a real unique name by which
    they can be referenced.
    
    To use a mapping defined not in the local compilation unit (e.g. in
    a library) a reference to the mapping table is added. This is done
    by including a declaration in the header file.
    
    Expected values in test-engine are fixed to reflect the new mappings.

diff --git a/src/libsystemd/sd-bus/bus-error.c b/src/libsystemd/sd-bus/bus-error.c
index ad1a66d..cfb8d14 100644
--- a/src/libsystemd/sd-bus/bus-error.c
+++ b/src/libsystemd/sd-bus/bus-error.c
@@ -35,7 +35,7 @@
 #define BUS_ERROR_OOM SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_NO_MEMORY, "Out of memory")
 #define BUS_ERROR_FAILED SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_FAILED, "Operation failed")
 
-SD_BUS_ERROR_MAPPING = {
+SD_BUS_ERROR_MAPPING(sd_bus_standard) = {
         {"org.freedesktop.DBus.Error.Failed",                           EACCES},
         {"org.freedesktop.DBus.Error.NoMemory",                         ENOMEM},
         {"org.freedesktop.DBus.Error.ServiceUnknown",                   EHOSTUNREACH},
diff --git a/src/libsystemd/sd-bus/test-bus-error.c b/src/libsystemd/sd-bus/test-bus-error.c
index aff34a9..ae894e3 100644
--- a/src/libsystemd/sd-bus/test-bus-error.c
+++ b/src/libsystemd/sd-bus/test-bus-error.c
@@ -130,7 +130,7 @@ static void test_errno_mapping_standard(void) {
         assert_se(sd_bus_error_set(NULL, "System.Error.WHATSIT", NULL) == -EIO);
 }
 
-SD_BUS_ERROR_MAPPING = {
+SD_BUS_ERROR_MAPPING(test) = {
         {"org.freedesktop.custom-dbus-error", 5},
         {"org.freedesktop.custom-dbus-error-2", 52},
 };
diff --git a/src/shared/bus-errors.c b/src/shared/bus-errors.c
index 31d00ba..b6f65d2 100644
--- a/src/shared/bus-errors.c
+++ b/src/shared/bus-errors.c
@@ -24,7 +24,7 @@
 #include "sd-bus.h"
 #include "bus-errors.h"
 
-SD_BUS_ERROR_MAPPING = {
+SD_BUS_ERROR_MAPPING(systemd_shared) = {
         {BUS_ERROR_NO_SUCH_UNIT,                 ENOENT},
         {BUS_ERROR_NO_UNIT_FOR_PID,              ESRCH},
         {BUS_ERROR_UNIT_EXISTS,                  EEXIST},
diff --git a/src/shared/bus-errors.h b/src/shared/bus-errors.h
index 504ab1f..1bf19c3 100644
--- a/src/shared/bus-errors.h
+++ b/src/shared/bus-errors.h
@@ -21,6 +21,8 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+#include "sd-bus.h"
+
 #define BUS_ERROR_NO_SUCH_UNIT "org.freedesktop.systemd1.NoSuchUnit"
 #define BUS_ERROR_NO_UNIT_FOR_PID "org.freedesktop.systemd1.NoUnitForPID"
 #define BUS_ERROR_UNIT_EXISTS "org.freedesktop.systemd1.UnitExists"
@@ -67,3 +69,5 @@
 #define BUS_ERROR_CNAME_LOOP "org.freedesktop.resolve1.CNameLoop"
 #define BUS_ERROR_ABORTED "org.freedesktop.resolve1.Aborted"
 #define _BUS_ERROR_DNS "org.freedesktop.resolve1.DnsError."
+
+SD_BUS_ERROR_MAPPING_USE(systemd_shared);
diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h
index c95b5e7..21a6412 100644
--- a/src/systemd/sd-bus.h
+++ b/src/systemd/sd-bus.h
@@ -334,14 +334,24 @@ typedef struct sd_bus_name_error_mapping sd_bus_name_error_mapping;
 
 #define SD_BUS_ERROR_MAKE_CONST(name, message) ((const sd_bus_error) {(name), (message), 0})
 #define SD_BUS_ERROR_NULL SD_BUS_ERROR_MAKE_CONST(NULL, NULL)
+
 #ifndef SD_BUS_ERROR_MAPPING
 #  define _SD_BUS_ERROR_XCONCAT(x, y) x ## y
 #  define _SD_BUS_ERROR_CONCAT(x, y) _SD_BUS_ERROR_XCONCAT(x, y)
-#  define SD_BUS_ERROR_MAPPING \
-        __attribute((__section__("sd_bus_errnomap"))) __attribute((__used__)) \
-        static const sd_bus_name_error_mapping _SD_BUS_ERROR_CONCAT(_sd_bus_errno_mapping_, __COUNTER__)[]
+#  define SD_BUS_ERROR_MAPPING(name)                                    \
+        __attribute((__section__("sd_bus_errnomap")))                   \
+        __attribute((__used__))                                         \
+        const sd_bus_name_error_mapping _SD_BUS_ERROR_CONCAT(_sd_bus_errno_mapping_, name)[]
+#  define SD_BUS_ERROR_MAPPING_USE(name)                                \
+        extern                                                          \
+        const sd_bus_name_error_mapping _SD_BUS_ERROR_CONCAT(_sd_bus_errno_mapping_, name)[]; \
+        __attribute((__used__))                                         \
+        static const sd_bus_name_error_mapping*                         \
+        _SD_BUS_ERROR_CONCAT(sd_bus_name_error_mapping_ref, __COUNTER__) \
+        = _SD_BUS_ERROR_CONCAT(_sd_bus_errno_mapping_, name);
 #endif
 
+
 void sd_bus_error_free(sd_bus_error *e);
 int sd_bus_error_set(sd_bus_error *e, const char *name, const char *message);
 int sd_bus_error_setf(sd_bus_error *e, const char *name, const char *format, ...)  _sd_printf_(3, 4);
diff --git a/src/test/test-engine.c b/src/test/test-engine.c
index 6acd394..456999c 100644
--- a/src/test/test-engine.c
+++ b/src/test/test-engine.c
@@ -66,7 +66,7 @@ int main(int argc, char *argv[]) {
         manager_dump_units(m, stdout, "\t");
 
         printf("Test2: (Cyclic Order, Unfixable)\n");
-        assert_se(manager_add_job(m, JOB_START, d, JOB_REPLACE, false, NULL, &j) == -ENOEXEC);
+        assert_se(manager_add_job(m, JOB_START, d, JOB_REPLACE, false, NULL, &j) == -EDEADLOCK);
         manager_dump_jobs(m, stdout, "\t");
 
         printf("Test3: (Cyclic Order, Fixable, Garbage Collector)\n");
@@ -82,14 +82,14 @@ int main(int argc, char *argv[]) {
         manager_dump_units(m, stdout, "\t");
 
         printf("Test5: (Colliding transaction, fail)\n");
-        assert_se(manager_add_job(m, JOB_START, g, JOB_FAIL, false, NULL, &j) == -EEXIST);
+        assert_se(manager_add_job(m, JOB_START, g, JOB_FAIL, false, NULL, &j) == -EDEADLOCK);
 
         printf("Test6: (Colliding transaction, replace)\n");
         assert_se(manager_add_job(m, JOB_START, g, JOB_REPLACE, false, NULL, &j) == 0);
         manager_dump_jobs(m, stdout, "\t");
 
         printf("Test7: (Unmergeable job type, fail)\n");
-        assert_se(manager_add_job(m, JOB_STOP, g, JOB_FAIL, false, NULL, &j) == -EEXIST);
+        assert_se(manager_add_job(m, JOB_STOP, g, JOB_FAIL, false, NULL, &j) == -EDEADLOCK);
 
         printf("Test8: (Mergeable job type, fail)\n");
         assert_se(manager_add_job(m, JOB_RESTART, g, JOB_FAIL, false, NULL, &j) == 0);
diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
index 49a957c..e720227 100644
--- a/src/timedate/timedated.c
+++ b/src/timedate/timedated.c
@@ -44,7 +44,7 @@
 #define NULL_ADJTIME_UTC "0.0 0 0\n0\nUTC\n"
 #define NULL_ADJTIME_LOCAL "0.0 0 0\n0\nLOCAL\n"
 
-SD_BUS_ERROR_MAPPING = {
+SD_BUS_ERROR_MAPPING(timedated) = {
         {"org.freedesktop.timedate1.NoNTPSupport", ENOTSUP},
 };
 

commit 5e071f200c4cc86443af07a876ee0e1c2901fda1
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Fri Oct 31 09:31:02 2014 -0400

    bus: do not segfault on zeros in errno mapping table
    
    Depending on the link order, holes might appear in the body of
    the sd_bus_errnomap section. Ignore them.
    
    Adds a simple test to print the table to help with debugging such
    issues in the future.

diff --git a/src/libsystemd/sd-bus/bus-error.c b/src/libsystemd/sd-bus/bus-error.c
index 2e64b92..ad1a66d 100644
--- a/src/libsystemd/sd-bus/bus-error.c
+++ b/src/libsystemd/sd-bus/bus-error.c
@@ -80,7 +80,7 @@ static int bus_error_mapping_lookup(const char *name, size_t len) {
         const sd_bus_name_error_mapping *m;
 
         for (m = __start_sd_bus_errnomap; m < __stop_sd_bus_errnomap; m++)
-                if (strneq(m->name, name, len))
+                if (m->name && strneq(m->name, name, len))
                         return m->code;
 
         return EIO;
diff --git a/src/libsystemd/sd-bus/test-bus-error.c b/src/libsystemd/sd-bus/test-bus-error.c
index dd0cca4..aff34a9 100644
--- a/src/libsystemd/sd-bus/test-bus-error.c
+++ b/src/libsystemd/sd-bus/test-bus-error.c
@@ -111,6 +111,18 @@ static void test_error(void) {
         assert_se(sd_bus_error_is_set(&error));
 }
 
+extern const sd_bus_name_error_mapping __start_sd_bus_errnomap[];
+extern const sd_bus_name_error_mapping __stop_sd_bus_errnomap[];
+
+static void dump_mapping_table(void) {
+        const sd_bus_name_error_mapping *m;
+
+        printf("----- errno mappings ------\n");
+        for (m = __start_sd_bus_errnomap; m < __stop_sd_bus_errnomap; m++)
+                printf("%s -> %d\n", m->name, m->code);
+        printf("---------------------------\n");
+}
+
 static void test_errno_mapping_standard(void) {
         assert_se(sd_bus_error_set(NULL, "System.Error.EUCLEAN", NULL) == -EUCLEAN);
         assert_se(sd_bus_error_set(NULL, "System.Error.EBUSY", NULL) == -EBUSY);
@@ -130,6 +142,7 @@ static void test_errno_mapping_custom(void) {
 }
 
 int main(int argc, char *argv[]) {
+        dump_mapping_table();
 
         test_error();
         test_errno_mapping_standard();



More information about the systemd-commits mailing list