From 2f3ccee059f85888a6f77f1634ac55a871bc728c Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 31 Mar 2022 12:04:45 +0200 Subject: [PATCH] main: Add debug flag This will be used to restrict some D-Bus methods to when debugging is enabled. --- src/up-daemon.c | 14 ++++++++++++++ src/up-daemon.h | 3 +++ src/up-main.c | 7 +++++++ 3 files changed, 24 insertions(+) diff --git a/src/up-daemon.c b/src/up-daemon.c index b032e1b..2d38164 100644 --- a/src/up-daemon.c +++ b/src/up-daemon.c @@ -38,6 +38,7 @@ struct UpDaemonPrivate { UpConfig *config; + gboolean debug; UpBackend *backend; UpDeviceList *power_devices; guint action_timeout_id; @@ -1005,6 +1006,19 @@ up_daemon_resume_poll (UpDaemon *daemon) daemon->priv->poll_paused = FALSE; } +void +up_daemon_set_debug (UpDaemon *daemon, + gboolean debug) +{ + daemon->priv->debug = debug; +} + +gboolean +up_daemon_get_debug (UpDaemon *daemon) +{ + return daemon->priv->debug; +} + /** * up_daemon_device_added_cb: **/ diff --git a/src/up-daemon.h b/src/up-daemon.h index 76e7937..9f21e17 100644 --- a/src/up-daemon.h +++ b/src/up-daemon.h @@ -92,6 +92,9 @@ void up_daemon_start_poll (GObject *object, void up_daemon_stop_poll (GObject *object); void up_daemon_pause_poll (UpDaemon *daemon); void up_daemon_resume_poll (UpDaemon *daemon); +void up_daemon_set_debug (UpDaemon *daemon, + gboolean debug); +gboolean up_daemon_get_debug (UpDaemon *daemon); G_END_DECLS diff --git a/src/up-main.c b/src/up-main.c index f805ed3..4dace9f 100644 --- a/src/up-main.c +++ b/src/up-main.c @@ -169,6 +169,7 @@ main (gint argc, gchar **argv) gboolean timed_exit = FALSE; gboolean immediate_exit = FALSE; guint timer_id = 0; + gboolean debug = FALSE; gboolean verbose = FALSE; UpState *state; GBusNameOwnerFlags bus_flags; @@ -185,6 +186,8 @@ main (gint argc, gchar **argv) _("Replace the old daemon"), NULL}, { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, _("Show extra debugging information"), NULL }, + { "debug", 'd', 0, G_OPTION_ARG_NONE, &debug, + _("Enable debugging (implies --verbose)"), NULL }, { NULL} }; @@ -202,6 +205,9 @@ main (gint argc, gchar **argv) } g_option_context_free (context); + if (debug) + verbose = TRUE; + /* verbose? */ if (verbose) { g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | @@ -233,6 +239,7 @@ main (gint argc, gchar **argv) /* initialize state */ state = up_state_new (); + up_daemon_set_debug (state->daemon, debug); /* do stuff on ctrl-c */ g_unix_signal_add_full (G_PRIORITY_DEFAULT,