main: Add debug flag

This will be used to restrict some D-Bus methods to when debugging is
enabled.
This commit is contained in:
Bastien Nocera 2022-03-31 12:04:45 +02:00
parent 380e974d75
commit 2f3ccee059
3 changed files with 24 additions and 0 deletions

View file

@ -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:
**/

View file

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

View file

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