summaryrefslogtreecommitdiff
path: root/src/libsystemd-bus
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsystemd-bus')
-rw-r--r--src/libsystemd-bus/.gitignore1
-rw-r--r--src/libsystemd-bus/bus-error-mapping.gperf49
-rw-r--r--src/libsystemd-bus/bus-error.c79
-rw-r--r--src/libsystemd-bus/bus-error.h8
4 files changed, 62 insertions, 75 deletions
diff --git a/src/libsystemd-bus/.gitignore b/src/libsystemd-bus/.gitignore
index 5f797a28d5..fcfd804516 100644
--- a/src/libsystemd-bus/.gitignore
+++ b/src/libsystemd-bus/.gitignore
@@ -1 +1,2 @@
/libsystemd-bus.pc
+/bus-error-mapping.c
diff --git a/src/libsystemd-bus/bus-error-mapping.gperf b/src/libsystemd-bus/bus-error-mapping.gperf
new file mode 100644
index 0000000000..df2c4d407d
--- /dev/null
+++ b/src/libsystemd-bus/bus-error-mapping.gperf
@@ -0,0 +1,49 @@
+%{
+#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.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-bus/bus-error.c b/src/libsystemd-bus/bus-error.c
index 25eaf0eee4..35bd4f0daf 100644
--- a/src/libsystemd-bus/bus-error.c
+++ b/src/libsystemd-bus/bus-error.c
@@ -38,6 +38,7 @@
static int bus_error_name_to_errno(const char *name) {
const char *p;
int r;
+ const name_error_mapping *m;
if (!name)
return EINVAL;
@@ -51,81 +52,9 @@ static int bus_error_name_to_errno(const char *name) {
return r;
}
- /* Better replace this with a gperf table */
-
- if (streq(name, SD_BUS_ERROR_NO_MEMORY))
- return ENOMEM;
-
- if (streq(name, SD_BUS_ERROR_SERVICE_UNKNOWN))
- return EHOSTUNREACH;
-
- if (streq(name, SD_BUS_ERROR_NAME_HAS_NO_OWNER))
- return ENXIO;
-
- if (streq(name, SD_BUS_ERROR_NO_REPLY) ||
- streq(name, SD_BUS_ERROR_TIMEOUT) ||
- streq(name, "org.freedesktop.DBus.Error.TimedOut"))
- return ETIMEDOUT;
-
- if (streq(name, SD_BUS_ERROR_IO_ERROR))
- return EIO;
-
- if (streq(name, SD_BUS_ERROR_BAD_ADDRESS))
- return EADDRNOTAVAIL;
-
- if (streq(name, SD_BUS_ERROR_NOT_SUPPORTED))
- return ENOTSUP;
-
- if (streq(name, SD_BUS_ERROR_LIMITS_EXCEEDED))
- return ENOBUFS;
-
- if (streq(name, SD_BUS_ERROR_ACCESS_DENIED) ||
- streq(name, SD_BUS_ERROR_AUTH_FAILED))
- return EACCES;
-
- if (streq(name, SD_BUS_ERROR_NO_SERVER))
- return EHOSTDOWN;
-
- if (streq(name, SD_BUS_ERROR_NO_NETWORK))
- return ENONET;
-
- if (streq(name, SD_BUS_ERROR_ADDRESS_IN_USE))
- return EADDRINUSE;
-
- if (streq(name, SD_BUS_ERROR_DISCONNECTED))
- return ECONNRESET;
-
- if (streq(name, SD_BUS_ERROR_INVALID_ARGS) ||
- streq(name, SD_BUS_ERROR_INVALID_SIGNATURE) ||
- streq(name, "org.freedesktop.DBus.Error.MatchRuleInvalid") ||
- streq(name, "org.freedesktop.DBus.Error.InvalidFileContent"))
- return EINVAL;
-
- if (streq(name, SD_BUS_ERROR_FILE_NOT_FOUND) ||
- streq(name, "org.freedesktop.DBus.Error.MatchRuleNotFound"))
- return ENOENT;
-
- if (streq(name, SD_BUS_ERROR_FILE_EXISTS))
- return EEXIST;
-
- if (streq(name, SD_BUS_ERROR_UNKNOWN_METHOD) ||
- streq(name, SD_BUS_ERROR_UNKNOWN_OBJECT) ||
- streq(name, SD_BUS_ERROR_UNKNOWN_INTERFACE) ||
- streq(name, SD_BUS_ERROR_UNKNOWN_PROPERTY))
- return EBADR;
-
- if (streq(name, SD_BUS_ERROR_PROPERTY_READ_ONLY))
- return EROFS;
-
- if (streq(name, SD_BUS_ERROR_UNIX_PROCESS_ID_UNKNOWN) ||
- streq(name, "org.freedesktop.DBus.Error.SELinuxSecurityContextUnknown"))
- return ESRCH;
-
- if (streq(name, SD_BUS_ERROR_INCONSISTENT_MESSAGE))
- return EBADMSG;
-
- if (streq(name, "org.freedesktop.DBus.Error.ObjectPathInUse"))
- return EBUSY;
+ m = bus_error_mapping_lookup(name, strlen(name));
+ if (m)
+ return m->code;
return EIO;
}
diff --git a/src/libsystemd-bus/bus-error.h b/src/libsystemd-bus/bus-error.h
index f6b9824c95..cf0ad9d545 100644
--- a/src/libsystemd-bus/bus-error.h
+++ b/src/libsystemd-bus/bus-error.h
@@ -26,6 +26,14 @@
#include "sd-bus.h"
#include "macro.h"
+struct name_error_mapping {
+ const char* name;
+ int code;
+};
+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);