context: rework application options and help output
Group together all options that allow configuring the logging output, and make them have the same --log-[XXX] prefix. Also rework the --help output so that all option groups are printed by default (i.e. there is no longer a --help-all option).
This commit is contained in:
@@ -19,20 +19,6 @@ actual device (Generic AT, vendor-specific AT, QCDM, QMI, MBIM...).
|
|||||||
ModemManager is a DBus-based system daemon and is not meant to be used directly
|
ModemManager is a DBus-based system daemon and is not meant to be used directly
|
||||||
from the command line.
|
from the command line.
|
||||||
|
|
||||||
.SH HELP OPTIONS
|
|
||||||
.TP
|
|
||||||
.B \-V, \-\-version
|
|
||||||
Print the ModemManager software version and exit.
|
|
||||||
.TP
|
|
||||||
.B \-h, \-\-help
|
|
||||||
Show application options.
|
|
||||||
.TP
|
|
||||||
.B \-\-help\-all
|
|
||||||
Show application and test options.
|
|
||||||
.TP
|
|
||||||
.B \-\-help\-test
|
|
||||||
Show test options.
|
|
||||||
|
|
||||||
.SH APPLICATION OPTIONS
|
.SH APPLICATION OPTIONS
|
||||||
.TP
|
.TP
|
||||||
.B \-\-no\-auto\-scan
|
.B \-\-no\-auto\-scan
|
||||||
@@ -47,6 +33,14 @@ Runs ModemManager with "DEBUG" log level and without daemonizing. This is useful
|
|||||||
for debugging, as it directs log output to the controlling terminal in addition to
|
for debugging, as it directs log output to the controlling terminal in addition to
|
||||||
syslog.
|
syslog.
|
||||||
.TP
|
.TP
|
||||||
|
.B \-V, \-\-version
|
||||||
|
Print the ModemManager software version and exit.
|
||||||
|
.TP
|
||||||
|
.B \-h, \-\-help
|
||||||
|
Show application options.
|
||||||
|
|
||||||
|
.SH LOGGING OPTIONS
|
||||||
|
.TP
|
||||||
.B \-\-log\-level=<level>
|
.B \-\-log\-level=<level>
|
||||||
Sets how much information ModemManager sends to the log destination (usually
|
Sets how much information ModemManager sends to the log destination (usually
|
||||||
syslog's "daemon" facility). By default, only informational, warning, and error
|
syslog's "daemon" facility). By default, only informational, warning, and error
|
||||||
@@ -56,10 +50,10 @@ messages are logged. Given level must be one of "ERR", "WARN", "INFO" or "DEBUG"
|
|||||||
Specify location of the file where ModemManager will dump its log messages,
|
Specify location of the file where ModemManager will dump its log messages,
|
||||||
instead of syslog.
|
instead of syslog.
|
||||||
.TP
|
.TP
|
||||||
.B \-\-timestamps
|
.B \-\-log\-timestamps
|
||||||
Include absolute timestamps in the log output.
|
Include absolute timestamps in the log output.
|
||||||
.TP
|
.TP
|
||||||
.B \-\-relative-timestamps
|
.B \-\-log\-relative\-timestamps
|
||||||
Include timestamps, relative to the start time of the daemon, in the log output.
|
Include timestamps, relative to the start time of the daemon, in the log output.
|
||||||
|
|
||||||
.SH TEST OPTIONS
|
.SH TEST OPTIONS
|
||||||
|
@@ -141,8 +141,8 @@ main (int argc, char *argv[])
|
|||||||
|
|
||||||
if (!mm_log_setup (mm_context_get_log_level (),
|
if (!mm_log_setup (mm_context_get_log_level (),
|
||||||
mm_context_get_log_file (),
|
mm_context_get_log_file (),
|
||||||
mm_context_get_timestamps (),
|
mm_context_get_log_timestamps (),
|
||||||
mm_context_get_relative_timestamps (),
|
mm_context_get_log_relative_timestamps (),
|
||||||
mm_context_get_debug (),
|
mm_context_get_debug (),
|
||||||
&err)) {
|
&err)) {
|
||||||
g_warning ("Failed to set up logging: %s", err->message);
|
g_warning ("Failed to set up logging: %s", err->message);
|
||||||
|
212
src/mm-context.c
212
src/mm-context.c
@@ -21,36 +21,48 @@
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Application context */
|
/* Application context */
|
||||||
|
|
||||||
static gboolean version_flag;
|
|
||||||
static gboolean debug;
|
|
||||||
static const gchar *log_level;
|
|
||||||
static const gchar *log_file;
|
|
||||||
static gboolean show_ts;
|
|
||||||
static gboolean rel_ts;
|
|
||||||
|
|
||||||
#if WITH_UDEV
|
#if WITH_UDEV
|
||||||
static gboolean no_auto_scan = FALSE;
|
# define NO_AUTO_SCAN_OPTION_FLAG 0
|
||||||
#else
|
# define NO_AUTO_SCAN_DEFAULT FALSE
|
||||||
static gboolean no_auto_scan = TRUE;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static const gchar *initial_kernel_events;
|
|
||||||
|
|
||||||
static const GOptionEntry entries[] = {
|
|
||||||
{ "version", 'V', 0, G_OPTION_ARG_NONE, &version_flag, "Print version", NULL },
|
|
||||||
{ "debug", 0, 0, G_OPTION_ARG_NONE, &debug, "Run with extended debugging capabilities", NULL },
|
|
||||||
{ "log-level", 0, 0, G_OPTION_ARG_STRING, &log_level, "Log level: one of ERR, WARN, INFO, DEBUG", "[LEVEL]" },
|
|
||||||
{ "log-file", 0, 0, G_OPTION_ARG_FILENAME, &log_file, "Path to log file", "[PATH]" },
|
|
||||||
{ "timestamps", 0, 0, G_OPTION_ARG_NONE, &show_ts, "Show timestamps in log output", NULL },
|
|
||||||
{ "relative-timestamps", 0, 0, G_OPTION_ARG_NONE, &rel_ts, "Use relative timestamps (from MM start)", NULL },
|
|
||||||
#if WITH_UDEV
|
|
||||||
{ "no-auto-scan", 0, 0, G_OPTION_ARG_NONE, &no_auto_scan, "Don't auto-scan looking for devices", NULL },
|
|
||||||
#else
|
#else
|
||||||
/* Keep the option when udev disabled, just so that the unit test setup can
|
/* Keep the option when udev disabled, just so that the unit test setup can
|
||||||
* unconditionally use --no-auto-scan */
|
* unconditionally use --no-auto-scan */
|
||||||
{ "no-auto-scan", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &no_auto_scan, NULL, NULL },
|
# define NO_AUTO_SCAN_OPTION_FLAG G_OPTION_FLAG_HIDDEN
|
||||||
|
# define NO_AUTO_SCAN_DEFAULT TRUE
|
||||||
#endif
|
#endif
|
||||||
{ "initial-kernel-events", 0, 0, G_OPTION_ARG_FILENAME, &initial_kernel_events, "Path to initial kernel events file", "[PATH]" },
|
|
||||||
|
static gboolean help_flag;
|
||||||
|
static gboolean version_flag;
|
||||||
|
static gboolean debug;
|
||||||
|
static gboolean no_auto_scan = NO_AUTO_SCAN_DEFAULT;
|
||||||
|
static const gchar *initial_kernel_events;
|
||||||
|
|
||||||
|
static const GOptionEntry entries[] = {
|
||||||
|
{
|
||||||
|
"no-auto-scan", 0, NO_AUTO_SCAN_OPTION_FLAG, G_OPTION_ARG_NONE, &no_auto_scan,
|
||||||
|
"Don't auto-scan looking for devices",
|
||||||
|
NULL
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"initial-kernel-events", 0, 0, G_OPTION_ARG_FILENAME, &initial_kernel_events,
|
||||||
|
"Path to initial kernel events file",
|
||||||
|
"[PATH]"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"debug", 0, 0, G_OPTION_ARG_NONE, &debug,
|
||||||
|
"Run with extended debugging capabilities",
|
||||||
|
NULL
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"version", 'V', 0, G_OPTION_ARG_NONE, &version_flag,
|
||||||
|
"Print version",
|
||||||
|
NULL
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"help", 'h', 0, G_OPTION_ARG_NONE, &help_flag,
|
||||||
|
"Show help",
|
||||||
|
NULL
|
||||||
|
},
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -60,30 +72,6 @@ mm_context_get_debug (void)
|
|||||||
return debug;
|
return debug;
|
||||||
}
|
}
|
||||||
|
|
||||||
const gchar *
|
|
||||||
mm_context_get_log_level (void)
|
|
||||||
{
|
|
||||||
return log_level;
|
|
||||||
}
|
|
||||||
|
|
||||||
const gchar *
|
|
||||||
mm_context_get_log_file (void)
|
|
||||||
{
|
|
||||||
return log_file;
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean
|
|
||||||
mm_context_get_timestamps (void)
|
|
||||||
{
|
|
||||||
return show_ts;
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean
|
|
||||||
mm_context_get_relative_timestamps (void)
|
|
||||||
{
|
|
||||||
return rel_ts;
|
|
||||||
}
|
|
||||||
|
|
||||||
const gchar *
|
const gchar *
|
||||||
mm_context_get_initial_kernel_events (void)
|
mm_context_get_initial_kernel_events (void)
|
||||||
{
|
{
|
||||||
@@ -96,6 +84,76 @@ mm_context_get_no_auto_scan (void)
|
|||||||
return no_auto_scan;
|
return no_auto_scan;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Log context */
|
||||||
|
|
||||||
|
static const gchar *log_level;
|
||||||
|
static const gchar *log_file;
|
||||||
|
static gboolean log_show_ts;
|
||||||
|
static gboolean log_rel_ts;
|
||||||
|
|
||||||
|
static const GOptionEntry log_entries[] = {
|
||||||
|
{
|
||||||
|
"log-level", 0, 0, G_OPTION_ARG_STRING, &log_level,
|
||||||
|
"Log level: one of ERR, WARN, INFO, DEBUG",
|
||||||
|
"[LEVEL]"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"log-file", 0, 0, G_OPTION_ARG_FILENAME, &log_file,
|
||||||
|
"Path to log file",
|
||||||
|
"[PATH]"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"log-timestamps", 0, 0, G_OPTION_ARG_NONE, &log_show_ts,
|
||||||
|
"Show timestamps in log output",
|
||||||
|
NULL
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"log-relative-timestamps", 0, 0, G_OPTION_ARG_NONE, &log_rel_ts,
|
||||||
|
"Use relative timestamps (from MM start)",
|
||||||
|
NULL
|
||||||
|
},
|
||||||
|
{ NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
static GOptionGroup *
|
||||||
|
log_get_option_group (void)
|
||||||
|
{
|
||||||
|
GOptionGroup *group;
|
||||||
|
|
||||||
|
group = g_option_group_new ("log",
|
||||||
|
"Logging options",
|
||||||
|
"Show logging options",
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
g_option_group_add_entries (group, log_entries);
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
|
const gchar *
|
||||||
|
mm_context_get_log_level (void)
|
||||||
|
{
|
||||||
|
return log_level;
|
||||||
|
}
|
||||||
|
|
||||||
|
const gchar *
|
||||||
|
mm_context_get_log_file (void)
|
||||||
|
{
|
||||||
|
return log_file;
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
mm_context_get_log_timestamps (void)
|
||||||
|
{
|
||||||
|
return log_show_ts;
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
mm_context_get_log_relative_timestamps (void)
|
||||||
|
{
|
||||||
|
return log_rel_ts;
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Test context */
|
/* Test context */
|
||||||
|
|
||||||
@@ -104,9 +162,21 @@ static gboolean test_enable;
|
|||||||
static gchar *test_plugin_dir;
|
static gchar *test_plugin_dir;
|
||||||
|
|
||||||
static const GOptionEntry test_entries[] = {
|
static const GOptionEntry test_entries[] = {
|
||||||
{ "test-session", 0, 0, G_OPTION_ARG_NONE, &test_session, "Run in session DBus", NULL },
|
{
|
||||||
{ "test-enable", 0, 0, G_OPTION_ARG_NONE, &test_enable, "Enable the Test interface in the daemon", NULL },
|
"test-session", 0, 0, G_OPTION_ARG_NONE, &test_session,
|
||||||
{ "test-plugin-dir", 0, 0, G_OPTION_ARG_FILENAME, &test_plugin_dir, "Path to look for plugins", "[PATH]" },
|
"Run in session DBus",
|
||||||
|
NULL
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"test-enable", 0, 0, G_OPTION_ARG_NONE, &test_enable,
|
||||||
|
"Enable the Test interface in the daemon",
|
||||||
|
NULL
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"test-plugin-dir", 0, 0, G_OPTION_ARG_FILENAME, &test_plugin_dir,
|
||||||
|
"Path to look for plugins",
|
||||||
|
"[PATH]"
|
||||||
|
},
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -149,12 +219,22 @@ print_version (void)
|
|||||||
{
|
{
|
||||||
g_print ("\n"
|
g_print ("\n"
|
||||||
"ModemManager " MM_DIST_VERSION "\n"
|
"ModemManager " MM_DIST_VERSION "\n"
|
||||||
"Copyright (2008 - 2016) The ModemManager authors\n"
|
"Copyright (C) 2008-2017 The ModemManager authors\n"
|
||||||
"License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl-2.0.html>\n"
|
"License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl-2.0.html>\n"
|
||||||
"This is free software: you are free to change and redistribute it.\n"
|
"This is free software: you are free to change and redistribute it.\n"
|
||||||
"There is NO WARRANTY, to the extent permitted by law.\n"
|
"There is NO WARRANTY, to the extent permitted by law.\n"
|
||||||
"\n");
|
"\n");
|
||||||
exit (EXIT_SUCCESS);
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
print_help (GOptionContext *context)
|
||||||
|
{
|
||||||
|
gchar *str;
|
||||||
|
|
||||||
|
/* Always print --help-all */
|
||||||
|
str = g_option_context_get_help (context, FALSE, NULL);
|
||||||
|
g_print ("%s", str);
|
||||||
|
g_free (str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -165,9 +245,11 @@ mm_context_init (gint argc,
|
|||||||
GOptionContext *ctx;
|
GOptionContext *ctx;
|
||||||
|
|
||||||
ctx = g_option_context_new (NULL);
|
ctx = g_option_context_new (NULL);
|
||||||
g_option_context_set_summary (ctx, "DBus system service to communicate with modems.");
|
g_option_context_set_summary (ctx, "DBus system service to control mobile broadband modems.");
|
||||||
g_option_context_add_main_entries (ctx, entries, NULL);
|
g_option_context_add_main_entries (ctx, entries, NULL);
|
||||||
|
g_option_context_add_group (ctx, log_get_option_group ());
|
||||||
g_option_context_add_group (ctx, test_get_option_group ());
|
g_option_context_add_group (ctx, test_get_option_group ());
|
||||||
|
g_option_context_set_help_enabled (ctx, FALSE);
|
||||||
|
|
||||||
if (!g_option_context_parse (ctx, &argc, &argv, &error)) {
|
if (!g_option_context_parse (ctx, &argc, &argv, &error)) {
|
||||||
g_warning ("error: %s", error->message);
|
g_warning ("error: %s", error->message);
|
||||||
@@ -175,19 +257,27 @@ mm_context_init (gint argc,
|
|||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (version_flag) {
|
||||||
|
print_version ();
|
||||||
|
g_option_context_free (ctx);
|
||||||
|
exit (EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (help_flag) {
|
||||||
|
print_help (ctx);
|
||||||
|
g_option_context_free (ctx);
|
||||||
|
exit (EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
g_option_context_free (ctx);
|
g_option_context_free (ctx);
|
||||||
|
|
||||||
/* Additional setup to be done on debug mode */
|
/* Additional setup to be done on debug mode */
|
||||||
if (debug) {
|
if (debug) {
|
||||||
log_level = "DEBUG";
|
log_level = "DEBUG";
|
||||||
if (!show_ts && !rel_ts)
|
if (!log_show_ts && !log_rel_ts)
|
||||||
show_ts = TRUE;
|
log_show_ts = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If just version requested, print and exit */
|
|
||||||
if (version_flag)
|
|
||||||
print_version ();
|
|
||||||
|
|
||||||
/* Initial kernel events processing may only be used if autoscan is disabled */
|
/* Initial kernel events processing may only be used if autoscan is disabled */
|
||||||
#if WITH_UDEV
|
#if WITH_UDEV
|
||||||
if (!no_auto_scan && initial_kernel_events) {
|
if (!no_auto_scan && initial_kernel_events) {
|
||||||
|
@@ -27,13 +27,15 @@ void mm_context_init (gint argc,
|
|||||||
gchar **argv);
|
gchar **argv);
|
||||||
|
|
||||||
gboolean mm_context_get_debug (void);
|
gboolean mm_context_get_debug (void);
|
||||||
const gchar *mm_context_get_log_level (void);
|
|
||||||
const gchar *mm_context_get_log_file (void);
|
|
||||||
gboolean mm_context_get_timestamps (void);
|
|
||||||
gboolean mm_context_get_relative_timestamps (void);
|
|
||||||
const gchar *mm_context_get_initial_kernel_events (void);
|
const gchar *mm_context_get_initial_kernel_events (void);
|
||||||
gboolean mm_context_get_no_auto_scan (void);
|
gboolean mm_context_get_no_auto_scan (void);
|
||||||
|
|
||||||
|
/* Logging support */
|
||||||
|
const gchar *mm_context_get_log_level (void);
|
||||||
|
const gchar *mm_context_get_log_file (void);
|
||||||
|
gboolean mm_context_get_log_timestamps (void);
|
||||||
|
gboolean mm_context_get_log_relative_timestamps (void);
|
||||||
|
|
||||||
/* Testing support */
|
/* Testing support */
|
||||||
gboolean mm_context_get_test_session (void);
|
gboolean mm_context_get_test_session (void);
|
||||||
gboolean mm_context_get_test_enable (void);
|
gboolean mm_context_get_test_enable (void);
|
||||||
|
Reference in New Issue
Block a user