core: rework logging

Make it more flexible, add logging to a file, and absolute and
relative timestamps.
This commit is contained in:
Dan Williams
2011-01-23 20:51:48 -06:00
parent f85b014d84
commit 16039244bb
30 changed files with 537 additions and 414 deletions

View File

@@ -28,6 +28,7 @@
#include "mm-callback-info.h"
#include "mm-serial-port.h"
#include "mm-serial-parsers.h"
#include "mm-log.h"
static void modem_init (MMModem *modem_class);
@@ -140,7 +141,7 @@ evdo_state_done (MMAtSerialPort *port,
G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
if (!r) {
/* Parse error; warn about it and assume EVDO is not available */
g_warning ("AnyDATA(%s): *HSTATE parse regex creation failed.", __func__);
mm_warn ("ANYDATA: *HSTATE parse regex creation failed.");
goto done;
}
@@ -167,7 +168,7 @@ evdo_state_done (MMAtSerialPort *port,
reg_state = MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
break;
default:
g_message ("ANYDATA: unknown *STATE (%d); assuming no service.", val);
mm_warn ("ANYDATA: unknown *STATE (%d); assuming no service.", val);
/* fall through */
case 0: /* NO SERVICE */
case 1: /* ACQUISITION */
@@ -206,7 +207,7 @@ state_done (MMAtSerialPort *port,
r = g_regex_new ("\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*([^,\\)]*)\\s*,.*",
G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
if (!r) {
g_warning ("AnyDATA(%s): *STATE parse regex creation failed.", __func__);
mm_warn ("ANYDATA: *STATE parse regex creation failed.");
mm_callback_info_schedule (info);
return;
}
@@ -235,7 +236,7 @@ state_done (MMAtSerialPort *port,
reg_state = MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
break;
default:
g_warning ("ANYDATA: unknown *STATE (%d); assuming no service.", val);
mm_warn ("ANYDATA: unknown *STATE (%d); assuming no service.", val);
/* fall through */
case 0: /* NO SERVICE */
break;

View File

@@ -27,6 +27,7 @@
#include "mm-callback-info.h"
#include "mm-serial-port.h"
#include "mm-serial-parsers.h"
#include "mm-log.h"
static void modem_init (MMModem *modem_class);
@@ -79,7 +80,7 @@ parse_quality (const char *str, const char *detail)
quality = strtol (str, NULL, 10);
if (errno == 0) {
quality = CLAMP (quality, 0, 100);
g_debug ("%s: %ld", detail, quality);
mm_dbg ("%s: %ld", detail, quality);
return (gint) quality;
}
return -1;
@@ -177,7 +178,7 @@ sysinfo_done (MMAtSerialPort *port,
r = g_regex_new ("\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)",
G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
if (!r) {
g_warning ("Huawei(%s): ^SYSINFO parse regex creation failed.", __func__);
mm_warn ("Huawei: ^SYSINFO parse regex creation failed.");
goto done;
}
@@ -218,7 +219,7 @@ sysinfo_done (MMAtSerialPort *port,
mm_generic_cdma_query_reg_state_set_callback_1x_state (info, reg_state);
}
} else
g_warning ("Huawei(%s): failed to parse ^SYSINFO response.", __func__);
mm_warn ("Huawei: failed to parse ^SYSINFO response.");
g_match_info_free (match_info);
g_regex_unref (r);

View File

@@ -29,7 +29,7 @@
#include "mm-callback-info.h"
#include "mm-at-serial-port.h"
#include "mm-serial-parsers.h"
#include "mm-options.h"
#include "mm-log.h"
static void modem_init (MMModem *modem_class);
static void modem_gsm_network_init (MMModemGsmNetwork *gsm_network_class);
@@ -534,7 +534,7 @@ send_huawei_cpin_done (MMAtSerialPort *port,
else if (strstr (pin_type, MM_MODEM_GSM_CARD_SIM_PIN2))
num = 5;
else {
g_debug ("%s: unhandled pin type '%s'", __func__, pin_type);
mm_dbg ("unhandled pin type '%s'", pin_type);
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "Unhandled PIN type");
}
@@ -576,7 +576,7 @@ get_unlock_retries (MMModemGsmCard *modem,
char *command;
MMCallbackInfo *info = mm_callback_info_uint_new (MM_MODEM (modem), callback, user_data);
g_debug ("%s: pin type '%s'", __func__, pin_type);
mm_dbg ("pin type '%s'", pin_type);
/* Ensure we have a usable port to use for the command */
port = mm_generic_gsm_get_best_at_port (MM_GENERIC_GSM (modem), &info->error);
@@ -660,12 +660,11 @@ handle_mode_change (MMAtSerialPort *port,
} else if (a == 0)
act = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN;
else {
g_warning ("Couldn't parse mode change value: '%s'", str);
mm_warn ("Couldn't parse mode change value: '%s'", str);
return;
}
if (mm_options_debug ())
g_debug ("Access Technology: %d", act);
mm_dbg ("Access Technology: %d", act);
mm_generic_gsm_update_access_technology (MM_GENERIC_GSM (self), act);
}
@@ -680,11 +679,9 @@ handle_status_change (MMAtSerialPort *port,
str = g_match_info_fetch (match_info, 1);
if (sscanf (str, "%x,%x,%x,%x,%x,%x,%x", &n1, &n2, &n3, &n4, &n5, &n6, &n7)) {
if (mm_options_debug ()) {
g_debug ("Duration: %d Up: %d Kbps Down: %d Kbps Total: %d Total: %d\n",
mm_dbg ("Duration: %d Up: %d Kbps Down: %d Kbps Total: %d Total: %d\n",
n1, n2 * 8 / 1000, n3 * 8 / 1000, n4 / 1024, n5 / 1024);
}
}
g_free (str);
}

View File

@@ -32,6 +32,7 @@
#include "mm-at-serial-port.h"
#include "mm-generic-gsm.h"
#include "mm-modem-helpers.h"
#include "mm-log.h"
struct _MMModemIceraPrivate {
/* Pending connection attempt */
@@ -325,7 +326,7 @@ icera_disconnect_done (MMModem *modem,
GError *error,
gpointer user_data)
{
g_message ("Modem signaled disconnection from the network");
mm_info ("Modem signaled disconnection from the network");
}
static void
@@ -380,7 +381,7 @@ connection_enabled (MMAtSerialPort *port,
connect_pending_done (self);
break;
default:
g_warning ("Unknown Icera connect status %d", status);
mm_warn ("Unknown Icera connect status %d", status);
break;
}
}

View File

@@ -1,7 +1,7 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* Copyright (C) 2008 - 2010 Ericsson AB
* Copyright (C) 2009 - 2010 Red Hat, Inc.
* Copyright (C) 2009 - 2011 Red Hat, Inc.
*
* Author: Per Hallsmark <per.hallsmark@ericsson.com>
* Bjorn Runaker <bjorn.runaker@ericsson.com>
@@ -31,6 +31,7 @@
#include "mm-modem-gsm-card.h"
#include "mm-errors.h"
#include "mm-callback-info.h"
#include "mm-log.h"
static void modem_init (MMModem *modem_class);
static void modem_gsm_network_init (MMModemGsmNetwork *gsm_network_class);
@@ -410,7 +411,7 @@ mbm_emrdy_done (MMAtSerialPort *port,
MMModemMbmPrivate *priv = MM_MODEM_MBM_GET_PRIVATE (info->modem);
if (g_error_matches (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_RESPONSE_TIMEOUT))
g_warning ("%s: timed out waiting for EMRDY response.", __func__);
mm_warn ("timed out waiting for EMRDY response.");
else
priv->have_emrdy = TRUE;
@@ -632,16 +633,16 @@ mbm_e2nap_received (MMAtSerialPort *port,
g_free (str);
if (MBM_E2NAP_DISCONNECTED == state) {
g_debug ("%s: disconnected", __func__);
mm_dbg ("disconnected");
mbm_do_connect_done (MM_MODEM_MBM (user_data), FALSE);
} else if (MBM_E2NAP_CONNECTED == state) {
g_debug ("%s: connected", __func__);
mm_dbg ("connected");
mbm_do_connect_done (MM_MODEM_MBM (user_data), TRUE);
} else if (MBM_E2NAP_CONNECTING == state)
g_debug("%s: connecting", __func__);
mm_dbg ("connecting");
else {
/* Should not happen */
g_debug("%s: unhandled E2NAP state %d", __func__, state);
mm_dbg ("unhandled E2NAP state %d", state);
mbm_do_connect_done (MM_MODEM_MBM (user_data), FALSE);
}
}
@@ -811,7 +812,7 @@ send_epin_done (MMAtSerialPort *port,
else if (strstr (pin_type, MM_MODEM_GSM_CARD_SIM_PUK2))
sscanf (response->str, "*EPIN: %*d, %*d, %*d, %d", &attempts_left);
else {
g_debug ("%s: unhandled pin type '%s'", __func__, pin_type);
mm_dbg ("unhandled pin type '%s'", pin_type);
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "Unhandled PIN type");
}
@@ -838,7 +839,7 @@ mbm_get_unlock_retries (MMModemGsmCard *modem,
char *command;
MMCallbackInfo *info = mm_callback_info_uint_new (MM_MODEM (modem), callback, user_data);
g_debug ("%s: pin type '%s'", __func__, pin_type);
mm_dbg ("pin type '%s'", pin_type);
/* Ensure we have a usable port to use for the command */
port = mm_generic_gsm_get_best_at_port (MM_GENERIC_GSM (modem), &info->error);

View File

@@ -31,6 +31,7 @@
#include "mm-generic-cdma.h"
#include "mm-errors.h"
#include "mm-serial-parsers.h"
#include "mm-log.h"
G_DEFINE_TYPE (MMPluginGeneric, mm_plugin_generic, MM_TYPE_PLUGIN_BASE)
@@ -127,7 +128,7 @@ grab_port (MMPluginBase *base,
g_set_error (error, 0, 0, "Could not get port's sysfs file.");
return NULL;
} else {
g_message ("%s: (%s/%s) WARNING: missing udev 'device' file",
mm_warn ("%s: (%s/%s) WARNING: missing udev 'device' file",
mm_plugin_get_name (MM_PLUGIN (base)),
subsys,
name);

View File

@@ -27,6 +27,7 @@
#include "mm-modem-huawei-cdma.h"
#include "mm-serial-parsers.h"
#include "mm-at-serial-port.h"
#include "mm-log.h"
G_DEFINE_TYPE (MMPluginHuawei, mm_plugin_huawei, MM_TYPE_PLUGIN_BASE)
@@ -240,8 +241,8 @@ supports_port (MMPluginBase *base,
info->id = g_timeout_add_seconds (7, probe_secondary_timeout, task);
if (!mm_serial_port_open (MM_SERIAL_PORT (info->serial), &error)) {
g_warning ("%s: (Huawei) %s: couldn't open serial port: (%d) %s",
__func__, name,
mm_warn ("(Huawei) %s: couldn't open serial port: (%d) %s",
name,
error ? error->code : -1,
error && error->message ? error->message : "(unknown)");
g_clear_error (&error);

View File

@@ -84,7 +84,7 @@ supports_port (MMPluginBase *base,
client = g_udev_client_new (sys);
if (!client) {
g_warning ("mbm: could not get udev client.");
g_warn_if_fail (client != NULL);
return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED;
}

View File

@@ -81,6 +81,8 @@ endif
modem_manager_SOURCES = \
main.c \
mm-log.c \
mm-log.h \
mm-callback-info.c \
mm-callback-info.h \
$(auth_sources) \
@@ -109,8 +111,6 @@ modem_manager_SOURCES = \
mm-modem-gsm-ussd.h \
mm-modem-simple.c \
mm-modem-simple.h \
mm-options.c \
mm-options.h \
mm-plugin.c \
mm-plugin.h \
mm-plugin-base.c \

View File

@@ -11,7 +11,7 @@
* GNU General Public License for more details:
*
* Copyright (C) 2008 - 2009 Novell, Inc.
* Copyright (C) 2009 - 2010 Red Hat, Inc.
* Copyright (C) 2009 - 2011 Red Hat, Inc.
*/
#include <config.h>
@@ -21,8 +21,10 @@
#include <unistd.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
#include <stdlib.h>
#include "mm-manager.h"
#include "mm-options.h"
#include "mm-log.h"
#if !defined(MM_DIST_VERSION)
# define MM_DIST_VERSION VERSION
@@ -34,9 +36,9 @@ static void
mm_signal_handler (int signo)
{
if (signo == SIGUSR1)
mm_options_set_debug (!mm_options_debug ());
mm_log_usr1 ();
else if (signo == SIGINT || signo == SIGTERM) {
g_message ("Caught signal %d, shutting down...", signo);
mm_info ("Caught signal %d, shutting down...", signo);
if (loop)
g_main_loop_quit (loop);
else
@@ -59,65 +61,10 @@ setup_signals (void)
sigaction (SIGINT, &action, NULL);
}
static void
log_handler (const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *message,
gpointer ignored)
{
int syslog_priority;
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_WARNING:
syslog_priority = LOG_WARNING;
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_INFO:
default:
syslog_priority = LOG_INFO;
break;
}
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);
}
static void
logging_shutdown (void)
{
closelog ();
}
static void
destroy_cb (DBusGProxy *proxy, gpointer user_data)
{
g_message ("disconnected from the system bus, exiting.");
mm_warn ("disconnected from the system bus, exiting.");
g_main_loop_quit (loop);
}
@@ -139,14 +86,14 @@ create_dbus_proxy (DBusGConnection *bus)
G_TYPE_INVALID,
G_TYPE_UINT, &request_name_result,
G_TYPE_INVALID)) {
g_warning ("Could not acquire the %s service.\n"
mm_warn ("Could not acquire the %s service.\n"
" Message: '%s'", MM_DBUS_SERVICE, err->message);
g_error_free (err);
g_object_unref (proxy);
proxy = NULL;
} else if (request_name_result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
g_warning ("Could not acquire the " MM_DBUS_SERVICE
mm_warn ("Could not acquire the " MM_DBUS_SERVICE
" service as it is already taken. Return: %d",
request_name_result);
@@ -175,17 +122,46 @@ main (int argc, char *argv[])
DBusGProxy *proxy;
MMManager *manager;
GError *err = NULL;
GOptionContext *opt_ctx;
guint id;
const char *log_level = NULL, *log_file = NULL;
gboolean debug = FALSE, show_ts = FALSE, rel_ts = FALSE;
GOptionEntry entries[] = {
{ "debug", 0, 0, G_OPTION_ARG_NONE, &debug, "Output to console rather than syslog", NULL },
{ "log-level", 0, 0, G_OPTION_ARG_STRING, &log_level, "Log level: one of [ERR, WARN, INFO, DEBUG]", "INFO" },
{ "log-file", 0, 0, G_OPTION_ARG_STRING, &log_file, "Path to log file", NULL },
{ "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 },
{ NULL }
};
mm_options_parse (argc, argv);
g_type_init ();
opt_ctx = g_option_context_new (NULL);
g_option_context_set_summary (opt_ctx, "DBus system service to communicate with modems.");
g_option_context_add_main_entries (opt_ctx, entries, NULL);
if (!g_option_context_parse (opt_ctx, &argc, &argv, &err)) {
g_warning ("%s\n", err->message);
g_error_free (err);
exit (1);
}
g_option_context_free (opt_ctx);
if (debug)
log_level = "DEBUG";
if (!mm_log_setup (log_level, log_file, show_ts, rel_ts, &err)) {
g_warning ("Failed to set up logging: %s", err->message);
g_error_free (err);
exit (1);
}
setup_signals ();
if (!mm_options_debug ())
logging_setup ();
g_message ("ModemManager (version " MM_DIST_VERSION ") starting...");
mm_info ("ModemManager (version " MM_DIST_VERSION ") starting...");
bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &err);
if (!bus) {
@@ -235,7 +211,7 @@ main (int argc, char *argv[])
g_object_unref (proxy);
dbus_g_connection_unref (bus);
logging_shutdown ();
mm_log_shutdown ();
return 0;
}

View File

@@ -23,7 +23,7 @@
#include "mm-at-serial-port.h"
#include "mm-errors.h"
#include "mm-options.h"
#include "mm-log.h"
G_DEFINE_TYPE (MMAtSerialPort, mm_at_serial_port, MM_TYPE_SERIAL_PORT)
@@ -273,7 +273,6 @@ debug_log (MMSerialPort *port, const char *prefix, const char *buf, gsize len)
{
static GString *debug = NULL;
const char *s;
GTimeVal tv;
if (!debug)
debug = g_string_sized_new (256);
@@ -296,12 +295,7 @@ debug_log (MMSerialPort *port, const char *prefix, const char *buf, gsize len)
}
g_string_append_c (debug, '\'');
g_get_current_time (&tv);
g_debug ("<%ld.%ld> (%s): %s",
tv.tv_sec,
tv.tv_usec,
mm_port_get_device (MM_PORT (port)),
debug->str);
mm_dbg ("(%s): %s", mm_port_get_device (MM_PORT (port)), debug->str);
g_string_truncate (debug, 0);
}

View File

@@ -30,6 +30,7 @@
#include "mm-serial-parsers.h"
#include "mm-modem-helpers.h"
#include "libqcdm/src/commands.h"
#include "mm-log.h"
#define MM_GENERIC_CDMA_PREV_STATE_TAG "prev-state"
@@ -1047,7 +1048,7 @@ get_signal_quality (MMModemCdma *modem,
at_port = mm_generic_cdma_get_best_at_port (MM_GENERIC_CDMA (modem), &info->error);
if (!at_port && !priv->qcdm) {
g_message ("Returning saved signal quality %d", priv->cdma1x_quality);
mm_dbg ("Returning saved signal quality %d", priv->cdma1x_quality);
mm_callback_info_set_result (info, GUINT_TO_POINTER (priv->cdma1x_quality), NULL);
mm_callback_info_schedule (info);
return;
@@ -1876,7 +1877,7 @@ get_registration_state (MMModemCdma *modem,
port = mm_generic_cdma_get_best_at_port (MM_GENERIC_CDMA (modem), &info->error);
if (!port && !priv->qcdm) {
g_message ("Returning saved registration states: 1x: %d EVDO: %d",
mm_dbg ("Returning saved registration states: 1x: %d EVDO: %d",
priv->cdma_1x_reg_state, priv->evdo_reg_state);
mm_generic_cdma_query_reg_state_set_callback_1x_state (info, priv->cdma_1x_reg_state);
mm_generic_cdma_query_reg_state_set_callback_evdo_state (info, priv->evdo_reg_state);

View File

@@ -33,7 +33,7 @@
#include "mm-qcdm-serial-port.h"
#include "mm-serial-parsers.h"
#include "mm-modem-helpers.h"
#include "mm-options.h"
#include "mm-log.h"
#include "mm-properties-changed-signal.h"
#include "mm-utils.h"
#include "mm-modem-location.h"
@@ -471,10 +471,8 @@ get_iccid_done (MMModem *modem,
g_free (priv->simid);
priv->simid = g_strdup (g_checksum_get_string (sum));
if (mm_options_debug ()) {
g_debug ("SIM ID source '%s'", response);
g_debug ("SIM ID '%s'", priv->simid);
}
mm_dbg ("SIM ID source '%s'", response);
mm_dbg ("SIM ID '%s'", priv->simid);
g_object_notify (G_OBJECT (modem), MM_MODEM_GSM_CARD_SIM_IDENTIFIER);
@@ -1306,14 +1304,11 @@ mm_generic_gsm_enable_complete (MMGenericGsm *self,
*/
if (priv->secondary) {
if (!mm_serial_port_open (MM_SERIAL_PORT (priv->secondary), &error)) {
if (mm_options_debug ()) {
g_warning ("%s: error opening secondary port: (%d) %s",
__func__,
mm_dbg ("error opening secondary port: (%d) %s",
error ? error->code : -1,
error && error->message ? error->message : "(unknown)");
}
}
}
/* Try to enable XON/XOFF flow control */
mm_at_serial_port_queue_command (priv->primary, "+IFC=1,1", 3, NULL, NULL);
@@ -2237,7 +2232,7 @@ roam_disconnect_done (MMModem *modem,
GError *error,
gpointer user_data)
{
g_message ("Disconnected because roaming is not allowed");
mm_info ("Disconnected because roaming is not allowed");
}
static void
@@ -2268,7 +2263,7 @@ mm_generic_gsm_set_reg_status (MMGenericGsm *self,
if (priv->reg_status[rs_type - 1] == status)
return;
g_debug ("%s registration state changed: %d",
mm_dbg ("%s registration state changed: %d",
(rs_type == MM_GENERIC_GSM_REG_TYPE_CS) ? "CS" : "PS",
status);
priv->reg_status[rs_type - 1] = status;
@@ -2389,11 +2384,8 @@ reg_state_changed (MMAtSerialPort *port,
GError *error = NULL;
if (!mm_gsm_parse_creg_response (match_info, &state, &lac, &cell_id, &act, &cgreg, &error)) {
if (mm_options_debug ()) {
g_warning ("%s: error parsing unsolicited registration: %s",
__func__,
mm_warn ("error parsing unsolicited registration: %s",
error && error->message ? error->message : "(unknown)");
}
return;
}
@@ -3891,10 +3883,8 @@ ussd_send_done (MMAtSerialPort *port,
if (reply) {
/* look for the reply data coding scheme */
if (mm_options_debug ()) {
if ((start = strrchr (end, ',')) != NULL)
g_debug ("USSD data coding scheme %d", atoi (start + 1));
}
mm_dbg ("USSD data coding scheme %d", atoi (start + 1));
converted = mm_modem_charset_hex_to_utf8 (reply, priv->cur_charset);
mm_callback_info_set_result (info, converted, g_free);
@@ -4164,6 +4154,7 @@ simple_state_machine (MMModem *modem, GError *error, gpointer user_data)
gboolean done = FALSE;
MMModemGsmAllowedMode allowed_mode;
gboolean home_only = FALSE;
char *data_device;
info->error = mm_modem_check_removed (modem, error);
if (info->error)
@@ -4171,16 +4162,9 @@ simple_state_machine (MMModem *modem, GError *error, gpointer user_data)
priv = MM_GENERIC_GSM_GET_PRIVATE (modem);
if (mm_options_debug ()) {
GTimeVal tv;
char *data_device;
g_object_get (G_OBJECT (modem), MM_MODEM_DATA_DEVICE, &data_device, NULL);
g_get_current_time (&tv);
g_debug ("<%ld.%ld> (%s): simple connect state %d",
tv.tv_sec, tv.tv_usec, data_device, state);
mm_dbg ("(%s): simple connect state %d", data_device, state);
g_free (data_device);
}
switch (state) {
case SIMPLE_STATE_CHECK_PIN:
@@ -4279,29 +4263,21 @@ simple_connect (MMModemSimple *simple,
gpointer user_data)
{
MMCallbackInfo *info;
/* If debugging, list all the simple connect properties */
if (mm_options_debug ()) {
GHashTableIter iter;
gpointer key, value;
GTimeVal tv;
char *data_device;
/* List simple connect properties when debugging */
g_object_get (G_OBJECT (simple), MM_MODEM_DATA_DEVICE, &data_device, NULL);
g_get_current_time (&tv);
g_hash_table_iter_init (&iter, properties);
while (g_hash_table_iter_next (&iter, &key, &value)) {
char *val_str;
val_str = g_strdup_value_contents ((GValue *) value);
g_debug ("<%ld.%ld> (%s): %s => %s",
tv.tv_sec, tv.tv_usec,
data_device, (const char *) key, val_str);
mm_dbg ("(%s): %s => %s", data_device, (const char *) key, val_str);
g_free (val_str);
}
g_free (data_device);
}
info = mm_callback_info_new (MM_MODEM (simple), callback, user_data);
mm_callback_info_set_data (info, "simple-connect-properties",

227
src/mm-log.c Normal file
View File

@@ -0,0 +1,227 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details:
*
* Copyright (C) 2011 Red Hat, Inc.
*/
#define _GNU_SOURCE
#include <config.h>
#include <stdio.h>
#include <syslog.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <unistd.h>
#include "mm-log.h"
enum {
TS_FLAG_NONE = 0,
TS_FLAG_WALL,
TS_FLAG_REL
};
static gboolean ts_flags = TS_FLAG_NONE;
static guint32 log_level = LOGL_INFO | LOGL_WARN | LOGL_ERR;
static GTimeVal rel_start = { 0, 0 };
static int logfd = -1;
typedef struct {
guint32 num;
const char *name;
} LogDesc;
static const LogDesc level_descs[] = {
{ LOGL_ERR, "ERR" },
{ LOGL_WARN | LOGL_ERR, "WARN" },
{ LOGL_INFO | LOGL_WARN | LOGL_ERR, "INFO" },
{ LOGL_DEBUG | LOGL_INFO | LOGL_WARN | LOGL_ERR, "DEBUG" },
{ 0, NULL }
};
void
_mm_log (const char *loc,
const char *func,
guint32 level,
const char *fmt,
...)
{
va_list args;
char *msg;
GTimeVal tv;
char tsbuf[100] = { 0 };
char msgbuf[512] = { 0 };
int syslog_priority = LOG_INFO;
const char *prefix = NULL;
if (!(log_level & level))
return;
va_start (args, fmt);
msg = g_strdup_vprintf (fmt, args);
va_end (args);
if (ts_flags == TS_FLAG_WALL) {
g_get_current_time (&tv);
snprintf (&tsbuf[0], sizeof (tsbuf), " [%09ld.%06ld]", tv.tv_sec, tv.tv_usec);
} else if (ts_flags == TS_FLAG_REL) {
time_t secs;
suseconds_t usecs;
g_get_current_time (&tv);
secs = tv.tv_sec - rel_start.tv_sec;
usecs = tv.tv_usec - rel_start.tv_usec;
if (usecs < 0) {
secs--;
usecs += 1000000;
}
snprintf (&tsbuf[0], sizeof (tsbuf), " [%06ld.%06ld]", secs, usecs);
}
if ((log_level & LOGL_DEBUG) && (level == LOGL_DEBUG))
prefix = "debug";
else if ((log_level & LOGL_INFO) && (level == LOGL_INFO))
prefix = "info";
else if ((log_level & LOGL_WARN) && (level == LOGL_WARN)) {
prefix = "warn";
syslog_priority = LOG_WARNING;
} else if ((log_level & LOGL_ERR) && (level == LOGL_ERR)) {
prefix = "err";
syslog_priority = LOG_ERR;
} else
g_warn_if_reached ();
if (prefix) {
if (log_level & LOGL_DEBUG)
snprintf (msgbuf, sizeof (msgbuf), "<%s>%s [%s] %s(): %s\n", prefix, tsbuf, loc, func, msg);
else
snprintf (msgbuf, sizeof (msgbuf), "<%s>%s %s\n", prefix, tsbuf, msg);
if (logfd < 0)
syslog (syslog_priority, "%s", msgbuf);
else {
write (logfd, msgbuf, strlen (msgbuf));
fsync (logfd); /* Make sure output is dumped to disk immediately */
}
}
g_free (msg);
}
static void
log_handler (const gchar *log_domain,
GLogLevelFlags level,
const gchar *message,
gpointer ignored)
{
int syslog_priority;
switch (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_WARNING:
syslog_priority = LOG_WARNING;
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_INFO:
default:
syslog_priority = LOG_INFO;
break;
}
if (logfd < 0)
syslog (syslog_priority, "%s", message);
else
write (logfd, message, strlen (message));
}
gboolean
mm_log_setup (const char *level,
const char *log_file,
gboolean show_timestamps,
gboolean rel_timestamps,
GError **error)
{
/* levels */
if (level && strlen (level)) {
gboolean found = FALSE;
const LogDesc *diter;
for (diter = &level_descs[0]; diter->name; diter++) {
if (!strcasecmp (diter->name, level)) {
log_level = diter->num;
found = TRUE;
break;
}
}
if (!found) {
g_set_error (error, 0, 0, "Unknown log level '%s'", level);
return FALSE;
}
}
if (show_timestamps)
ts_flags = TS_FLAG_WALL;
else if (rel_timestamps)
ts_flags = TS_FLAG_REL;
/* Grab start time for relative timestamps */
g_get_current_time (&rel_start);
if (log_file == NULL)
openlog (G_LOG_DOMAIN, LOG_CONS | LOG_PID | LOG_PERROR, LOG_DAEMON);
else {
logfd = open (log_file,
O_CREAT | O_APPEND | O_WRONLY,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
if (logfd < 0) {
g_set_error (error, 0, 0, "Failed to open log file: (%d) %s",
errno, strerror (errno));
return FALSE;
}
}
g_log_set_handler (G_LOG_DOMAIN,
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
log_handler,
NULL);
return TRUE;
}
void
mm_log_usr1 (void)
{
}
void
mm_log_shutdown (void)
{
if (logfd < 0)
closelog ();
else
close (logfd);
}

61
src/mm-log.h Normal file
View File

@@ -0,0 +1,61 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details:
*
* Copyright (C) 2011 Red Hat, Inc.
*/
#ifndef MM_LOG_H
#define MM_LOG_H
#include <glib.h>
/* Log levels */
enum {
LOGL_ERR = 0x00000001,
LOGL_WARN = 0x00000002,
LOGL_INFO = 0x00000004,
LOGL_DEBUG = 0x00000008
};
#define mm_err(...) \
_mm_log (G_STRLOC, G_STRFUNC, LOGL_ERR, ## __VA_ARGS__ )
#define mm_warn(...) \
_mm_log (G_STRLOC, G_STRFUNC, LOGL_WARN, ## __VA_ARGS__ )
#define mm_info(...) \
_mm_log (G_STRLOC, G_STRFUNC, LOGL_INFO, ## __VA_ARGS__ )
#define mm_dbg(...) \
_mm_log (G_STRLOC, G_STRFUNC, LOGL_DEBUG, ## __VA_ARGS__ )
#define mm_log(level, ...) \
_mm_log (G_STRLOC, G_STRFUNC, level, ## __VA_ARGS__ )
void _mm_log (const char *loc,
const char *func,
guint32 level,
const char *fmt,
...) __attribute__((__format__ (__printf__, 4, 5)));
gboolean mm_log_setup (const char *level,
const char *log_file,
gboolean show_ts,
gboolean rel_ts,
GError **error);
void mm_log_usr1 (void);
void mm_log_shutdown (void);
#endif /* MM_LOG_H */

View File

@@ -24,6 +24,7 @@
#include "mm-manager.h"
#include "mm-errors.h"
#include "mm-plugin.h"
#include "mm-log.h"
static gboolean impl_manager_enumerate_devices (MMManager *manager,
GPtrArray **devices,
@@ -112,9 +113,9 @@ load_plugin (const char *path)
plugin = (*plugin_create_func) ();
if (plugin) {
g_object_weak_ref (G_OBJECT (plugin), (GWeakNotify) g_module_close, module);
g_message ("Loaded plugin %s", mm_plugin_get_name (plugin));
mm_info ("Loaded plugin %s", mm_plugin_get_name (plugin));
} else
g_warning ("Could not load plugin %s: initialization failed", path);
mm_warn ("Could not load plugin %s: initialization failed", path);
out:
if (!plugin)
@@ -196,7 +197,7 @@ remove_modem (MMManager *manager, MMModem *modem)
device = mm_modem_get_device (modem);
g_assert (device);
g_debug ("Removed modem %s", device);
mm_dbg ("Removed modem %s", device);
g_signal_emit (manager, signals[DEVICE_REMOVED], 0, modem);
g_hash_table_remove (priv->modems, device);
@@ -234,7 +235,7 @@ check_export_modem (MMManager *self, MMModem *modem)
SupportsInfo *info = value;
if (!strcmp (info->physdev_path, modem_physdev)) {
g_debug ("(%s/%s): outstanding support task prevents export of %s",
mm_dbg ("(%s/%s): outstanding support task prevents export of %s",
info->subsys, info->name, modem_physdev);
goto out;
}
@@ -257,7 +258,7 @@ check_export_modem (MMManager *self, MMModem *modem)
dbus_g_connection_register_g_object (priv->connection, path, G_OBJECT (modem));
g_object_set_data_full (G_OBJECT (modem), DBUS_PATH_TAG, path, (GDestroyNotify) g_free);
g_debug ("Exported modem %s as %s", modem_physdev, path);
mm_dbg ("Exported modem %s as %s", modem_physdev, path);
physdev = g_udev_client_query_by_sysfs_path (priv->udev, modem_physdev);
if (physdev)
@@ -268,10 +269,10 @@ check_export_modem (MMManager *self, MMModem *modem)
MM_MODEM_HW_VID, &vid,
MM_MODEM_HW_PID, &pid,
NULL);
g_debug ("(%s): VID 0x%04X PID 0x%04X (%s)",
mm_dbg ("(%s): VID 0x%04X PID 0x%04X (%s)",
path, (vid & 0xFFFF), (pid & 0xFFFF),
subsys ? subsys : "unknown");
g_debug ("(%s): data port is %s", path, data_device);
mm_dbg ("(%s): data port is %s", path, data_device);
g_free (data_device);
if (physdev)
@@ -309,7 +310,7 @@ add_modem (MMManager *manager, MMModem *modem, MMPlugin *plugin)
g_hash_table_insert (priv->modems, g_strdup (device), modem);
g_object_set_data (G_OBJECT (modem), MANAGER_PLUGIN_TAG, plugin);
g_debug ("Added modem %s", device);
mm_dbg ("Added modem %s", device);
g_signal_connect (modem, "notify::" MM_MODEM_VALID, G_CALLBACK (modem_valid), manager);
check_export_modem (manager, modem);
}
@@ -446,7 +447,7 @@ supports_defer_timeout (gpointer user_data)
existing = find_modem_for_device (info->manager, info->physdev_path);
g_debug ("(%s): re-checking support...", info->name);
mm_dbg ("(%s): re-checking support...", info->name);
try_supports_port (info->manager,
MM_PLUGIN (info->cur_plugin->data),
existing,
@@ -478,7 +479,7 @@ try_supports_port (MMManager *manager,
supports_callback (plugin, info->subsys, info->name, 0, info);
break;
case MM_PLUGIN_SUPPORTS_PORT_DEFER:
g_debug ("(%s): (%s) deferring support check",
mm_dbg ("(%s): (%s) deferring support check",
mm_plugin_get_name (plugin),
info->name);
if (info->defer_id)
@@ -549,7 +550,7 @@ do_grab_port (gpointer user_data)
type_name = "CDMA";
device = mm_modem_get_device (modem);
g_message ("(%s): %s modem %s claimed port %s",
mm_info ("(%s): %s modem %s claimed port %s",
mm_plugin_get_name (info->best_plugin),
type_name,
device,
@@ -558,8 +559,7 @@ do_grab_port (gpointer user_data)
add_modem (info->manager, modem, info->best_plugin);
} else {
g_warning ("%s: plugin '%s' claimed to support %s/%s but couldn't: (%d) %s",
__func__,
mm_warn ("plugin '%s' claimed to support %s/%s but couldn't: (%d) %s",
mm_plugin_get_name (info->best_plugin),
info->subsys,
info->name,
@@ -613,7 +613,7 @@ supports_callback (MMPlugin *plugin,
* support this port, but this plugin is clearly the right plugin
* since it claimed this port's physical modem, just drop the port.
*/
g_debug ("(%s/%s): ignoring port unsupported by physical modem's plugin",
mm_dbg ("(%s/%s): ignoring port unsupported by physical modem's plugin",
info->subsys, info->name);
supports_cleanup (info->manager, info->subsys, info->name, existing);
return;
@@ -631,7 +631,7 @@ supports_callback (MMPlugin *plugin,
*/
next_plugin = existing_plugin;
} else {
g_debug ("(%s/%s): plugin %p (%s) existing %p (%s) info->best %p (%s)",
mm_dbg ("(%s/%s): plugin %p (%s) existing %p (%s) info->best %p (%s)",
info->subsys, info->name,
plugin,
plugin ? mm_plugin_get_name (plugin) : "none",
@@ -783,14 +783,14 @@ device_added (MMManager *manager, GUdevDevice *device)
&& strcmp (name, "lo")
&& strcmp (name, "tty")
&& !strstr (name, "virbr"))
g_debug ("(%s/%s): could not get port's parent device", subsys, name);
mm_dbg ("(%s/%s): could not get port's parent device", subsys, name);
goto out;
}
/* Is the device blacklisted? */
if (g_udev_device_get_property_as_boolean (physdev, "ID_MM_DEVICE_IGNORE")) {
g_debug ("(%s/%s): port's parent device is blacklisted", subsys, name);
mm_dbg ("(%s/%s): port's parent device is blacklisted", subsys, name);
goto out;
}
@@ -799,13 +799,13 @@ device_added (MMManager *manager, GUdevDevice *device)
if ( physdev_subsys
&& !strcmp (physdev_subsys, "platform")
&& !g_udev_device_get_property_as_boolean (physdev, "ID_MM_PLATFORM_DRIVER_PROBE")) {
g_debug ("(%s/%s): port's parent platform driver is not whitelisted", subsys, name);
mm_dbg ("(%s/%s): port's parent platform driver is not whitelisted", subsys, name);
goto out;
}
physdev_path = g_udev_device_get_sysfs_path (physdev);
if (!physdev_path) {
g_debug ("(%s/%s): could not get port's parent device sysfs path", subsys, name);
mm_dbg ("(%s/%s): could not get port's parent device sysfs path", subsys, name);
goto out;
}
@@ -865,10 +865,10 @@ device_removed (MMManager *manager, GUdevDevice *device)
*/
const char *sysfs_path = g_udev_device_get_sysfs_path (device);
// g_debug ("Looking for a modem for removed device %s", sysfs_path);
// mm_dbg ("Looking for a modem for removed device %s", sysfs_path);
modem = find_modem_for_device (manager, sysfs_path);
if (modem) {
g_debug ("Removing modem claimed by removed device %s", sysfs_path);
mm_dbg ("Removing modem claimed by removed device %s", sysfs_path);
remove_modem (manager, modem);
return;
}

View File

@@ -25,7 +25,7 @@
#include "mm-at-serial-port.h"
#include "mm-qcdm-serial-port.h"
#include "mm-errors.h"
#include "mm-options.h"
#include "mm-log.h"
#include "mm-properties-changed-signal.h"
#include "mm-callback-info.h"
#include "mm-modem-helpers.h"
@@ -148,15 +148,13 @@ mm_modem_base_add_port (MMModemBase *self,
if (!port)
return NULL;
if (mm_options_debug ()) {
device = mm_modem_get_device (MM_MODEM (self));
g_message ("(%s) type %s claimed by %s",
mm_dbg ("(%s) type %s claimed by %s",
name,
mm_port_type_to_name (ptype),
device);
g_free (device);
}
key = get_hash_key (subsys, name);
g_hash_table_insert (priv->ports, key, port);
return port;
@@ -233,9 +231,9 @@ mm_modem_base_set_equipment_identifier (MMModemBase *self, const char *ident)
dbus_path = (const char *) g_object_get_data (G_OBJECT (self), DBUS_PATH_TAG);
if (dbus_path) {
if (priv->equipment_ident)
g_message ("Modem %s: Equipment identifier set (%s)", dbus_path, priv->equipment_ident);
mm_info ("Modem %s: Equipment identifier set (%s)", dbus_path, priv->equipment_ident);
else
g_message ("Modem %s: Equipment identifier not set", dbus_path);
mm_warn ("Modem %s: Equipment identifier not set", dbus_path);
}
g_object_notify (G_OBJECT (self), MM_MODEM_EQUIPMENT_IDENTIFIER);
@@ -274,9 +272,9 @@ mm_modem_base_set_unlock_required (MMModemBase *self, const char *unlock_require
dbus_path = (const char *) g_object_get_data (G_OBJECT (self), DBUS_PATH_TAG);
if (dbus_path) {
if (priv->unlock_required)
g_message ("Modem %s: unlock required (%s)", dbus_path, priv->unlock_required);
mm_info ("Modem %s: unlock required (%s)", dbus_path, priv->unlock_required);
else
g_message ("Modem %s: unlock no longer required", dbus_path);
mm_info ("Modem %s: unlock no longer required", dbus_path);
}
g_object_notify (G_OBJECT (self), MM_MODEM_UNLOCK_REQUIRED);
@@ -311,10 +309,10 @@ mm_modem_base_set_unlock_retries (MMModemBase *self, guint unlock_retries)
dbus_path = (const char *) g_object_get_data (G_OBJECT (self), DBUS_PATH_TAG);
if (dbus_path) {
if (priv->unlock_required) {
g_message ("Modem %s: # unlock retries for %s is %d",
mm_info ("Modem %s: # unlock retries for %s is %d",
dbus_path, priv->unlock_required, priv->unlock_retries);
} else {
g_message ("Modem %s: # unlock retries is %d",
mm_info ("Modem %s: # unlock retries is %d",
dbus_path, priv->unlock_retries);
}
}
@@ -446,8 +444,7 @@ card_info_cache_invoke (MMCallbackInfo *info)
priv->gsn,
priv->revision,
priv->model,
priv->manf,
mm_options_debug ());
priv->manf);
g_object_notify (G_OBJECT (self), MM_MODEM_DEVICE_IDENTIFIER);
callback (info->modem, priv->manf, priv->model, priv->revision, info->error, info->user_data);

View File

@@ -25,6 +25,7 @@
#include "mm-errors.h"
#include "mm-modem-helpers.h"
#include "mm-log.h"
const char *
mm_strip_tag (const char *str, const char *cmd)
@@ -829,10 +830,9 @@ mm_create_device_identifier (guint vid,
const char *gsn,
const char *revision,
const char *model,
const char *manf,
gboolean debug)
const char *manf)
{
GString *devid, *dbg = NULL;
GString *devid, *msg = NULL;
GChecksum *sum;
char *p, *ret = NULL;
char str_vid[10], str_pid[10];
@@ -859,41 +859,35 @@ mm_create_device_identifier (guint vid,
return NULL;
p = devid->str;
if (debug)
dbg = g_string_sized_new (strlen (devid->str) + 17);
msg = g_string_sized_new (strlen (devid->str) + 17);
sum = g_checksum_new (G_CHECKSUM_SHA1);
if (vid) {
snprintf (str_vid, sizeof (str_vid) - 1, "%08x", vid);
g_checksum_update (sum, (const guchar *) &str_vid[0], strlen (str_vid));
if (dbg)
g_string_append_printf (dbg, "%08x", vid);
g_string_append_printf (msg, "%08x", vid);
}
if (vid) {
snprintf (str_pid, sizeof (str_pid) - 1, "%08x", pid);
g_checksum_update (sum, (const guchar *) &str_pid[0], strlen (str_pid));
if (dbg)
g_string_append_printf (dbg, "%08x", pid);
g_string_append_printf (msg, "%08x", pid);
}
while (*p) {
/* Strip spaces and linebreaks */
if (!isblank (*p) && !isspace (*p) && isascii (*p)) {
g_checksum_update (sum, (const guchar *) p, 1);
if (dbg)
g_string_append_c (dbg, *p);
g_string_append_c (msg, *p);
}
p++;
}
ret = g_strdup (g_checksum_get_string (sum));
g_checksum_free (sum);
if (dbg) {
g_debug ("Device ID source '%s'", dbg->str);
g_debug ("Device ID '%s'", ret);
g_string_free (dbg, TRUE);
}
mm_dbg ("Device ID source '%s'", msg->str);
mm_dbg ("Device ID '%s'", ret);
g_string_free (msg, TRUE);
return ret;
}

View File

@@ -66,8 +66,7 @@ char *mm_create_device_identifier (guint vid,
const char *gsn,
const char *revision,
const char *model,
const char *manf,
gboolean debug);
const char *manf);
typedef struct CindResponse CindResponse;
GHashTable *mm_parse_cind_test_response (const char *reply, GError **error);

View File

@@ -18,7 +18,7 @@
#include <string.h>
#include <dbus/dbus-glib.h>
#include "mm-modem.h"
#include "mm-options.h"
#include "mm-log.h"
#include "mm-errors.h"
#include "mm-callback-info.h"
#include "mm-marshal.h"
@@ -755,22 +755,10 @@ mm_modem_set_state (MMModem *self,
dbus_path = (const char *) g_object_get_data (G_OBJECT (self), DBUS_PATH_TAG);
if (dbus_path) {
if (mm_options_debug ()) {
GTimeVal tv;
g_get_current_time (&tv);
g_debug ("<%ld.%ld> Modem %s: state changed (%s -> %s)",
tv.tv_sec,
tv.tv_usec,
mm_info ("Modem %s: state changed (%s -> %s)",
dbus_path,
state_to_string (old_state),
state_to_string (new_state));
} else {
g_message ("Modem %s: state changed (%s -> %s)",
dbus_path,
state_to_string (old_state),
state_to_string (new_state));
}
}
}
}

View File

@@ -1,55 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details:
*
* Copyright (C) 2008 Novell, Inc.
*/
#include <stdlib.h>
#include <glib.h>
#include "mm-options.h"
static gboolean debug = FALSE;
void
mm_options_parse (int argc, char *argv[])
{
GOptionContext *opt_ctx;
GError *error = NULL;
GOptionEntry entries[] = {
{ "debug", 0, 0, G_OPTION_ARG_NONE, &debug, "Output to console rather than syslog", NULL },
{ NULL }
};
opt_ctx = g_option_context_new (NULL);
g_option_context_set_summary (opt_ctx, "DBus system service to communicate with modems.");
g_option_context_add_main_entries (opt_ctx, entries, NULL);
if (!g_option_context_parse (opt_ctx, &argc, &argv, &error)) {
g_warning ("%s\n", error->message);
g_error_free (error);
exit (1);
}
g_option_context_free (opt_ctx);
}
void
mm_options_set_debug (gboolean enabled)
{
debug = enabled;
}
gboolean
mm_options_debug (void)
{
return debug;
}

View File

@@ -1,23 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details:
*
* Copyright (C) 2008 Novell, Inc.
*/
#ifndef MM_OPTIONS_H
#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

@@ -36,6 +36,7 @@
#include "mm-utils.h"
#include "libqcdm/src/commands.h"
#include "libqcdm/src/utils.h"
#include "mm-log.h"
static void plugin_init (MMPlugin *plugin_class);
@@ -807,7 +808,7 @@ try_open (gpointer user_data)
task_priv->full_id = g_signal_connect (task_priv->probe_port, "buffer-full",
G_CALLBACK (port_buffer_full), task);
g_debug ("(%s): probe requested by plugin '%s'",
mm_dbg ("(%s): probe requested by plugin '%s'",
g_udev_device_get_name (port),
mm_plugin_get_name (MM_PLUGIN (task_priv->plugin)));
mm_serial_port_flash (MM_SERIAL_PORT (task_priv->probe_port), 100, TRUE, flash_done, task);

View File

@@ -19,7 +19,7 @@
#include <string.h>
#include "mm-port.h"
#include "mm-options.h"
#include "mm-log.h"
G_DEFINE_TYPE (MMPort, mm_port, G_TYPE_OBJECT)
@@ -161,17 +161,11 @@ mm_port_set_connected (MMPort *self, gboolean connected)
if (priv->connected != connected) {
priv->connected = connected;
g_object_notify (G_OBJECT (self), MM_PORT_CONNECTED);
if (mm_options_debug()) {
GTimeVal tv;
g_get_current_time (&tv);
g_debug ("<%ld.%ld> (%s): port now %s",
tv.tv_sec,
tv.tv_usec,
mm_dbg ("(%s): port now %s",
priv->device,
connected ? "connected" : "disconnected");
}
}
}
/*****************************************************************************/

View File

@@ -21,6 +21,7 @@
#include "mm-marshal.h"
#include "mm-properties-changed-signal.h"
#include "mm-properties-changed-glue.h"
#include "mm-log.h"
#define DBUS_TYPE_G_MAP_OF_VARIANT (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE))
#define DBUS_TYPE_G_ARRAY_OF_STRING (dbus_g_type_get_collection ("GPtrArray", G_TYPE_STRING))
@@ -150,7 +151,7 @@ properties_changed (gpointer data)
{
char buf[2048] = { 0, };
g_hash_table_foreach (props, add_to_string, &buf);
g_message ("%s: %s -> (%s) %s", __func__,
mm_dbg ("%s: %s -> (%s) %s", __func__,
G_OBJECT_TYPE_NAME (object),
interface,
buf);

View File

@@ -21,9 +21,9 @@
#include "mm-qcdm-serial-port.h"
#include "mm-errors.h"
#include "mm-options.h"
#include "libqcdm/src/com.h"
#include "libqcdm/src/utils.h"
#include "mm-log.h"
G_DEFINE_TYPE (MMQcdmSerialPort, mm_qcdm_serial_port, MM_TYPE_SERIAL_PORT)
@@ -182,7 +182,6 @@ debug_log (MMSerialPort *port, const char *prefix, const char *buf, gsize len)
{
static GString *debug = NULL;
const char *s = buf;
GTimeVal tv;
if (!debug)
debug = g_string_sized_new (512);
@@ -192,12 +191,7 @@ debug_log (MMSerialPort *port, const char *prefix, const char *buf, gsize len)
while (len--)
g_string_append_printf (debug, " %02x", (guint8) (*s++ & 0xFF));
g_get_current_time (&tv);
g_debug ("<%ld.%ld> (%s): %s",
tv.tv_sec,
tv.tv_usec,
mm_port_get_device (MM_PORT (port)),
debug->str);
mm_dbg ("(%s): %s", mm_port_get_device (MM_PORT (port)), debug->str);
g_string_truncate (debug, 0);
}

View File

@@ -19,6 +19,7 @@
#include "mm-serial-parsers.h"
#include "mm-errors.h"
#include "mm-log.h"
/* Clean up the response by removing control characters like <CR><LF> etc */
static void
@@ -174,7 +175,7 @@ mm_serial_parser_v0_parse (gpointer data,
response_clean (response);
if (local_error) {
g_debug ("Got failure code %d: %s", local_error->code, local_error->message);
mm_dbg ("Got failure code %d: %s", local_error->code, local_error->message);
g_propagate_error (error, local_error);
}
@@ -336,7 +337,7 @@ done:
response_clean (response);
if (local_error) {
g_debug ("Got failure code %d: %s", local_error->code, local_error->message);
mm_dbg ("Got failure code %d: %s", local_error->code, local_error->message);
g_propagate_error (error, local_error);
}

View File

@@ -30,7 +30,7 @@
#include "mm-serial-port.h"
#include "mm-errors.h"
#include "mm-options.h"
#include "mm-log.h"
static gboolean mm_serial_port_queue_process (gpointer data);
@@ -152,8 +152,8 @@ mm_serial_port_print_config (MMSerialPort *port, const char *detail)
return;
}
g_message ("*** %s (%s): (%s) baud rate: %d (%s)",
__func__, detail, mm_port_get_device (MM_PORT (port)),
mm_info ("(%s): (%s) baud rate: %d (%s)",
detail, mm_port_get_device (MM_PORT (port)),
stbuf.c_cflag & CBAUD,
baud_to_string (stbuf.c_cflag & CBAUD));
}
@@ -350,7 +350,7 @@ serial_debug (MMSerialPort *self, const char *prefix, const char *buf, gsize len
{
g_return_if_fail (len > 0);
if (mm_options_debug () && MM_SERIAL_PORT_GET_CLASS (self)->debug_log)
if (MM_SERIAL_PORT_GET_CLASS (self)->debug_log)
MM_SERIAL_PORT_GET_CLASS (self)->debug_log (self, prefix, buf, len);
}
@@ -686,7 +686,6 @@ mm_serial_port_open (MMSerialPort *self, GError **error)
MMSerialPortPrivate *priv;
char *devfile;
const char *device;
GTimeVal tv;
struct serial_struct sinfo;
g_return_val_if_fail (MM_IS_SERIAL_PORT (self), FALSE);
@@ -700,12 +699,7 @@ mm_serial_port_open (MMSerialPort *self, GError **error)
goto success;
}
if (mm_options_debug ()) {
g_get_current_time (&tv);
g_debug ("<%ld.%ld> (%s) opening serial port...",
tv.tv_sec, tv.tv_usec, device);
} else
g_message ("(%s) opening serial port...", device);
mm_info ("(%s) opening serial port...", device);
/* Only open a new file descriptor if we weren't given one already */
if (priv->fd < 0) {
@@ -767,11 +761,7 @@ mm_serial_port_open (MMSerialPort *self, GError **error)
success:
priv->open_count++;
if (mm_options_debug ()) {
g_get_current_time (&tv);
g_debug ("<%ld.%ld> (%s) device open count is %d (open)",
tv.tv_sec, tv.tv_usec, device, priv->open_count);
}
mm_dbg ("(%s) device open count is %d (open)", device, priv->open_count);
return TRUE;
error:
@@ -794,7 +784,6 @@ mm_serial_port_close (MMSerialPort *self)
{
MMSerialPortPrivate *priv;
const char *device;
GTimeVal tv;
int i;
g_return_if_fail (MM_IS_SERIAL_PORT (self));
@@ -806,11 +795,7 @@ mm_serial_port_close (MMSerialPort *self)
priv->open_count--;
if (mm_options_debug ()) {
g_get_current_time (&tv);
g_debug ("<%ld.%ld> (%s) device open count is %d (close)",
tv.tv_sec, tv.tv_usec, device, priv->open_count);
}
mm_dbg ("(%s) device open count is %d (close)", device, priv->open_count);
if (priv->open_count > 0)
return;
@@ -823,12 +808,7 @@ mm_serial_port_close (MMSerialPort *self)
if (priv->fd >= 0) {
GTimeVal tv_start, tv_end;
g_get_current_time (&tv_start);
if (mm_options_debug ()) {
g_debug ("<%ld.%ld> (%s) closing serial port...",
tv_start.tv_sec, tv_start.tv_usec, device);
} else
g_message ("(%s) closing serial port...", device);
mm_info ("(%s) closing serial port...", device);
mm_port_set_connected (MM_PORT (self), FALSE);
@@ -842,16 +822,16 @@ mm_serial_port_close (MMSerialPort *self)
mm_serial_port_flash_cancel (self);
g_get_current_time (&tv_start);
tcsetattr (priv->fd, TCSANOW, &priv->old_t);
tcflush (priv->fd, TCIOFLUSH);
close (priv->fd);
priv->fd = -1;
g_get_current_time (&tv_end);
if (mm_options_debug ()) {
g_debug ("<%ld.%ld> (%s) serial port closed",
tv_end.tv_sec, tv_end.tv_usec, device);
}
mm_info ("(%s) serial port closed", device);
/* Some ports don't respond to data and when close is called
* the serial layer waits up to 30 second (closing_wait) for
@@ -859,7 +839,7 @@ mm_serial_port_close (MMSerialPort *self)
* Log that. See GNOME bug #630670 for more details.
*/
if (tv_end.tv_sec - tv_start.tv_sec > 20)
g_warning ("(%s): close blocked by driver for more than 20 seconds!", device);
mm_warn ("(%s): close blocked by driver for more than 20 seconds!", device);
}
/* Clear the command queue */

View File

@@ -17,6 +17,7 @@
#include <string.h>
#include "mm-modem-helpers.h"
#include "mm-log.h"
typedef struct {
GPtrArray *solicited_creg;
@@ -1079,8 +1080,7 @@ test_devid_item (void *f, gpointer d)
item->gsn,
item->revision,
item->model,
item->manf,
FALSE);
item->manf);
g_assert (devid);
if (strcmp (devid, item->devid))
g_message ("%s", devid);
@@ -1178,6 +1178,15 @@ test_data_free (TestData *data)
g_free (data);
}
void
_mm_log (const char *loc,
const char *func,
guint32 level,
const char *fmt,
...)
{
/* Dummy log function */
}
#if GLIB_CHECK_VERSION(2,25,12)
typedef GTestFixtureFunc TCFunc;

View File

@@ -31,6 +31,7 @@
#include "libqcdm/src/commands.h"
#include "libqcdm/src/utils.h"
#include "libqcdm/src/com.h"
#include "mm-log.h"
typedef struct {
int master;
@@ -449,10 +450,14 @@ typedef void (*TCFunc)(void);
#define TESTCASE(t, d) g_test_create_case (#t, 0, d, NULL, (TCFunc) t, NULL)
#define TESTCASE_PTY(t, d) g_test_create_case (#t, sizeof (*d), d, (TCFunc) test_pty_create, (TCFunc) t, (TCFunc) test_pty_cleanup)
gboolean mm_options_debug (void);
gboolean mm_options_debug (void)
void
_mm_log (const char *loc,
const char *func,
guint32 level,
const char *fmt,
...)
{
return g_test_verbose ();
/* Dummy log function */
}
int main (int argc, char **argv)