From 6236c1bccf3c12290f1b84fd6f2ff96272af944e Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 8 Feb 2021 16:51:17 +0100 Subject: [PATCH] main: Exit with 1 if there are startup D-Bus errors If there are D-Bus errors on startup such as the daemon already being started, make main() return with an error. --- src/power-profiles-daemon.c | 8 +++++++- tests/integration-test | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/power-profiles-daemon.c b/src/power-profiles-daemon.c index ffcc398..1795a5f 100644 --- a/src/power-profiles-daemon.c +++ b/src/power-profiles-daemon.c @@ -25,6 +25,7 @@ typedef struct { GDBusNodeInfo *introspection_data; GDBusConnection *connection; guint name_id; + gboolean was_started; int ret; PpdProfile active_profile; @@ -390,7 +391,10 @@ name_lost_handler (GDBusConnection *connection, const gchar *name, gpointer user_data) { + PpdApp *data = user_data; g_debug ("power-profiles-daemon is already running, or it cannot own its D-Bus name. Verify installation."); + if (!data->was_started) + data->ret = 1; g_main_loop_quit (main_loop); } @@ -526,10 +530,12 @@ name_acquired_handler (GDBusConnection *connection, send_dbus_event (data, PROP_ALL); + data->was_started = TRUE; + return; bail: - data->ret = 0; + data->ret = 1; g_debug ("Exiting because some non recoverable error occurred during startup"); g_main_loop_quit (main_loop); } diff --git a/tests/integration-test b/tests/integration-test index 3916488..6aa5514 100755 --- a/tests/integration-test +++ b/tests/integration-test @@ -246,6 +246,13 @@ class Tests(dbusmock.DBusTestCase): # # Actual test cases # + def test_dbus_startup_error(self): + '''D-Bus startup error''' + + self.start_daemon() + out = subprocess.run([self.daemon_path], capture_output=True) + self.assertEqual(out.returncode, 1, "power-profile-daemon started but should have failed") + self.stop_daemon() def test_no_performance_driver(self): '''no performance driver'''