libdbus-p2p: better error reporting 97/269297/1
authorMichal Bloch <m.bloch@samsung.com>
Wed, 5 Jan 2022 15:10:23 +0000 (16:10 +0100)
committerMichal Bloch <m.bloch@samsung.com>
Wed, 12 Jan 2022 11:53:07 +0000 (12:53 +0100)
Change-Id: Ie172dcf45da6a2eb82f37cbb9a9eca7a31ebb4bf
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
benchmark/libdbus-p2p-server.cpp

index 0a80407c714327a6784d5ee599224de74fbb2b29..0540dfd4f37cf71a1c6cab7572723d0534a0f030 100644 (file)
@@ -338,12 +338,22 @@ int main (int argc, char ** argv)
                return EXIT_FAILURE;
        }
 
+       DBusError derror;
+       dbus_error_init (& derror);
+
        /* thread_local ensures the destructor runs, the destructor doesn't
         * run on std::exit without it as per the std::exit specification.
         * Otherwise it makes no difference since we're single-threaded. */
-       thread_local std::unique_ptr <DBusServer, DBusServer_deleter> server (dbus_server_listen (("unix:path=" + opt.sock_path).c_str(), nullptr));
+       thread_local std::unique_ptr <DBusServer, DBusServer_deleter> server (dbus_server_listen (("unix:path=" + opt.sock_path).c_str(), & derror));
        if (!server) {
-               std::cerr << "listening on " << opt.sock_path << "failed" << std::endl;
+
+               if (dbus_error_is_set (&derror)) {
+                       std::cerr << derror.name << ": " << derror.message << std::endl;
+                       dbus_error_free (&derror); // stack var is fine, doesn't actually free the memory
+               } else {
+                       std::cerr << "listening on " << opt.sock_path << " failed (unknown error)" << std::endl;
+               }
+
                return EXIT_FAILURE;
        }