Enable/disable debugging on SIGUSR1.
This commit is contained in:
22
src/main.c
22
src/main.c
@@ -5,6 +5,26 @@
|
|||||||
#include "mm-manager.h"
|
#include "mm-manager.h"
|
||||||
#include "mm-options.h"
|
#include "mm-options.h"
|
||||||
|
|
||||||
|
static void
|
||||||
|
mm_signal_handler (int signo)
|
||||||
|
{
|
||||||
|
if (signo == SIGUSR1)
|
||||||
|
mm_options_set_debug (!mm_options_debug ());
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
setup_signals (void)
|
||||||
|
{
|
||||||
|
struct sigaction action;
|
||||||
|
sigset_t mask;
|
||||||
|
|
||||||
|
sigemptyset (&mask);
|
||||||
|
action.sa_handler = mm_signal_handler;
|
||||||
|
action.sa_mask = mask;
|
||||||
|
action.sa_flags = 0;
|
||||||
|
sigaction (SIGUSR1, &action, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
log_handler (const gchar *log_domain,
|
log_handler (const gchar *log_domain,
|
||||||
GLogLevelFlags log_level,
|
GLogLevelFlags log_level,
|
||||||
@@ -130,6 +150,8 @@ main (int argc, char *argv[])
|
|||||||
mm_options_parse (argc, argv);
|
mm_options_parse (argc, argv);
|
||||||
g_type_init ();
|
g_type_init ();
|
||||||
|
|
||||||
|
setup_signals ();
|
||||||
|
|
||||||
if (!mm_options_debug ())
|
if (!mm_options_debug ())
|
||||||
logging_setup ();
|
logging_setup ();
|
||||||
|
|
||||||
|
@@ -29,6 +29,12 @@ mm_options_parse (int argc, char *argv[])
|
|||||||
g_option_context_free (opt_ctx);
|
g_option_context_free (opt_ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mm_options_set_debug (gboolean enabled)
|
||||||
|
{
|
||||||
|
debug = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
mm_options_debug (void)
|
mm_options_debug (void)
|
||||||
{
|
{
|
||||||
|
@@ -4,6 +4,7 @@
|
|||||||
#define MM_OPTIONS_H
|
#define MM_OPTIONS_H
|
||||||
|
|
||||||
void mm_options_parse (int argc, char *argv[]);
|
void mm_options_parse (int argc, char *argv[]);
|
||||||
|
void mm_options_set_debug (gboolean enabled);
|
||||||
gboolean mm_options_debug (void);
|
gboolean mm_options_debug (void);
|
||||||
|
|
||||||
#endif /* MM_OPTIONS_H */
|
#endif /* MM_OPTIONS_H */
|
||||||
|
@@ -244,6 +244,7 @@ config_fd (MMSerial *self)
|
|||||||
static void
|
static void
|
||||||
serial_debug (const char *prefix, const char *buf, int len)
|
serial_debug (const char *prefix, const char *buf, int len)
|
||||||
{
|
{
|
||||||
|
static GString *debug = NULL;
|
||||||
const char *s;
|
const char *s;
|
||||||
|
|
||||||
if (!mm_options_debug ())
|
if (!mm_options_debug ())
|
||||||
@@ -252,23 +253,29 @@ serial_debug (const char *prefix, const char *buf, int len)
|
|||||||
if (len < 0)
|
if (len < 0)
|
||||||
len = strlen (buf);
|
len = strlen (buf);
|
||||||
|
|
||||||
g_print ("%s '", prefix);
|
if (!debug)
|
||||||
|
debug = g_string_sized_new (256);
|
||||||
|
|
||||||
|
g_string_append (debug, prefix);
|
||||||
|
g_string_append (debug, " '");
|
||||||
|
|
||||||
s = buf;
|
s = buf;
|
||||||
while (len--) {
|
while (len--) {
|
||||||
if (g_ascii_isprint (*s))
|
if (g_ascii_isprint (*s))
|
||||||
g_print ("%c", *s);
|
g_string_append_c (debug, *s);
|
||||||
else if (*s == '\r')
|
else if (*s == '\r')
|
||||||
g_print ("<CR>");
|
g_string_append (debug, "<CR>");
|
||||||
else if (*s == '\n')
|
else if (*s == '\n')
|
||||||
g_print ("<LF>");
|
g_string_append (debug, "<LF>");
|
||||||
else
|
else
|
||||||
g_print ("\\%d", *s);
|
g_string_append_printf (debug, "\\%d", *s);
|
||||||
|
|
||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_print ("'\n");
|
g_string_append_c (debug, '\'');
|
||||||
|
g_debug (debug->str);
|
||||||
|
g_string_truncate (debug, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
Reference in New Issue
Block a user