Enable/disable debugging on SIGUSR1.
This commit is contained in:
128
src/main.c
128
src/main.c
@@ -5,68 +5,88 @@
|
|||||||
#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,
|
||||||
const gchar *message,
|
const gchar *message,
|
||||||
gpointer ignored)
|
gpointer ignored)
|
||||||
{
|
{
|
||||||
int syslog_priority;
|
int syslog_priority;
|
||||||
|
|
||||||
switch (log_level) {
|
switch (log_level) {
|
||||||
case G_LOG_LEVEL_ERROR:
|
case G_LOG_LEVEL_ERROR:
|
||||||
syslog_priority = LOG_CRIT;
|
syslog_priority = LOG_CRIT;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case G_LOG_LEVEL_CRITICAL:
|
case G_LOG_LEVEL_CRITICAL:
|
||||||
syslog_priority = LOG_ERR;
|
syslog_priority = LOG_ERR;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case G_LOG_LEVEL_WARNING:
|
case G_LOG_LEVEL_WARNING:
|
||||||
syslog_priority = LOG_WARNING;
|
syslog_priority = LOG_WARNING;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case G_LOG_LEVEL_MESSAGE:
|
case G_LOG_LEVEL_MESSAGE:
|
||||||
syslog_priority = LOG_NOTICE;
|
syslog_priority = LOG_NOTICE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case G_LOG_LEVEL_DEBUG:
|
case G_LOG_LEVEL_DEBUG:
|
||||||
syslog_priority = LOG_DEBUG;
|
syslog_priority = LOG_DEBUG;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case G_LOG_LEVEL_INFO:
|
case G_LOG_LEVEL_INFO:
|
||||||
default:
|
default:
|
||||||
syslog_priority = LOG_INFO;
|
syslog_priority = LOG_INFO;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
syslog (syslog_priority, "%s", message);
|
syslog (syslog_priority, "%s", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
logging_setup (void)
|
logging_setup (void)
|
||||||
{
|
{
|
||||||
openlog (G_LOG_DOMAIN, LOG_CONS, LOG_DAEMON);
|
openlog (G_LOG_DOMAIN, LOG_CONS, LOG_DAEMON);
|
||||||
g_log_set_handler (G_LOG_DOMAIN,
|
g_log_set_handler (G_LOG_DOMAIN,
|
||||||
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
|
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
|
||||||
log_handler,
|
log_handler,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
logging_shutdown (void)
|
logging_shutdown (void)
|
||||||
{
|
{
|
||||||
closelog ();
|
closelog ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
destroy_cb (DBusGProxy *proxy, gpointer user_data)
|
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_message ("disconnected from the system bus, exiting.");
|
||||||
g_main_loop_quit (loop);
|
g_main_loop_quit (loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@@ -80,11 +100,11 @@ dbus_init (GMainLoop *loop)
|
|||||||
connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &err);
|
connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &err);
|
||||||
if (!connection) {
|
if (!connection) {
|
||||||
g_warning ("Could not get the system bus. Make sure "
|
g_warning ("Could not get the system bus. Make sure "
|
||||||
"the message bus daemon is running! Message: %s",
|
"the message bus daemon is running! Message: %s",
|
||||||
err->message);
|
err->message);
|
||||||
g_error_free (err);
|
g_error_free (err);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
proxy = dbus_g_proxy_new_for_name (connection,
|
proxy = dbus_g_proxy_new_for_name (connection,
|
||||||
"org.freedesktop.DBus",
|
"org.freedesktop.DBus",
|
||||||
@@ -92,23 +112,23 @@ dbus_init (GMainLoop *loop)
|
|||||||
"org.freedesktop.DBus");
|
"org.freedesktop.DBus");
|
||||||
|
|
||||||
if (!dbus_g_proxy_call (proxy, "RequestName", &err,
|
if (!dbus_g_proxy_call (proxy, "RequestName", &err,
|
||||||
G_TYPE_STRING, MM_DBUS_SERVICE,
|
G_TYPE_STRING, MM_DBUS_SERVICE,
|
||||||
G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE,
|
G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE,
|
||||||
G_TYPE_INVALID,
|
G_TYPE_INVALID,
|
||||||
G_TYPE_UINT, &request_name_result,
|
G_TYPE_UINT, &request_name_result,
|
||||||
G_TYPE_INVALID)) {
|
G_TYPE_INVALID)) {
|
||||||
g_warning ("Could not acquire the %s service.\n"
|
g_warning ("Could not acquire the %s service.\n"
|
||||||
" Message: '%s'", MM_DBUS_SERVICE, err->message);
|
" Message: '%s'", MM_DBUS_SERVICE, err->message);
|
||||||
g_error_free (err);
|
g_error_free (err);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request_name_result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
|
if (request_name_result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
|
||||||
g_warning ("Could not acquire the NetworkManagerSystemSettings service "
|
g_warning ("Could not acquire the NetworkManagerSystemSettings service "
|
||||||
"as it is already taken. Return: %d",
|
"as it is already taken. Return: %d",
|
||||||
request_name_result);
|
request_name_result);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_signal_connect (proxy, "destroy", G_CALLBACK (destroy_cb), loop);
|
g_signal_connect (proxy, "destroy", G_CALLBACK (destroy_cb), loop);
|
||||||
|
|
||||||
@@ -130,8 +150,10 @@ main (int argc, char *argv[])
|
|||||||
mm_options_parse (argc, argv);
|
mm_options_parse (argc, argv);
|
||||||
g_type_init ();
|
g_type_init ();
|
||||||
|
|
||||||
if (!mm_options_debug ())
|
setup_signals ();
|
||||||
logging_setup ();
|
|
||||||
|
if (!mm_options_debug ())
|
||||||
|
logging_setup ();
|
||||||
|
|
||||||
loop = g_main_loop_new (NULL, FALSE);
|
loop = g_main_loop_new (NULL, FALSE);
|
||||||
|
|
||||||
|
@@ -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)
|
||||||
{
|
{
|
||||||
|
@@ -3,7 +3,8 @@
|
|||||||
#ifndef MM_OPTIONS_H
|
#ifndef MM_OPTIONS_H
|
||||||
#define MM_OPTIONS_H
|
#define MM_OPTIONS_H
|
||||||
|
|
||||||
void mm_options_parse (int argc, char *argv[]);
|
void mm_options_parse (int argc, char *argv[]);
|
||||||
gboolean mm_options_debug (void);
|
void mm_options_set_debug (gboolean enabled);
|
||||||
|
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