Enable/disable debugging on SIGUSR1.

This commit is contained in:
Tambet Ingo
2008-10-30 15:13:51 +02:00
parent ced49a6a10
commit fe4e7ee62b
4 changed files with 97 additions and 61 deletions

View File

@@ -5,6 +5,26 @@
#include "mm-manager.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
log_handler (const gchar *log_domain,
GLogLevelFlags log_level,
@@ -130,6 +150,8 @@ main (int argc, char *argv[])
mm_options_parse (argc, argv);
g_type_init ();
setup_signals ();
if (!mm_options_debug ())
logging_setup ();

View File

@@ -29,6 +29,12 @@ mm_options_parse (int argc, char *argv[])
g_option_context_free (opt_ctx);
}
void
mm_options_set_debug (gboolean enabled)
{
debug = enabled;
}
gboolean
mm_options_debug (void)
{

View File

@@ -4,6 +4,7 @@
#define MM_OPTIONS_H
void mm_options_parse (int argc, char *argv[]);
void mm_options_set_debug (gboolean enabled);
gboolean mm_options_debug (void);
#endif /* MM_OPTIONS_H */

View File

@@ -244,6 +244,7 @@ config_fd (MMSerial *self)
static void
serial_debug (const char *prefix, const char *buf, int len)
{
static GString *debug = NULL;
const char *s;
if (!mm_options_debug ())
@@ -252,23 +253,29 @@ serial_debug (const char *prefix, const char *buf, int len)
if (len < 0)
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;
while (len--) {
if (g_ascii_isprint (*s))
g_print ("%c", *s);
g_string_append_c (debug, *s);
else if (*s == '\r')
g_print ("<CR>");
g_string_append (debug, "<CR>");
else if (*s == '\n')
g_print ("<LF>");
g_string_append (debug, "<LF>");
else
g_print ("\\%d", *s);
g_string_append_printf (debug, "\\%d", *s);
s++;
}
g_print ("'\n");
g_string_append_c (debug, '\'');
g_debug (debug->str);
g_string_truncate (debug, 0);
}
static gboolean