summaryrefslogtreecommitdiff
path: root/src/libsystemd
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsystemd')
-rw-r--r--src/libsystemd/sd-bus/.gitignore1
-rw-r--r--src/libsystemd/sd-bus/bus-error-mapping.gperf50
-rw-r--r--src/libsystemd/sd-bus/bus-error.c58
-rw-r--r--src/libsystemd/sd-bus/bus-error.h2
-rw-r--r--src/libsystemd/sd-bus/test-bus-error.c28
5 files changed, 78 insertions, 61 deletions
diff --git a/src/libsystemd/sd-bus/.gitignore b/src/libsystemd/sd-bus/.gitignore
deleted file mode 100644
index d32542e2a6..0000000000
--- a/src/libsystemd/sd-bus/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/bus-error-mapping.c
diff --git a/src/libsystemd/sd-bus/bus-error-mapping.gperf b/src/libsystemd/sd-bus/bus-error-mapping.gperf
deleted file mode 100644
index 59eaa3554b..0000000000
--- a/src/libsystemd/sd-bus/bus-error-mapping.gperf
+++ /dev/null
@@ -1,50 +0,0 @@
-%{
-#include <errno.h>
-#include "bus-error.h"
-%}
-name_error_mapping;
-%null_strings
-%language=ANSI-C
-%define slot-name name
-%define hash-function-name bus_error_mapping_hash
-%define lookup-function-name bus_error_mapping_lookup
-%readonly-tables
-%omit-struct-type
-%struct-type
-%includes
-%%
-org.freedesktop.DBus.Error.Failed, EACCES
-org.freedesktop.DBus.Error.NoMemory, ENOMEM
-org.freedesktop.DBus.Error.ServiceUnknown, EHOSTUNREACH
-org.freedesktop.DBus.Error.NameHasNoOwner, ENXIO
-org.freedesktop.DBus.Error.NoReply, ETIMEDOUT
-org.freedesktop.DBus.Error.IOError, EIO
-org.freedesktop.DBus.Error.BadAddress, EADDRNOTAVAIL
-org.freedesktop.DBus.Error.NotSupported, ENOTSUP
-org.freedesktop.DBus.Error.LimitsExceeded, ENOBUFS
-org.freedesktop.DBus.Error.AccessDenied, EACCES
-org.freedesktop.DBus.Error.AuthFailed, EACCES
-org.freedesktop.DBus.Error.InteractiveAuthorizationRequired EACCES
-org.freedesktop.DBus.Error.NoServer, EHOSTDOWN
-org.freedesktop.DBus.Error.Timeout, ETIMEDOUT
-org.freedesktop.DBus.Error.NoNetwork, ENONET
-org.freedesktop.DBus.Error.AddressInUse, EADDRINUSE
-org.freedesktop.DBus.Error.Disconnected, ECONNRESET
-org.freedesktop.DBus.Error.InvalidArgs, EINVAL
-org.freedesktop.DBus.Error.FileNotFound, ENOENT
-org.freedesktop.DBus.Error.FileExists, EEXIST
-org.freedesktop.DBus.Error.UnknownMethod, EBADR
-org.freedesktop.DBus.Error.UnknownObject, EBADR
-org.freedesktop.DBus.Error.UnknownInterface, EBADR
-org.freedesktop.DBus.Error.UnknownProperty, EBADR
-org.freedesktop.DBus.Error.PropertyReadOnly, EROFS
-org.freedesktop.DBus.Error.UnixProcessIdUnknown, ESRCH
-org.freedesktop.DBus.Error.InvalidSignature, EINVAL
-org.freedesktop.DBus.Error.InconsistentMessage, EBADMSG
-#
-org.freedesktop.DBus.Error.TimedOut, ETIMEDOUT
-org.freedesktop.DBus.Error.MatchRuleInvalid, EINVAL
-org.freedesktop.DBus.Error.InvalidFileContent, EINVAL
-org.freedesktop.DBus.Error.MatchRuleNotFound, ENOENT
-org.freedesktop.DBus.Error.SELinuxSecurityContextUnknown, ESRCH
-org.freedesktop.DBus.Error.ObjectPathInUse, EBUSY
diff --git a/src/libsystemd/sd-bus/bus-error.c b/src/libsystemd/sd-bus/bus-error.c
index af83c12d53..2e64b925f3 100644
--- a/src/libsystemd/sd-bus/bus-error.c
+++ b/src/libsystemd/sd-bus/bus-error.c
@@ -35,10 +35,60 @@
#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 = {
+ {"org.freedesktop.DBus.Error.Failed", EACCES},
+ {"org.freedesktop.DBus.Error.NoMemory", ENOMEM},
+ {"org.freedesktop.DBus.Error.ServiceUnknown", EHOSTUNREACH},
+ {"org.freedesktop.DBus.Error.NameHasNoOwner", ENXIO},
+ {"org.freedesktop.DBus.Error.NoReply", ETIMEDOUT},
+ {"org.freedesktop.DBus.Error.IOError", EIO},
+ {"org.freedesktop.DBus.Error.BadAddress", EADDRNOTAVAIL},
+ {"org.freedesktop.DBus.Error.NotSupported", ENOTSUP},
+ {"org.freedesktop.DBus.Error.LimitsExceeded", ENOBUFS},
+ {"org.freedesktop.DBus.Error.AccessDenied", EACCES},
+ {"org.freedesktop.DBus.Error.AuthFailed", EACCES},
+ {"org.freedesktop.DBus.Error.InteractiveAuthorizationRequired", EACCES},
+ {"org.freedesktop.DBus.Error.NoServer", EHOSTDOWN},
+ {"org.freedesktop.DBus.Error.Timeout", ETIMEDOUT},
+ {"org.freedesktop.DBus.Error.NoNetwork", ENONET},
+ {"org.freedesktop.DBus.Error.AddressInUse", EADDRINUSE},
+ {"org.freedesktop.DBus.Error.Disconnected", ECONNRESET},
+ {"org.freedesktop.DBus.Error.InvalidArgs", EINVAL},
+ {"org.freedesktop.DBus.Error.FileNotFound", ENOENT},
+ {"org.freedesktop.DBus.Error.FileExists", EEXIST},
+ {"org.freedesktop.DBus.Error.UnknownMethod", EBADR},
+ {"org.freedesktop.DBus.Error.UnknownObject", EBADR},
+ {"org.freedesktop.DBus.Error.UnknownInterface", EBADR},
+ {"org.freedesktop.DBus.Error.UnknownProperty", EBADR},
+ {"org.freedesktop.DBus.Error.PropertyReadOnly", EROFS},
+ {"org.freedesktop.DBus.Error.UnixProcessIdUnknown", ESRCH},
+ {"org.freedesktop.DBus.Error.InvalidSignature", EINVAL},
+ {"org.freedesktop.DBus.Error.InconsistentMessage", EBADMSG},
+
+ {"org.freedesktop.DBus.Error.TimedOut", ETIMEDOUT},
+ {"org.freedesktop.DBus.Error.MatchRuleInvalid", EINVAL},
+ {"org.freedesktop.DBus.Error.InvalidFileContent", EINVAL},
+ {"org.freedesktop.DBus.Error.MatchRuleNotFound", ENOENT},
+ {"org.freedesktop.DBus.Error.SELinuxSecurityContextUnknown", ESRCH},
+ {"org.freedesktop.DBus.Error.ObjectPathInUse", EBUSY},
+};
+
+extern const sd_bus_name_error_mapping __start_sd_bus_errnomap[];
+extern const sd_bus_name_error_mapping __stop_sd_bus_errnomap[];
+
+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))
+ return m->code;
+
+ return EIO;
+}
+
static int bus_error_name_to_errno(const char *name) {
const char *p;
int r;
- const name_error_mapping *m;
if (!name)
return EINVAL;
@@ -52,11 +102,7 @@ static int bus_error_name_to_errno(const char *name) {
return r;
}
- m = bus_error_mapping_lookup(name, strlen(name));
- if (m)
- return m->code;
-
- return EIO;
+ return bus_error_mapping_lookup(name, strlen(name));
}
static sd_bus_error errno_to_bus_error_const(int error) {
diff --git a/src/libsystemd/sd-bus/bus-error.h b/src/libsystemd/sd-bus/bus-error.h
index cf0ad9d545..1469486187 100644
--- a/src/libsystemd/sd-bus/bus-error.h
+++ b/src/libsystemd/sd-bus/bus-error.h
@@ -32,8 +32,6 @@ struct name_error_mapping {
};
typedef struct name_error_mapping name_error_mapping;
-const name_error_mapping* bus_error_mapping_lookup(const char *str, unsigned int len);
-
bool bus_error_is_dirty(sd_bus_error *e);
const char *bus_error_message(const sd_bus_error *e, int error);
diff --git a/src/libsystemd/sd-bus/test-bus-error.c b/src/libsystemd/sd-bus/test-bus-error.c
index b78be5499c..dd0cca4ab8 100644
--- a/src/libsystemd/sd-bus/test-bus-error.c
+++ b/src/libsystemd/sd-bus/test-bus-error.c
@@ -23,8 +23,7 @@
#include "bus-error.h"
#include "bus-util.h"
-int main(int argc, char *argv[]) {
-
+static void test_error(void) {
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL, second = SD_BUS_ERROR_NULL;
const sd_bus_error const_error = SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_FILE_EXISTS, "const error");
const sd_bus_error temporarily_const_error = {
@@ -110,6 +109,31 @@ int main(int argc, char *argv[]) {
assert_se(sd_bus_error_has_name(&error, SD_BUS_ERROR_IO_ERROR));
assert_se(sd_bus_error_get_errno(&error) == EIO);
assert_se(sd_bus_error_is_set(&error));
+}
+
+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);
+ assert_se(sd_bus_error_set(NULL, "System.Error.EINVAL", NULL) == -EINVAL);
+ assert_se(sd_bus_error_set(NULL, "System.Error.WHATSIT", NULL) == -EIO);
+}
+
+SD_BUS_ERROR_MAPPING = {
+ {"org.freedesktop.custom-dbus-error", 5},
+ {"org.freedesktop.custom-dbus-error-2", 52},
+};
+
+static void test_errno_mapping_custom(void) {
+ assert_se(sd_bus_error_set(NULL, "org.freedesktop.custom-dbus-error", NULL) == -5);
+ assert_se(sd_bus_error_set(NULL, "org.freedesktop.custom-dbus-error-2", NULL) == -52);
+ assert_se(sd_bus_error_set(NULL, "org.freedesktop.custom-dbus-error-x", NULL) == -EIO);
+}
+
+int main(int argc, char *argv[]) {
+
+ test_error();
+ test_errno_mapping_standard();
+ test_errno_mapping_custom();
return 0;
}