chiark / gitweb /
Move bus_error to dbus-common and remove bus_error_message_or_strerror
authorSimon Peeters <peeters.simon@gmail.com>
Wed, 10 Apr 2013 22:39:01 +0000 (00:39 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 18 Apr 2013 00:54:58 +0000 (02:54 +0200)
bus_error and bus_error_message_or_strerror dit almost exactly the same,
so use only one of them and place it in dbus-common.

12 files changed:
src/core/bus-errors.h
src/core/load-fragment.c
src/core/main.c
src/core/path.c
src/core/service.c
src/core/socket.c
src/core/timer.c
src/core/transaction.c
src/login/inhibit.c
src/login/logind-dbus.c
src/shared/dbus-common.c
src/shared/dbus-common.h

index 04c1b2849d20f2cd5ef858aea0bcbfa742d503a6..7a4084ea15c17eda37a64825bdec1b39c981f267 100644 (file)
@@ -21,9 +21,6 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <string.h>
-#include <dbus/dbus.h>
-
 #define BUS_ERROR_NO_SUCH_UNIT "org.freedesktop.systemd1.NoSuchUnit"
 #define BUS_ERROR_NO_SUCH_JOB "org.freedesktop.systemd1.NoSuchJob"
 #define BUS_ERROR_NOT_SUBSCRIBED "org.freedesktop.systemd1.NotSubscribed"
 #define BUS_ERROR_TRANSACTION_ORDER_IS_CYCLIC "org.freedesktop.systemd1.TransactionOrderIsCyclic"
 #define BUS_ERROR_SHUTTING_DOWN "org.freedesktop.systemd1.ShuttingDown"
 #define BUS_ERROR_NO_SUCH_PROCESS "org.freedesktop.systemd1.NoSuchProcess"
-
-static inline const char *bus_error(const DBusError *e, int r) {
-        if (e && e->message)
-                return e->message;
-
-        if (r >= 0)
-                return strerror(r);
-
-        return strerror(-r);
-}
index 6839da8817b5b78d6d2a2a34d3f2de2ec565286b..e71194301d1a619925fe1d0c2b9a8a4c676a4fb8 100644 (file)
@@ -46,7 +46,7 @@
 #include "missing.h"
 #include "unit-name.h"
 #include "unit-printf.h"
-#include "bus-errors.h"
+#include "dbus-common.h"
 #include "utf8.h"
 #include "path-util.h"
 #include "syscall-list.h"
index f19e432d4a0b75851746cce028fbd261bafc2a61..51c83154a54eac6fe95cec4e78f993f2b78e8641 100644 (file)
@@ -40,7 +40,7 @@
 #include "fdset.h"
 #include "special.h"
 #include "conf-parser.h"
-#include "bus-errors.h"
+#include "dbus-common.h"
 #include "missing.h"
 #include "label.h"
 #include "build.h"
index ff49c069eebc96084d9b53b35c8aa12aa007e9f3..b8ba057561384ca74aa0eb3987e08c6da379c1d2 100644 (file)
@@ -31,7 +31,7 @@
 #include "mkdir.h"
 #include "dbus-path.h"
 #include "special.h"
-#include "bus-errors.h"
+#include "dbus-common.h"
 #include "path-util.h"
 #include "macro.h"
 
index a104b300c3724994bf3c5a9df6d832617fc2322b..cf19ccb7b8e43b19caef6f039de12bd54d72d26c 100644 (file)
@@ -36,7 +36,7 @@
 #include "unit-printf.h"
 #include "dbus-service.h"
 #include "special.h"
-#include "bus-errors.h"
+#include "dbus-common.h"
 #include "exit-status.h"
 #include "def.h"
 #include "path-util.h"
index f3cbe08a4476385d03dea1d66f475f9f8f0639b0..9f1af1e28f2c92accfa94de70a1b0da3e1d85687 100644 (file)
@@ -46,7 +46,7 @@
 #include "dbus-socket.h"
 #include "missing.h"
 #include "special.h"
-#include "bus-errors.h"
+#include "dbus-common.h"
 #include "label.h"
 #include "exit-status.h"
 #include "def.h"
index 16ca573177a80e82e28d6ab7679dcee79b8e684c..107dbb3f21641c05a94276bbe069975aba610f1c 100644 (file)
@@ -26,7 +26,7 @@
 #include "timer.h"
 #include "dbus-timer.h"
 #include "special.h"
-#include "bus-errors.h"
+#include "dbus-common.h"
 
 static const UnitActiveState state_translation_table[_TIMER_STATE_MAX] = {
         [TIMER_DEAD] = UNIT_INACTIVE,
index 4a8d90e6e569692c14f5890eae89ad69033a0cc3..610344eff3f256d01a4e67478dab4f1c3eccc261 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "transaction.h"
 #include "bus-errors.h"
+#include "dbus-common.h"
 
 static void transaction_unlink_job(Transaction *tr, Job *j, bool delete_dependencies);
 
index 9cb321fc8fb1e7cc8d329decdb3d2617a3de409e..fbab42aff1713f7f43bfc62ce3b496912c99868f 100644 (file)
@@ -251,7 +251,7 @@ int main(int argc, char *argv[]) {
 
                 r = print_inhibitors(bus, &error);
                 if (r < 0) {
-                        log_error("Failed to list inhibitors: %s", bus_error_message_or_strerror(&error, -r));
+                        log_error("Failed to list inhibitors: %s", bus_error(&error, r));
                         goto finish;
                 }
 
@@ -266,7 +266,7 @@ int main(int argc, char *argv[]) {
                 free(w);
 
                 if (fd < 0) {
-                        log_error("Failed to inhibit: %s", bus_error_message_or_strerror(&error, -r));
+                        log_error("Failed to inhibit: %s", bus_error(&error, r));
                         r = fd;
                         goto finish;
                 }
index 228a8389ee06b410400872e518e992e23577a58a..b63b79d9a6f853346684e92c123d29e52bfb2914 100644 (file)
@@ -2457,7 +2457,7 @@ int manager_dispatch_delayed(Manager *manager) {
         dbus_error_init(&error);
         r = execute_shutdown_or_sleep(manager, manager->action_what, manager->action_unit, &error);
         if (r < 0) {
-                log_warning("Failed to send delayed message: %s", bus_error_message_or_strerror(&error, -r));
+                log_warning("Failed to send delayed message: %s", bus_error(&error, r));
                 dbus_error_free(&error);
 
                 manager->action_unit = NULL;
index 5afce7627ae7db87b6b3ff33752cc3c3f9d1240e..b8c15cb9fc35e9fbdd046db32805a786b3a9e92e 100644 (file)
@@ -258,12 +258,11 @@ const char *bus_error_message(const DBusError *error) {
         return error->message;
 }
 
-const char *bus_error_message_or_strerror(const DBusError *error, int err) {
-
+const char *bus_error(const DBusError *error, int err) {
         if (error && dbus_error_is_set(error))
                 return bus_error_message(error);
 
-        return strerror(err);
+        return strerror(err < 0 ? -err : err);
 }
 
 DBusHandlerResult bus_default_message_handler(
index f7f614cdcd4a9e9e6df622c7d3fdcb64bdaf08a5..16fc14b8e42c10c61c6d43cf05a9c6e6b4d12a3f 100644 (file)
@@ -92,7 +92,7 @@ int bus_connect_system_ssh(const char *user, const char *host, DBusConnection **
 int bus_connect_system_polkit(DBusConnection **_bus, DBusError *error);
 
 const char *bus_error_message(const DBusError *error);
-const char *bus_error_message_or_strerror(const DBusError *error, int err);
+const char *bus_error(const DBusError *e, int r);
 
 typedef int (*BusPropertyCallback)(DBusMessageIter *iter, const char *property, void *data);
 typedef int (*BusPropertySetCallback)(DBusMessageIter *iter, const char *property, void *data);