aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.c128
-rw-r--r--src/mm-options.c6
-rw-r--r--src/mm-options.h5
-rw-r--r--src/mm-serial.c19
4 files changed, 97 insertions, 61 deletions
diff --git a/src/main.c b/src/main.c
index cdd07481..61e6e1fb 100644
--- a/src/main.c
+++ b/src/main.c
@@ -6,67 +6,87 @@
#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,
const gchar *message,
gpointer ignored)
{
- int syslog_priority;
+ int syslog_priority;
- switch (log_level) {
- case G_LOG_LEVEL_ERROR:
- syslog_priority = LOG_CRIT;
- break;
+ switch (log_level) {
+ case G_LOG_LEVEL_ERROR:
+ syslog_priority = LOG_CRIT;
+ break;
- case G_LOG_LEVEL_CRITICAL:
- syslog_priority = LOG_ERR;
- break;
+ case G_LOG_LEVEL_CRITICAL:
+ syslog_priority = LOG_ERR;
+ break;
- case G_LOG_LEVEL_WARNING:
- syslog_priority = LOG_WARNING;
- break;
+ case G_LOG_LEVEL_WARNING:
+ syslog_priority = LOG_WARNING;
+ break;
- case G_LOG_LEVEL_MESSAGE:
- syslog_priority = LOG_NOTICE;
- break;
+ case G_LOG_LEVEL_MESSAGE:
+ syslog_priority = LOG_NOTICE;
+ break;
- case G_LOG_LEVEL_DEBUG:
- syslog_priority = LOG_DEBUG;
- break;
+ case G_LOG_LEVEL_DEBUG:
+ syslog_priority = LOG_DEBUG;
+ break;
- case G_LOG_LEVEL_INFO:
- default:
- syslog_priority = LOG_INFO;
- break;
- }
+ case G_LOG_LEVEL_INFO:
+ default:
+ syslog_priority = LOG_INFO;
+ break;
+ }
- syslog (syslog_priority, "%s", message);
+ syslog (syslog_priority, "%s", message);
}
static void
logging_setup (void)
{
- openlog (G_LOG_DOMAIN, LOG_CONS, LOG_DAEMON);
- g_log_set_handler (G_LOG_DOMAIN,
- G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
- log_handler,
- NULL);
+ openlog (G_LOG_DOMAIN, LOG_CONS, LOG_DAEMON);
+ g_log_set_handler (G_LOG_DOMAIN,
+ G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
+ log_handler,
+ NULL);
}
static void
logging_shutdown (void)
{
- closelog ();
+ closelog ();
}
static void
destroy_cb (DBusGProxy *proxy, gpointer user_data)
{
- GMainLoop *loop = (GMainLoop *) user_data;
+ GMainLoop *loop = (GMainLoop *) user_data;
- g_message ("disconnected from the system bus, exiting.");
- g_main_loop_quit (loop);
+ g_message ("disconnected from the system bus, exiting.");
+ g_main_loop_quit (loop);
}
static gboolean
@@ -80,11 +100,11 @@ dbus_init (GMainLoop *loop)
connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &err);
if (!connection) {
g_warning ("Could not get the system bus. Make sure "
- "the message bus daemon is running! Message: %s",
- err->message);
- g_error_free (err);
- return FALSE;
- }
+ "the message bus daemon is running! Message: %s",
+ err->message);
+ g_error_free (err);
+ return FALSE;
+ }
proxy = dbus_g_proxy_new_for_name (connection,
"org.freedesktop.DBus",
@@ -92,23 +112,23 @@ dbus_init (GMainLoop *loop)
"org.freedesktop.DBus");
if (!dbus_g_proxy_call (proxy, "RequestName", &err,
- G_TYPE_STRING, MM_DBUS_SERVICE,
- G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE,
- G_TYPE_INVALID,
- G_TYPE_UINT, &request_name_result,
- G_TYPE_INVALID)) {
- g_warning ("Could not acquire the %s service.\n"
- " Message: '%s'", MM_DBUS_SERVICE, err->message);
- g_error_free (err);
+ G_TYPE_STRING, MM_DBUS_SERVICE,
+ G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE,
+ G_TYPE_INVALID,
+ G_TYPE_UINT, &request_name_result,
+ G_TYPE_INVALID)) {
+ g_warning ("Could not acquire the %s service.\n"
+ " Message: '%s'", MM_DBUS_SERVICE, err->message);
+ g_error_free (err);
goto err;
- }
+ }
- if (request_name_result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
- g_warning ("Could not acquire the NetworkManagerSystemSettings service "
- "as it is already taken. Return: %d",
- request_name_result);
+ if (request_name_result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
+ g_warning ("Could not acquire the NetworkManagerSystemSettings service "
+ "as it is already taken. Return: %d",
+ request_name_result);
goto err;
- }
+ }
g_signal_connect (proxy, "destroy", G_CALLBACK (destroy_cb), loop);
@@ -130,8 +150,10 @@ main (int argc, char *argv[])
mm_options_parse (argc, argv);
g_type_init ();
- if (!mm_options_debug ())
- logging_setup ();
+ setup_signals ();
+
+ if (!mm_options_debug ())
+ logging_setup ();
loop = g_main_loop_new (NULL, FALSE);
diff --git a/src/mm-options.c b/src/mm-options.c
index 190c99ea..0e86f708 100644
--- a/src/mm-options.c
+++ b/src/mm-options.c
@@ -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)
{
diff --git a/src/mm-options.h b/src/mm-options.h
index d9190bc3..f3a2c449 100644
--- a/src/mm-options.h
+++ b/src/mm-options.h
@@ -3,7 +3,8 @@
#ifndef MM_OPTIONS_H
#define MM_OPTIONS_H
-void mm_options_parse (int argc, char *argv[]);
-gboolean mm_options_debug (void);
+void mm_options_parse (int argc, char *argv[]);
+void mm_options_set_debug (gboolean enabled);
+gboolean mm_options_debug (void);
#endif /* MM_OPTIONS_H */
diff --git a/src/mm-serial.c b/src/mm-serial.c
index 04bea7dc..36a42de1 100644
--- a/src/mm-serial.c
+++ b/src/mm-serial.c
@@ -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