summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am1
-rw-r--r--src/dkp-daemon.c49
-rw-r--r--src/dkp-debug.c240
-rw-r--r--src/dkp-debug.h80
-rw-r--r--src/dkp-device.c12
-rw-r--r--src/dkp-enum.c7
-rw-r--r--src/dkp-source.c23
-rw-r--r--src/main.c44
-rw-r--r--src/sysfs-utils.c10
9 files changed, 396 insertions, 70 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 0d31644..834d250 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -42,6 +42,7 @@ devkit_power_daemon_SOURCES = \
dkp-device.h dkp-device.c \
dkp-source.h dkp-source.c \
dkp-enum.h dkp-enum.c \
+ dkp-debug.h dkp-debug.c \
sysfs-utils.h sysfs-utils.c \
main.c \
$(BUILT_SOURCES)
diff --git a/src/dkp-daemon.c b/src/dkp-daemon.c
index 8e1a0a9..613dec2 100644
--- a/src/dkp-daemon.c
+++ b/src/dkp-daemon.c
@@ -31,6 +31,7 @@
#include <dbus/dbus-glib-lowlevel.h>
#include <devkit-gobject.h>
+#include "dkp-debug.h"
#include "dkp-daemon.h"
#include "dkp-device.h"
@@ -290,7 +291,7 @@ static DBusHandlerResult
gpk_daemon_dbus_filter (DBusConnection *connection, DBusMessage *message, void *user_data)
{
DkpDaemon *daemon = DKP_DAEMON (user_data);
- const char *interface;
+ const gchar *interface;
interface = dbus_message_get_interface (message);
@@ -318,19 +319,19 @@ static void
gpk_daemon_device_changed (DkpDaemon *daemon, DevkitDevice *d, gboolean synthesized)
{
DkpDevice *device;
- const char *native_path;
+ const gchar *native_path;
native_path = devkit_device_get_native_path (d);
device = g_hash_table_lookup (daemon->priv->map_native_path_to_device, native_path);
if (device != NULL) {
if (!dkp_device_changed (device, d, synthesized)) {
- g_print ("changed triggered remove on %s\n", native_path);
+ dkp_debug ("changed triggered remove on %s", native_path);
gpk_daemon_device_remove (daemon, d);
} else {
- g_print ("changed %s\n", native_path);
+ dkp_debug ("changed %s", native_path);
}
} else {
- g_print ("treating change event as add on %s\n", native_path);
+ dkp_debug ("treating change event as add on %s", native_path);
gpk_daemon_device_add (daemon, d, TRUE);
}
}
@@ -342,7 +343,7 @@ static gboolean
gpk_daemon_device_went_away_remove_cb (gpointer key, gpointer value, gpointer user_data)
{
if (value == user_data) {
- g_print ("removed %s\n", (char *) key);
+ dkp_debug ("removed %s", (char *) key);
return TRUE;
}
return FALSE;
@@ -368,13 +369,13 @@ static void
gpk_daemon_device_add (DkpDaemon *daemon, DevkitDevice *d, gboolean emit_event)
{
DkpDevice *device;
- const char *native_path;
+ const gchar *native_path;
native_path = devkit_device_get_native_path (d);
device = g_hash_table_lookup (daemon->priv->map_native_path_to_device, native_path);
if (device != NULL) {
/* we already have the device; treat as change event */
- g_print ("treating add event as change event on %s\n", native_path);
+ dkp_debug ("treating add event as change event on %s", native_path);
gpk_daemon_device_changed (daemon, d, FALSE);
} else {
device = dkp_device_new (daemon, d);
@@ -388,13 +389,13 @@ gpk_daemon_device_add (DkpDaemon *daemon, DevkitDevice *d, gboolean emit_event)
g_hash_table_insert (daemon->priv->map_native_path_to_device,
g_strdup (native_path),
device);
- g_print ("added %s\n", native_path);
+ dkp_debug ("added %s", native_path);
if (emit_event) {
g_signal_emit (daemon, signals[DEVICE_ADDED_SIGNAL], 0,
dkp_device_get_object_path (device));
}
} else {
- g_print ("ignoring add event on %s\n", native_path);
+ dkp_debug ("ignoring add event on %s", native_path);
}
}
}
@@ -406,12 +407,12 @@ static void
gpk_daemon_device_remove (DkpDaemon *daemon, DevkitDevice *d)
{
DkpDevice *device;
- const char *native_path;
+ const gchar *native_path;
native_path = devkit_device_get_native_path (d);
device = g_hash_table_lookup (daemon->priv->map_native_path_to_device, native_path);
if (device == NULL) {
- g_print ("ignoring remove event on %s\n", native_path);
+ dkp_debug ("ignoring remove event on %s", native_path);
} else {
dkp_device_removed (device);
g_signal_emit (daemon, signals[DEVICE_REMOVED_SIGNAL], 0,
@@ -442,7 +443,7 @@ gpk_daemon_device_event_signal_handler (DevkitClient *client,
} else if (strcmp (action, "change") == 0) {
gpk_daemon_device_changed (daemon, device, FALSE);
} else {
- g_warning ("unhandled action '%s' on %s", action, devkit_device_get_native_path (device));
+ dkp_warning ("unhandled action '%s' on %s", action, devkit_device_get_native_path (device));
}
}
@@ -455,7 +456,7 @@ gpk_daemon_register_power_daemon (DkpDaemon *daemon)
DBusConnection *connection;
DBusError dbus_error;
GError *error = NULL;
- const char *subsystems[] = {"power_supply", NULL};
+ const gchar *subsystems[] = {"power_supply", NULL};
daemon->priv->pk_context = polkit_context_new ();
polkit_context_set_io_watch_functions (daemon->priv->pk_context, pk_io_add_watch, pk_io_remove_watch);
@@ -504,7 +505,7 @@ gpk_daemon_register_power_daemon (DkpDaemon *daemon)
&dbus_error);
if (dbus_error_is_set (&dbus_error)) {
- g_warning ("Cannot add match rule: %s: %s", dbus_error.name, dbus_error.message);
+ dkp_warning ("Cannot add match rule: %s: %s", dbus_error.name, dbus_error.message);
dbus_error_free (&dbus_error);
goto error;
}
@@ -515,7 +516,7 @@ gpk_daemon_register_power_daemon (DkpDaemon *daemon)
&dbus_error);
if (dbus_error_is_set (&dbus_error)) {
- g_warning ("Cannot add match rule: %s: %s", dbus_error.name, dbus_error.message);
+ dkp_warning ("Cannot add match rule: %s: %s", dbus_error.name, dbus_error.message);
dbus_error_free (&dbus_error);
goto error;
}
@@ -524,14 +525,14 @@ gpk_daemon_register_power_daemon (DkpDaemon *daemon)
gpk_daemon_dbus_filter,
daemon,
NULL)) {
- g_warning ("Cannot add D-Bus filter: %s: %s", dbus_error.name, dbus_error.message);
+ dkp_warning ("Cannot add D-Bus filter: %s: %s", dbus_error.name, dbus_error.message);
goto error;
}
/* connect to the DeviceKit daemon */
daemon->priv->devkit_client = devkit_client_new (subsystems);
if (!devkit_client_connect (daemon->priv->devkit_client, &error)) {
- g_warning ("Couldn't open connection to DeviceKit daemon: %s", error->message);
+ dkp_warning ("Couldn't open connection to DeviceKit daemon: %s", error->message);
g_error_free (error);
goto error;
}
@@ -553,7 +554,7 @@ dkp_daemon_new (void)
GError *error = NULL;
GList *devices;
GList *l;
- const char *subsystems[] = {"power_supply", NULL};
+ const gchar *subsystems[] = {"power_supply", NULL};
daemon = DKP_DAEMON (g_object_new (DKP_SOURCE_TYPE_DAEMON, NULL));
@@ -566,7 +567,7 @@ dkp_daemon_new (void)
subsystems,
&error);
if (error != NULL) {
- g_warning ("Cannot enumerate devices: %s", error->message);
+ dkp_warning ("Cannot enumerate devices: %s", error->message);
g_error_free (error);
g_object_unref (daemon);
return NULL;
@@ -587,7 +588,7 @@ dkp_daemon_new (void)
PolKitCaller *
dkp_daemon_local_get_caller_for_context (DkpDaemon *daemon, DBusGMethodInvocation *context)
{
- const char *sender;
+ const gchar *sender;
GError *error;
DBusError dbus_error;
PolKitCaller *pk_caller;
@@ -617,14 +618,12 @@ dkp_daemon_local_get_caller_for_context (DkpDaemon *daemon, DBusGMethodInvocatio
gboolean
dkp_daemon_local_check_auth (DkpDaemon *daemon, PolKitCaller *pk_caller, const char *action_id, DBusGMethodInvocation *context)
{
- gboolean ret;
+ gboolean ret = FALSE;
GError *error;
DBusError d_error;
PolKitAction *pk_action;
PolKitResult pk_result;
- ret = FALSE;
-
pk_action = polkit_action_new ();
polkit_action_set_action_id (pk_action, action_id);
pk_result = polkit_context_is_caller_authorized (daemon->priv->pk_context, pk_action, pk_caller, TRUE, NULL);
@@ -654,7 +653,7 @@ gpk_daemon_throw_error (DBusGMethodInvocation *context, int error_code, const ch
{
GError *error;
va_list args;
- char *message;
+ gchar *message;
va_start (args, format);
message = g_strdup_vprintf (format, args);
diff --git a/src/dkp-debug.c b/src/dkp-debug.c
new file mode 100644
index 0000000..bf3f12e
--- /dev/null
+++ b/src/dkp-debug.c
@@ -0,0 +1,240 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007-2008 Richard Hughes <richard@hughsie.com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/**
+ * SECTION:dkp-debug
+ * @short_description: Debugging functions
+ *
+ * This file contains functions that can be used for debugging.
+ */
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <glib/gprintf.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <time.h>
+#include <execinfo.h>
+
+#include "dkp-debug.h"
+
+#define CONSOLE_RESET 0
+#define CONSOLE_BLACK 30
+#define CONSOLE_RED 31
+#define CONSOLE_GREEN 32
+#define CONSOLE_YELLOW 33
+#define CONSOLE_BLUE 34
+#define CONSOLE_MAGENTA 35
+#define CONSOLE_CYAN 36
+#define CONSOLE_WHITE 37
+
+#define PK_LOG_FILE PK_LOG_DIR "/PackageKit"
+
+static gboolean do_verbose = FALSE; /* if we should print out debugging */
+static gboolean is_console = FALSE;
+
+/**
+ * dkp_set_console_mode:
+ **/
+static void
+dkp_set_console_mode (guint console_code)
+{
+ gchar command[13];
+
+ /* don't put extra commands into logs */
+ if (!is_console) {
+ return;
+ }
+ /* Command is the control command to the terminal */
+ g_snprintf (command, 13, "%c[%dm", 0x1B, console_code);
+ printf ("%s", command);
+}
+
+/**
+ * dkp_debug_backtrace:
+ **/
+void
+dkp_debug_backtrace (void)
+{
+ void *call_stack[512];
+ int call_stack_size;
+ char **symbols;
+ int i = 1;
+
+ call_stack_size = backtrace (call_stack, G_N_ELEMENTS (call_stack));
+ symbols = backtrace_symbols (call_stack, call_stack_size);
+ if (symbols != NULL) {
+ dkp_set_console_mode (CONSOLE_RED);
+ g_print ("Traceback:\n");
+ while (i < call_stack_size) {
+ g_print ("\t%s\n", symbols[i]);
+ i++;
+ }
+ dkp_set_console_mode (CONSOLE_RESET);
+ free (symbols);
+ }
+}
+
+/**
+ * dkp_print_line:
+ **/
+static void
+dkp_print_line (const gchar *func, const gchar *file, const int line, const gchar *buffer, guint color)
+{
+ gchar *str_time;
+ gchar *header;
+ time_t the_time;
+ GThread *thread;
+
+ time (&the_time);
+ str_time = g_new0 (gchar, 255);
+ strftime (str_time, 254, "%H:%M:%S", localtime (&the_time));
+ thread = g_thread_self ();
+
+ /* generate header text */
+ header = g_strdup_printf ("TI:%s\tTH:%p\tFI:%s\tFN:%s,%d", str_time, thread, file, func, line);
+ g_free (str_time);
+
+ /* always in light green */
+ dkp_set_console_mode (CONSOLE_GREEN);
+ printf ("%s\n", header);
+
+ /* different colours according to the severity */
+ dkp_set_console_mode (color);
+ printf (" - %s\n", buffer);
+ dkp_set_console_mode (CONSOLE_RESET);
+
+ /* flush this output, as we need to debug */
+ fflush (stdout);
+
+ g_free (header);
+}
+
+/**
+ * dkp_debug_real:
+ **/
+void
+dkp_debug_real (const gchar *func, const gchar *file, const int line, const gchar *format, ...)
+{
+ va_list args;
+ gchar *buffer = NULL;
+
+ if (do_verbose == FALSE) {
+ return;
+ }
+
+ va_start (args, format);
+ g_vasprintf (&buffer, format, args);
+ va_end (args);
+
+ dkp_print_line (func, file, line, buffer, CONSOLE_BLUE);
+
+ g_free(buffer);
+}
+
+/**
+ * dkp_warning_real:
+ **/
+void
+dkp_warning_real (const gchar *func, const gchar *file, const int line, const gchar *format, ...)
+{
+ va_list args;
+ gchar *buffer = NULL;
+
+ if (do_verbose == FALSE) {
+ return;
+ }
+
+ va_start (args, format);
+ g_vasprintf (&buffer, format, args);
+ va_end (args);
+
+ /* do extra stuff for a warning */
+ if (!is_console) {
+ printf ("*** WARNING ***\n");
+ }
+ dkp_print_line (func, file, line, buffer, CONSOLE_RED);
+
+ g_free(buffer);
+
+ /* we want to fix this! */
+ dkp_debug_backtrace ();
+}
+
+/**
+ * dkp_error_real:
+ **/
+void
+dkp_error_real (const gchar *func, const gchar *file, const int line, const gchar *format, ...)
+{
+ va_list args;
+ gchar *buffer = NULL;
+
+ va_start (args, format);
+ g_vasprintf (&buffer, format, args);
+ va_end (args);
+
+ /* do extra stuff for a warning */
+ if (!is_console) {
+ printf ("*** ERROR ***\n");
+ }
+ dkp_print_line (func, file, line, buffer, CONSOLE_RED);
+ g_free(buffer);
+
+ /* we want to fix this! */
+ dkp_debug_backtrace ();
+
+ exit (1);
+}
+
+/**
+ * dkp_debug_enabled:
+ *
+ * Returns: TRUE if we have debugging enabled
+ **/
+gboolean
+dkp_debug_enabled (void)
+{
+ return do_verbose;
+}
+
+/**
+ * dkp_debug_init:
+ * @debug: If we should print out verbose debugging
+ **/
+void
+dkp_debug_init (gboolean debug)
+{
+ do_verbose = debug;
+ /* check if we are on console */
+ if (isatty (fileno (stdout)) == 1) {
+ is_console = TRUE;
+ }
+ dkp_debug ("Verbose debugging %i (on console %i)", do_verbose, is_console);
+}
+
diff --git a/src/dkp-debug.h b/src/dkp-debug.h
new file mode 100644
index 0000000..8f05c01
--- /dev/null
+++ b/src/dkp-debug.h
@@ -0,0 +1,80 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007-2008 Richard Hughes <richard@hughsie.com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __PK_DEBUG_H
+#define __PK_DEBUG_H
+
+#include <stdarg.h>
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+/**
+ * dkp_debug:
+ *
+ * Non critical debugging
+ */
+#define dkp_debug(...) dkp_debug_real (__func__, __FILE__, __LINE__, __VA_ARGS__)
+
+/**
+ * dkp_warning:
+ *
+ * Important debugging
+ */
+#define dkp_warning(...) dkp_warning_real (__func__, __FILE__, __LINE__, __VA_ARGS__)
+
+/**
+ * dkp_error:
+ *
+ * Critical debugging, with exit
+ */
+#define dkp_error(...) dkp_error_real (__func__, __FILE__, __LINE__, __VA_ARGS__)
+
+#elif defined(__GNUC__) && __GNUC__ >= 3
+#define dkp_debug(...) dkp_debug_real (__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
+#define dkp_warning(...) dkp_warning_real (__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
+#define dkp_error(...) dkp_error_real (__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
+#else
+#define dkp_debug(...)
+#define dkp_warning(...)
+#define dkp_error(...)
+#endif
+
+void dkp_debug_init (gboolean debug);
+gboolean dkp_debug_enabled (void);
+void dkp_debug_backtrace (void);
+void dkp_debug_real (const gchar *func,
+ const gchar *file,
+ int line,
+ const gchar *format, ...) __attribute__((format (printf,4,5)));
+void dkp_warning_real (const gchar *func,
+ const gchar *file,
+ int line,
+ const gchar *format, ...) __attribute__((format (printf,4,5)));
+void dkp_error_real (const gchar *func,
+ const gchar *file,
+ int line,
+ const gchar *format, ...) __attribute__((format (printf,4,5)));
+
+G_END_DECLS
+
+#endif /* __PK_DEBUG_H */
diff --git a/src/dkp-device.c b/src/dkp-device.c
index 02ac719..b8678d2 100644
--- a/src/dkp-device.c
+++ b/src/dkp-device.c
@@ -34,6 +34,7 @@
#include <polkit-dbus/polkit-dbus.h>
#include "sysfs-utils.h"
+#include "dkp-debug.h"
#include "dkp-device.h"
#include "dkp-source.h"
@@ -76,15 +77,20 @@ dkp_device_removed (DkpDevice *device)
DkpDevice *
dkp_device_new (DkpDaemon *daemon, DevkitDevice *d)
{
- const char *subsys;
+ const gchar *subsys;
DkpDevice *device;
+ gchar *id;
device = NULL;
subsys = devkit_device_get_subsystem (d);
- if (strcmp (subsys, "power_supply") == 0)
+ if (strcmp (subsys, "power_supply") == 0) {
device = DKP_DEVICE (dkp_source_new (daemon, d));
-
+ id = dkp_source_get_id (DKP_SOURCE (device));
+ if (id != NULL)
+ dkp_debug ("Using device profile id: %s", id);
+ g_free (id);
+ }
return device;
}
diff --git a/src/dkp-enum.c b/src/dkp-enum.c
index e6aa4a2..4eb7262 100644
--- a/src/dkp-enum.c
+++ b/src/dkp-enum.c
@@ -21,6 +21,7 @@
#include <glib.h>
#include <strings.h>
+#include "dkp-debug.h"
#include "dkp-enum.h"
/**
@@ -29,7 +30,7 @@
const char *
dkp_source_type_to_text (DkpSourceType type_enum)
{
- const char *type = NULL;
+ const gchar *type = NULL;
switch (type_enum) {
case DKP_SOURCE_TYPE_LINE_POWER:
type = "line-power";
@@ -65,7 +66,7 @@ dkp_source_type_to_text (DkpSourceType type_enum)
const char *
dkp_source_state_to_text (DkpSourceState state_enum)
{
- const char *state = NULL;
+ const gchar *state = NULL;
switch (state_enum) {
case DKP_SOURCE_STATE_CHARGING:
state = "charging";
@@ -92,7 +93,7 @@ dkp_source_state_to_text (DkpSourceState state_enum)
const char *
dkp_source_technology_to_text (DkpSourceTechnology technology_enum)
{
- const char *technology = NULL;
+ const gchar *technology = NULL;
switch (technology_enum) {
case DKP_SOURCE_TECHNOLGY_LITHIUM_ION:
technology = "lithium-ion";
diff --git a/src/dkp-source.c b/src/dkp-source.c
index 002f725..9d1ef91 100644
--- a/src/dkp-source.c
+++ b/src/dkp-source.c
@@ -36,6 +36,7 @@
#include <polkit-dbus/polkit-dbus.h>
#include "sysfs-utils.h"
+#include "dkp-debug.h"
#include "dkp-enum.h"
#include "dkp-source.h"
#include "dkp-marshal.h"
@@ -374,8 +375,8 @@ dkp_source_finalize (GObject *object)
static char *
dkp_source_compute_object_path_from_basename (const char *native_path_basename)
{
- char *basename;
- char *object_path;
+ gchar *basename;
+ gchar *object_path;
unsigned int n;
/* TODO: need to be more thorough with making proper object
@@ -395,11 +396,11 @@ dkp_source_compute_object_path_from_basename (const char *native_path_basename)
/**
* dkp_source_compute_object_path:
**/
-static char *
+static gchar *
dkp_source_compute_object_path (const char *native_path)
{
- char *basename;
- char *object_path;
+ gchar *basename;
+ gchar *object_path;
basename = g_path_get_basename (native_path);
object_path = dkp_source_compute_object_path_from_basename (basename);
@@ -447,7 +448,7 @@ DkpSource *
dkp_source_new (DkpDaemon *daemon, DevkitDevice *d)
{
DkpSource *source;
- const char *native_path;
+ const gchar *native_path;
source = NULL;
native_path = devkit_device_get_native_path (d);
@@ -486,7 +487,7 @@ out:
static void
dkp_source_emit_changed (DkpSource *source)
{
- g_print ("emitting changed on %s\n", source->priv->native_path);
+ dkp_debug ("emitting changed on %s", source->priv->native_path);
g_signal_emit_by_name (source->priv->daemon,
"device-changed",
source->priv->object_path,
@@ -669,7 +670,7 @@ dkp_source_calculate_battery_rate (DkpSource *source)
static gboolean
dkp_source_update_battery (DkpSource *source)
{
- char *status;
+ gchar *status;
gboolean is_charging;
gboolean is_discharging;
DkpSourceState battery_state;
@@ -686,7 +687,7 @@ dkp_source_update_battery (DkpSource *source)
/* initial values */
if (!source->priv->has_coldplug_values) {
- char *technology_native;
+ gchar *technology_native;
/* when we add via sysfs power_supply class then we know this is true */
source->priv->power_supply = TRUE;
@@ -823,7 +824,7 @@ dkp_source_update_battery (DkpSource *source)
static gboolean
dkp_source_poll_battery (DkpSource *source)
{
- g_warning ("No updates on source %s for 30 seconds; forcing update", source->priv->native_path);
+ dkp_debug ("No updates on source %s for 30 seconds; forcing update", source->priv->native_path);
source->priv->poll_timer_id = 0;
dkp_source_update (source);
dkp_source_emit_changed (source);
@@ -850,9 +851,7 @@ dkp_source_update (DkpSource *source)
ret = dkp_source_update_line_power (source);
break;
case DKP_SOURCE_TYPE_BATTERY:
-
ret = dkp_source_update_battery (source);
-
/* Seems that we don't get change uevents from the
* kernel on some BIOS types; set up a timer to poll
*
diff --git a/src/main.c b/src/main.c
index 3f50629..8a73d95 100644
--- a/src/main.c
+++ b/src/main.c
@@ -38,6 +38,7 @@
#include <dbus/dbus-glib-lowlevel.h>
#include <devkit-gobject.h>
+#include "dkp-debug.h"
#include "dkp-daemon.h"
#define NAME_TO_CLAIM "org.freedesktop.DeviceKit.Power"
@@ -70,20 +71,20 @@ main_acquire_name_on_proxy (DBusGProxy *bus_proxy)
G_TYPE_INVALID);
if (!res) {
if (error != NULL) {
- g_warning ("Failed to acquire %s: %s", NAME_TO_CLAIM, error->message);
+ dkp_warning ("Failed to acquire %s: %s", NAME_TO_CLAIM, error->message);
g_error_free (error);
} else {
- g_warning ("Failed to acquire %s", NAME_TO_CLAIM);
+ dkp_warning ("Failed to acquire %s", NAME_TO_CLAIM);
}
goto out;
}
if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
if (error != NULL) {
- g_warning ("Failed to acquire %s: %s", NAME_TO_CLAIM, error->message);
+ dkp_warning ("Failed to acquire %s: %s", NAME_TO_CLAIM, error->message);
g_error_free (error);
} else {
- g_warning ("Failed to acquire %s", NAME_TO_CLAIM);
+ dkp_warning ("Failed to acquire %s", NAME_TO_CLAIM);
}
goto out;
}
@@ -100,58 +101,57 @@ main_acquire_name_on_proxy (DBusGProxy *bus_proxy)
int
main (int argc, char **argv)
{
- GError *error;
- GMainLoop *loop;
+ GError *error;
+ GMainLoop *loop;
DkpDaemon *power_daemon;
GOptionContext *context;
- DBusGProxy *bus_proxy;
+ DBusGProxy *bus_proxy;
DBusGConnection *bus;
- int ret;
- static GOptionEntry entries [] = {
+ gboolean verbose = FALSE;
+ int ret = 1;
+
+ const GOptionEntry entries[] = {
+ { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
+ _("Show extra debugging information"), NULL },
{ NULL }
};
- ret = 1;
-
g_type_init ();
context = g_option_context_new ("DeviceKit Power Daemon");
g_option_context_add_main_entries (context, entries, NULL);
g_option_context_parse (context, &argc, &argv, NULL);
g_option_context_free (context);
+ dkp_debug_init (verbose);
error = NULL;
bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
if (bus == NULL) {
- g_warning ("Couldn't connect to system bus: %s", error->message);
+ dkp_warning ("Couldn't connect to system bus: %s", error->message);
g_error_free (error);
goto out;
}
- bus_proxy = dbus_g_proxy_new_for_name (bus,
- DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS);
+ bus_proxy = dbus_g_proxy_new_for_name (bus, DBUS_SERVICE_DBUS,
+ DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
if (bus_proxy == NULL) {
- g_warning ("Could not construct bus_proxy object; bailing out");
+ dkp_warning ("Could not construct bus_proxy object; bailing out");
goto out;
}
if (!main_acquire_name_on_proxy (bus_proxy) ) {
- g_warning ("Could not acquire name; bailing out");
+ dkp_warning ("Could not acquire name; bailing out");
goto out;
}
- g_debug ("Starting devkit-power-daemon version %s", VERSION);
+ dkp_debug ("Starting devkit-power-daemon version %s", VERSION);
power_daemon = dkp_daemon_new ();
- if (power_daemon == NULL) {
+ if (power_daemon == NULL)
goto out;
- }
loop = g_main_loop_new (NULL, FALSE);
-
g_main_loop_run (loop);
g_object_unref (power_daemon);
diff --git a/src/sysfs-utils.c b/src/sysfs-utils.c
index 8a594f5..d9cb0f9 100644
--- a/src/sysfs-utils.c
+++ b/src/sysfs-utils.c
@@ -195,19 +195,19 @@ sysfs_resolve_link (const char *dir, const char *attribute)
full_path = g_build_filename (dir, attribute, NULL);
- //g_warning ("attribute='%s'", attribute);
- //g_warning ("full_path='%s'", full_path);
+ //dkp_warning ("attribute='%s'", attribute);
+ //dkp_warning ("full_path='%s'", full_path);
num = readlink (full_path, link_path, sizeof (link_path) - 1);
if (num != -1) {
char *absolute_path;
link_path[num] = '\0';
- //g_warning ("link_path='%s'", link_path);
+ //dkp_warning ("link_path='%s'", link_path);
absolute_path = g_build_filename (dir, link_path, NULL);
- //g_warning ("absolute_path='%s'", absolute_path);
+ //dkp_warning ("absolute_path='%s'", absolute_path);
if (realpath (absolute_path, resolved_path) != NULL) {
- //g_warning ("resolved_path='%s'", resolved_path);
+ //dkp_warning ("resolved_path='%s'", resolved_path);
found_it = TRUE;
}
g_free (absolute_path);