From 2afb01c31fad5b0e814eb13389ded499dcd8d88b Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 29 Aug 2009 22:50:54 -0700 Subject: Add support for handling errors from agent registration --- src/agent.c | 2 +- src/connman.h | 1 + src/error.c | 8 ++++++++ src/manager.c | 28 ++++++++++------------------ 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/agent.c b/src/agent.c index 42a126e8..82f6146e 100644 --- a/src/agent.c +++ b/src/agent.c @@ -75,7 +75,7 @@ int __connman_agent_unregister(const char *sender, const char *path) DBG("sender %s path %s", sender, path); if (agent_path == NULL) - return -ENOENT; + return -ESRCH; if (agent_watch > 0) g_dbus_remove_watch(connection, agent_watch); diff --git a/src/connman.h b/src/connman.h index af11c29e..81343dd8 100644 --- a/src/connman.h +++ b/src/connman.h @@ -36,6 +36,7 @@ DBusMessage *__connman_error_failed(DBusMessage *msg, int errnum); DBusMessage *__connman_error_invalid_arguments(DBusMessage *msg); DBusMessage *__connman_error_permission_denied(DBusMessage *msg); DBusMessage *__connman_error_passphrase_required(DBusMessage *msg); +DBusMessage *__connman_error_not_registered(DBusMessage *msg); DBusMessage *__connman_error_not_supported(DBusMessage *msg); DBusMessage *__connman_error_not_implemented(DBusMessage *msg); DBusMessage *__connman_error_not_found(DBusMessage *msg); diff --git a/src/error.c b/src/error.c index 4217091e..6021f4c7 100644 --- a/src/error.c +++ b/src/error.c @@ -35,6 +35,8 @@ DBusMessage *__connman_error_failed(DBusMessage *msg, int errnum) const char *str = strerror(errnum); switch (errnum) { + case ESRCH: + return __connman_error_not_registered(msg); case ENXIO: return __connman_error_not_found(msg); case EACCES: @@ -85,6 +87,12 @@ DBusMessage *__connman_error_passphrase_required(DBusMessage *msg) ".PassphraseRequired", "Passphrase required"); } +DBusMessage *__connman_error_not_registered(DBusMessage *msg) +{ + return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE + ".NotRegistered", "Not registered"); +} + DBusMessage *__connman_error_not_supported(DBusMessage *msg) { return g_dbus_create_error(msg, CONNMAN_ERROR_INTERFACE diff --git a/src/manager.c b/src/manager.c index 8acb317c..e761ce8c 100644 --- a/src/manager.c +++ b/src/manager.c @@ -579,8 +579,8 @@ static DBusMessage *connect_service(DBusConnection *conn, static DBusMessage *register_agent(DBusConnection *conn, DBusMessage *msg, void *data) { - DBusMessage *reply; const char *sender, *path; + int err; DBG("conn %p", conn); @@ -589,22 +589,18 @@ static DBusMessage *register_agent(DBusConnection *conn, dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID); - reply = dbus_message_new_method_return(msg); - if (reply == NULL) - return NULL; - - dbus_message_append_args(reply, DBUS_TYPE_INVALID); - - __connman_agent_register(sender, path); + err = __connman_agent_register(sender, path); + if (err < 0) + return __connman_error_failed(msg, -err); - return reply; + return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); } static DBusMessage *unregister_agent(DBusConnection *conn, DBusMessage *msg, void *data) { - DBusMessage *reply; const char *sender, *path; + int err; DBG("conn %p", conn); @@ -613,15 +609,11 @@ static DBusMessage *unregister_agent(DBusConnection *conn, dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID); - reply = dbus_message_new_method_return(msg); - if (reply == NULL) - return NULL; - - dbus_message_append_args(reply, DBUS_TYPE_INVALID); - - __connman_agent_unregister(sender, path); + err = __connman_agent_unregister(sender, path); + if (err < 0) + return __connman_error_failed(msg, -err); - return reply; + return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); } static GDBusMethodTable manager_methods[] = { -- cgit v1.2.3