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.
This commit is contained in:
Bastien Nocera 2021-02-08 16:51:17 +01:00
parent 74bfb0fd32
commit 6236c1bccf
2 changed files with 14 additions and 1 deletions

View file

@ -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);
}

View file

@ -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'''