hal: Branch 'master'

Danny Kukawka dkukawka at kemper.freedesktop.org
Mon Aug 21 11:20:30 PDT 2006


 hald/Makefile.am                                |    4 
 hald/hald.c                                     |   37 ----
 hald/linux2/acpi.c                              |    1 
 hald/linux2/addons/Makefile.am                  |   57 +++----
 hald/linux2/addons/addon-acpi-buttons-toshiba.c |   23 +-
 hald/linux2/addons/addon-acpi.c                 |   32 +--
 hald/linux2/addons/addon-hid-ups.c              |    9 -
 hald/linux2/addons/addon-keyboard.c             |    6 
 hald/linux2/addons/addon-macbookpro-backlight.c |   29 +--
 hald/linux2/addons/addon-pmu.c                  |   15 -
 hald/linux2/addons/addon-storage.c              |   51 +++---
 hald/linux2/addons/addon-usb-csr.c              |   47 ++---
 hald/linux2/apm.c                               |    1 
 hald/linux2/ids.c                               |   69 +++-----
 hald/linux2/pmu.c                               |    1 
 hald/linux2/probing/Makefile.am                 |   16 -
 hald/linux2/probing/probe-input.c               |   27 +--
 hald/linux2/probing/probe-pc-floppy.c           |   16 -
 hald/linux2/probing/probe-printer.c             |   24 +-
 hald/linux2/probing/probe-serial.c              |   23 +-
 hald/linux2/probing/probe-smbios.c              |   15 -
 hald/linux2/probing/probe-storage.c             |   68 ++------
 hald/linux2/probing/probe-volume.c              |   84 +++++-----
 hald/linux2/probing/shared.h                    |  174 ---------------------
 hald/logger.c                                   |  106 ++++++++++---
 hald/logger.h                                   |    4 
 hald/util.c                                     |  170 +--------------------
 hald/util.h                                     |    5 
 hald/util_helper.c                              |  143 +++++++++++++++++
 hald/util_helper.h                              |   33 ++++
 hald/util_pm.c                                  |  194 ++++++++++++++++++++++++
 hald/util_pm.h                                  |   35 ++++
 32 files changed, 814 insertions(+), 705 deletions(-)

New commits:
diff-tree 9f92b65ab9398476afc53e70a2173de53f2b4495 (from 5c3da435c0e367266e9d7d5be28d72117bb77541)
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Mon Aug 21 20:16:07 2006 +0200

    remove shared.h for addons/prober and some little fixes
    
    This remove hald/linux2/probing/shared.h for better reuse of related
    functions and to avoid compiler warnings about defined but unused
    functions.
    
    Major changes:
    * removed shared.h and switched addons and prober to use with
      logger.[c,h] the same functions and format as the hal daemon.
    * split off powermanagement related code from util.c/h to a new file
      util_pm.[c,h].
    * added a new file util_helper.[c,h] to collect functions
      drop_privileges() and hal_set_proc_title*().
    * removed unused function strdup_valid_utf8() from probe-storage.c and
      updated hal_util_strdup_valid_utf8() to do the same as
      strdup_valid_utf8() before.
    * fixed compiler warning in ids.c (use now *_ids_free() functions
      instead of call free() directly without checks).
    * fixed compiler warning in addon-macbookpro-backlight.c (added '#if 0'
      around unused function)

diff --git a/hald/Makefile.am b/hald/Makefile.am
index a5827d5..b332390 100644
--- a/hald/Makefile.am
+++ b/hald/Makefile.am
@@ -40,6 +40,8 @@ BUILT_SOURCES =		\
 hald_SOURCES =                                                          \
 	hald_marshal.h			hald_marshal.c			\
 	util.h				util.c				\
+	util_helper.h			util_helper.c			\
+	util_pm.h			util_pm.c			\
 	hald_runner.h			hald_runner.c			\
 	device.h			device.c			\
 	device_info.h			device_info.c			\
@@ -48,7 +50,7 @@ hald_SOURCES =                          
 	hald_dbus.h			hald_dbus.c			\
 	logger.h			logger.c			\
 	osspec.h							\
-	property.h			property.c
+	property.h			property.c			
 
 hald_LDADD = @GLIB_LIBS@ @DBUS_LIBS@ -lm @EXPAT_LIB@ $(top_builddir)/hald/$(HALD_BACKEND)/libhald_$(HALD_BACKEND).la
 
diff --git a/hald/hald.c b/hald/hald.c
index b29efbe..f10c087 100644
--- a/hald/hald.c
+++ b/hald/hald.c
@@ -56,6 +56,7 @@
 #include "hald_dbus.h"
 #include "util.h"
 #include "hald_runner.h"
+#include "util_helper.h"
 
 static void delete_pid(void)
 {
@@ -248,40 +249,6 @@ dbus_bool_t hald_is_initialising;
 
 static int startup_daemonize_pipe[2];
 
-/** Drop all but necessary privileges from hald when it runs as root.  Set the
- *  running user id to HAL_USER and group to HAL_GROUP
- */
-static void
-drop_privileges ()
-{
-    struct passwd *pw = NULL;
-    struct group *gr = NULL;
-
-    /* determine user id */
-    pw = getpwnam (HAL_USER);
-    if (!pw)  {
-	HAL_ERROR (("drop_privileges: user " HAL_USER " does not exist"));
-	exit (-1);
-    }
-
-    /* determine primary group id */
-    gr = getgrnam (HAL_GROUP);
-    if(!gr) {
-	HAL_ERROR (("drop_privileges: group " HAL_GROUP " does not exist"));
-	exit (-1);
-    }
-
-    if( setgid (gr->gr_gid) ) {
-	HAL_ERROR (("drop_privileges: could not set group id"));
-	exit (-1);
-    }
-
-    if( setuid (pw->pw_uid)) {
-	HAL_ERROR (("drop_privileges: could not set user id"));
-	exit (-1);
-    }
-}
-
 
 /*--------------------------------------------------------------------------------------------------*/
 
@@ -565,7 +532,7 @@ main (int argc, char *argv[])
 		return 1;
 	}
 
-	drop_privileges();
+	drop_privileges(0);
 
 	/* initialize operating system specific parts */
 	osspec_init ();
diff --git a/hald/linux2/acpi.c b/hald/linux2/acpi.c
index 3751573..4274d77 100644
--- a/hald/linux2/acpi.c
+++ b/hald/linux2/acpi.c
@@ -31,6 +31,7 @@
 #include "../hald_dbus.h"
 #include "../logger.h"
 #include "../util.h"
+#include "../util_pm.h"
 
 #include "osspec_linux.h"
 
diff --git a/hald/linux2/addons/Makefile.am b/hald/linux2/addons/Makefile.am
index 33cdd9c..19c229d 100644
--- a/hald/linux2/addons/Makefile.am
+++ b/hald/linux2/addons/Makefile.am
@@ -5,51 +5,50 @@ INCLUDES = \
 	-DPACKAGE_BIN_DIR=\""$(bindir)"\" \
 	-DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
 	-DPACKAGE_LOCALSTATEDIR=\""$(localstatedir)"\" \
-	-I$(top_srcdir) \
-	@GLIB_CFLAGS@ @DBUS_CFLAGS@
+        -I$(top_srcdir) -I$(top_srcdir)/hald \
+        @GLIB_CFLAGS@ @DBUS_CFLAGS@
 
 if HALD_COMPILE_LINUX2
-libexec_PROGRAMS  = \
-	hald-addon-hid-ups \
-	hald-addon-acpi \
+libexec_PROGRAMS  = 			\
+	hald-addon-acpi 		\
 	hald-addon-acpi-buttons-toshiba \
-	hald-addon-storage \
-	hald-addon-keyboard \
-	hald-addon-pmu
+	hald-addon-hid-ups 		\
+	hald-addon-keyboard 		\
+	hald-addon-pmu			\
+	hald-addon-storage
 
-if HAVE_LIBUSB
-libexec_PROGRAMS += hald-addon-usb-csr
-endif
 if HAVE_LIBPCI
 libexec_PROGRAMS += hald-addon-macbookpro-backlight
 endif
+if HAVE_LIBUSB
+libexec_PROGRAMS += hald-addon-usb-csr
+endif
 endif
 
-hald_addon_hid_ups_SOURCES = addon-hid-ups.c
-hald_addon_hid_ups_LDADD = $(top_builddir)/libhal/libhal.la
-
-hald_addon_acpi_SOURCES = addon-acpi.c
+hald_addon_acpi_SOURCES = addon-acpi.c ../../logger.c ../../util_helper.c
 hald_addon_acpi_LDADD = $(top_builddir)/libhal/libhal.la
 
-hald_addon_pmu_SOURCES = addon-pmu.c
-hald_addon_pmu_LDADD = $(top_builddir)/libhal/libhal.la
-
-hald_addon_acpi_buttons_toshiba_SOURCES = addon-acpi-buttons-toshiba.c
+hald_addon_acpi_buttons_toshiba_SOURCES = addon-acpi-buttons-toshiba.c ../../logger.c ../../util_helper.c
 hald_addon_acpi_buttons_toshiba_LDADD = $(top_builddir)/libhal/libhal.la @GLIB_LIBS@
 
-hald_addon_storage_SOURCES = addon-storage.c
-hald_addon_storage_LDADD = $(top_builddir)/libhal/libhal.la
+hald_addon_hid_ups_SOURCES = addon-hid-ups.c ../../logger.c ../../util_helper.c
+hald_addon_hid_ups_LDADD = $(top_builddir)/libhal/libhal.la 
 
-hald_addon_keyboard_SOURCES = addon-keyboard.c
-hald_addon_keyboard_LDADD = $(top_builddir)/libhal/libhal.la
+hald_addon_keyboard_SOURCES = addon-keyboard.c ../../logger.c ../../util_helper.c
+hald_addon_keyboard_LDADD = $(top_builddir)/libhal/libhal.la 
 
-if HAVE_LIBUSB
-hald_addon_usb_csr_SOURCES = addon-usb-csr.c
-hald_addon_usb_csr_LDADD = $(top_builddir)/libhal/libhal.la -lusb @GLIB_LIBS@
+if HAVE_LIBPCI
+hald_addon_macbookpro_backlight_SOURCES = addon-macbookpro-backlight.c ../../logger.c
+hald_addon_macbookpro_backlight_LDADD = $(top_builddir)/libhal/libhal.la -lpci @GLIB_LIBS@
 endif
 
+hald_addon_pmu_SOURCES = addon-pmu.c ../../logger.c ../../util_helper.c
+hald_addon_pmu_LDADD = $(top_builddir)/libhal/libhal.la
 
-if HAVE_LIBPCI
-hald_addon_macbookpro_backlight_SOURCES = addon-macbookpro-backlight.c
-hald_addon_macbookpro_backlight_LDADD = $(top_builddir)/libhal/libhal.la -lpci @GLIB_LIBS@
+hald_addon_storage_SOURCES = addon-storage.c ../../logger.c ../../util_helper.c
+hald_addon_storage_LDADD = $(top_builddir)/libhal/libhal.la
+
+if HAVE_LIBUSB
+hald_addon_usb_csr_SOURCES = addon-usb-csr.c ../../logger.c ../../util_helper.c
+hald_addon_usb_csr_LDADD = $(top_builddir)/libhal/libhal.la -lusb @GLIB_LIBS@
 endif
diff --git a/hald/linux2/addons/addon-acpi-buttons-toshiba.c b/hald/linux2/addons/addon-acpi-buttons-toshiba.c
index 908cf4e..7252759 100644
--- a/hald/linux2/addons/addon-acpi-buttons-toshiba.c
+++ b/hald/linux2/addons/addon-acpi-buttons-toshiba.c
@@ -38,7 +38,7 @@
 #include <glib/gmain.h>
 
 #include "libhal/libhal.h"
-#include "../probing/shared.h"
+#include "../../logger.h"
 
 /** Toshiba ACPI key interface */
 #define TOSHIBA_ACPI_KEYS		"/proc/acpi/toshiba/keys"
@@ -57,7 +57,7 @@ toshiba_key_flush (void)
 	int value;
 	FILE *fp = fopen (TOSHIBA_ACPI_KEYS, "r+");
 	if (!fp) {
-		dbg ("Could not open %s!", TOSHIBA_ACPI_KEYS);
+		HAL_DEBUG (("Could not open %s!", TOSHIBA_ACPI_KEYS));
 		return;
 	}
 	while (hotkey_ready) {
@@ -65,7 +65,7 @@ toshiba_key_flush (void)
 		fclose (fp);
 		fp = fopen (TOSHIBA_ACPI_KEYS, "r+");
 		if (fscanf (fp, "hotkey_ready: %d\nhotkey: 0x%4x", &hotkey_ready, &value) < 2)
-			dbg ("Warning: failure while parse %s", TOSHIBA_ACPI_KEYS);
+			HAL_WARNING(("Warning: failure while parse %s", TOSHIBA_ACPI_KEYS));
 	}
 	if (fp)
 		fclose (fp);
@@ -86,7 +86,7 @@ toshiba_key_ready (int *value)
 		return FALSE;
 
 	if (fscanf (fp, "hotkey_ready: %1d\nhotkey: 0x%4x", &hotkey_ready, value) < 2)
-		dbg ("Warning: failure while parse %s", TOSHIBA_ACPI_KEYS); 
+		HAL_WARNING (("Warning: failure while parse %s", TOSHIBA_ACPI_KEYS)); 
 
 	if (hotkey_ready) {
 		fprintf (fp, "hotkey_ready:0\n");
@@ -130,11 +130,12 @@ toshiba_key_poll (void)
 			result = "wifi-power";
 
 		if (result) {
-			dbg ("Sending condition '%s'", result);
+			HAL_DEBUG (("Sending condition '%s'", result));
 			libhal_device_emit_condition (ctx, udi, "ButtonPressed", result, &error);
 			if (dbus_error_is_set (&error)) {
-				dbg ("Failed to send condition: %s", error.message);
+				HAL_ERROR (("Failed to send condition: %s", error.message));
 				dbus_error_free (&error);
+				return FALSE;
 			}
 		}
 	}
@@ -150,23 +151,23 @@ main (int argc, char **argv)
 	DBusError error;
 	FILE *fp;
 
-	if ((getenv ("HALD_VERBOSE")) != NULL)
-		is_verbose = TRUE;
+	setup_logger ();
+
 	udi = getenv ("UDI");
 	if (udi == NULL) {
-		dbg ("Failed to get UDI");
+		HAL_ERROR (("Failed to get UDI"));
 		return 1;
 	}
 	dbus_error_init (&error);
 	if ((ctx = libhal_ctx_init_direct (&error)) == NULL) {
-		dbg ("Unable to initialise libhal context: %s", error.message);
+		HAL_ERROR (("Unable to initialise libhal context: %s", error.message));
 		return 1;
 	}
 
 	/* Check for Toshiba ACPI interface /proc/acpi/toshiba/keys */
 	fp = fopen (TOSHIBA_ACPI_KEYS, "r+");
 	if (!fp) {
-		dbg ("Could not open %s! Aborting.", TOSHIBA_ACPI_KEYS);
+		HAL_ERROR (("Could not open %s! Aborting.", TOSHIBA_ACPI_KEYS));
 		return 0;
 	}
 	fclose (fp);
diff --git a/hald/linux2/addons/addon-acpi.c b/hald/linux2/addons/addon-acpi.c
index 220d71d..4b19321 100644
--- a/hald/linux2/addons/addon-acpi.c
+++ b/hald/linux2/addons/addon-acpi.c
@@ -37,7 +37,8 @@
 
 #include "libhal/libhal.h"
 
-#include "../probing/shared.h"
+#include "../../logger.h"
+#include "../../util_helper.h"
 
 #ifdef ACPI_PROC
 static FILE *
@@ -48,7 +49,7 @@ acpi_get_event_fp_kernel (void)
 	fp = fopen ("/proc/acpi/event", "r");
 
 	if (fp == NULL)
-		dbg ("Cannot open /proc/acpi/event: %s", strerror (errno));
+		HAL_ERROR (("Cannot open /proc/acpi/event: %s", strerror (errno)));
 
 	return fp;
 }
@@ -64,7 +65,7 @@ acpi_get_event_fp_acpid (void)
 	int fd;
 
 	if( (fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0 ) {
-		dbg ("Cannot create socket: %s", strerror (errno));
+		HAL_ERROR (("Cannot create socket: %s", strerror (errno)));
 		return NULL;
 	}
 
@@ -73,14 +74,13 @@ acpi_get_event_fp_acpid (void)
 	strncpy (addr.sun_path, "/var/run/acpid.socket", sizeof addr.sun_path);
 
 	if (connect (fd, (struct sockaddr *) &addr, sizeof addr) < 0) {
-		dbg ("Cannot connect to acpid socket: %s", strerror (errno));
+		HAL_ERROR (("Cannot connect to acpid socket: %s", strerror (errno)));
 		close (fd);
 	} else {
 		fp = fdopen (fd, "r");
 
-		if (fp == NULL)
-		{
-			dbg ("fdopen failed: %s", strerror (errno));
+		if (fp == NULL) {
+			HAL_ERROR (("fdopen failed: %s", strerror (errno)));
 			close (fd);
 		}
 	}
@@ -104,7 +104,7 @@ main_loop (LibHalContext *ctx, FILE *eve
 
 	while (fgets (event, sizeof event, eventfp))
 	{
-		dbg ("event is '%s'", event);
+		HAL_DEBUG (("event is '%s'", event));
 
 		if (sscanf (event, "%s %s %x %x", acpi_path, acpi_name, &acpi_num1, &acpi_num2) == 4) {
 			char udi[256];
@@ -114,7 +114,7 @@ main_loop (LibHalContext *ctx, FILE *eve
 			if (strncmp (acpi_path, "button", sizeof ("button") - 1) == 0) {
 				char *type;
 
-				dbg ("button event");
+				HAL_DEBUG (("button event"));
 
 				/* TODO: only rescan if button got state */
 				libhal_device_rescan (ctx, udi, &error);
@@ -130,15 +130,15 @@ main_loop (LibHalContext *ctx, FILE *eve
 					libhal_device_emit_condition (ctx, udi, "ButtonPressed", "", &error);
 				}
 			} else if (strncmp (acpi_path, "ac_adapter", sizeof ("ac_adapter") - 1) == 0) {
-				dbg ("ac_adapter event");
+				HAL_DEBUG (("ac_adapter event"));
 				libhal_device_rescan (ctx, udi, &error);
 			} else if (strncmp (acpi_path, "battery", sizeof ("battery") - 1) == 0) {
-				dbg ("battery event");
+				HAL_DEBUG (("battery event"));
 				libhal_device_rescan (ctx, udi, &error);
 			}
 
 		} else {
-			dbg ("cannot parse event");
+			HAL_DEBUG (("cannot parse event"));
 		}
 
 		if (dbus_error_is_set (&error)) {
@@ -167,12 +167,12 @@ main (int argc, char **argv)
 	drop_privileges (0);
 #endif
 
-	_set_debug ();
+	setup_logger ();
 
 	dbus_error_init (&error);
 
 	if ((ctx = libhal_ctx_init_direct (&error)) == NULL) {
-		dbg ("Unable to initialise libhal context: %s", error.message);
+		HAL_ERROR (("Unable to initialise libhal context: %s", error.message));
 		return 1;
 	}
 
@@ -184,7 +184,7 @@ main (int argc, char **argv)
 	if (eventfp) {
 		hal_set_proc_title ("hald-addon-acpi: listening on acpi kernel interface /proc/acpi/event");
 		main_loop (ctx, eventfp);
-		dbg ("Lost connection to kernel acpi event source - exiting");
+		HAL_ERROR (("Lost connection to kernel acpi event source - exiting"));
 		return 1;
 	}
 #endif
@@ -196,7 +196,7 @@ main (int argc, char **argv)
 		if ((eventfp = acpi_get_event_fp_acpid ())) {
 			hal_set_proc_title ("hald-addon-acpi: listening on acpid socket /var/run/acpid.socket");
 			main_loop (ctx, eventfp);
-			dbg ("Cannot connect to acpid event socket - retry connect");
+			HAL_DEBUG (("Cannot connect to acpid event socket - retry connect"));
 		}
 #endif
 		
diff --git a/hald/linux2/addons/addon-hid-ups.c b/hald/linux2/addons/addon-hid-ups.c
index 4a47db2..1361ed6 100644
--- a/hald/linux2/addons/addon-hid-ups.c
+++ b/hald/linux2/addons/addon-hid-ups.c
@@ -48,7 +48,8 @@
 
 #include "libhal/libhal.h"
 
-#include "../probing/shared.h"
+#include "../../util_helper.h"
+#include "../../logger.h"
 
 #define UPS_USAGE		0x840000
 #define UPS_SERIAL		0x8400fe
@@ -110,7 +111,7 @@ ups_get_string (int fd, int sindex)
 	if (ioctl (fd, HIDIOCGSTRING, &sdesc) < 0) {
 		return "";
 	}
-	dbg ("foo: '%s'", sdesc.value);
+	HAL_DEBUG (("foo: '%s'", sdesc.value));
 	return sdesc.value;
 }
 
@@ -272,8 +273,8 @@ main (int argc, char *argv[])
 
 	hal_set_proc_title_init (argc, argv);
 
-	_set_debug ();
-	
+	setup_logger ();	
+
 	udi = getenv ("UDI");
 	if (udi == NULL)
 		goto out;
diff --git a/hald/linux2/addons/addon-keyboard.c b/hald/linux2/addons/addon-keyboard.c
index 29afcb0..a054ac9 100644
--- a/hald/linux2/addons/addon-keyboard.c
+++ b/hald/linux2/addons/addon-keyboard.c
@@ -36,7 +36,8 @@
 
 #include "libhal/libhal.h"
 
-#include "../probing/shared.h"
+#include "../../logger.h"
+#include "../../util_helper.h"
 
 static char *udi;
 
@@ -186,8 +187,7 @@ main (int argc, char **argv)
 
 	hal_set_proc_title_init (argc, argv);
 
-	if (getenv ("HALD_VERBOSE") != NULL)
-		is_verbose = TRUE;
+	/* setup_logger (); */
 
 	dbus_error_init (&error);
 
diff --git a/hald/linux2/addons/addon-macbookpro-backlight.c b/hald/linux2/addons/addon-macbookpro-backlight.c
index c97211b..f25a555 100644
--- a/hald/linux2/addons/addon-macbookpro-backlight.c
+++ b/hald/linux2/addons/addon-macbookpro-backlight.c
@@ -31,6 +31,7 @@
 #include <string.h>
 #include <sys/io.h>
 #include <sys/mman.h>
+#include <sys/time.h>
 #include <sys/types.h>
 #include <pci/pci.h>
 #include <unistd.h> 
@@ -40,7 +41,7 @@
 #include <dbus/dbus-glib-lowlevel.h>
 
 #include "libhal/libhal.h"
-#include "../probing/shared.h"
+#include "../../logger.h"
 
 static LibHalContext *halctx = NULL;
 static GMainLoop *main_loop;
@@ -201,6 +202,7 @@ set_keyboard_backlight (char value)
 }
 
 
+#if 0
 static int
 read_keyboard_backlight (void)
 {
@@ -211,6 +213,7 @@ read_keyboard_backlight (void)
 	else
 		return -1;
 }
+#endif
 
 static int last_keyboard_brightness = -1;
 
@@ -404,18 +407,18 @@ main (int argc, char *argv[])
  	int state;
 	DBusError err;
 
-	_set_debug ();	
+	setup_logger ();
 	udi = getenv ("UDI");
 
-	dbg ("udi=%s", udi);
+	HAL_DEBUG (("udi=%s", udi));
 	if (udi == NULL) {
-		fprintf (stderr, "No device specified");
+		HAL_ERROR (("No device specified"));
 		return -2;
 	}
 
 	dbus_error_init (&err);
 	if ((halctx = libhal_ctx_init_direct (&err)) == NULL) {
-		fprintf (stderr, "Cannot connect to hald");
+		HAL_ERROR (("Cannot connect to hald"));
 		return -3;
 	}
 
@@ -442,24 +445,24 @@ main (int argc, char *argv[])
  	}
  	pci_cleanup(pacc);
 
-	dbg ("addr 0x%x len=%d", address, length);
+	HAL_DEBUG (("addr 0x%x len=%d", address, length));
  
  	if (!address) {
- 		dbg ("Failed to detect ATI X1600, aborting...");
+ 		HAL_DEBUG (("Failed to detect ATI X1600, aborting..."));
  		return 1;
  	}
  
  	fd = open ("/dev/mem", O_RDWR);
  	
  	if (fd < 0) {
- 		dbg ("cannot open /dev/mem");
+ 		HAL_DEBUG (("cannot open /dev/mem"));
  		return 1;
  	}
  
  	memory = mmap (NULL, length, PROT_READ|PROT_WRITE, MAP_SHARED, fd, address);
  
  	if (memory == MAP_FAILED) {
- 		perror ("mmap failed");
+ 		HAL_ERROR (("mmap failed"));
  		return 2;
  	}
  
@@ -469,7 +472,7 @@ main (int argc, char *argv[])
  	OUTREG(0x7ae4, state);
 
 	if (ioperm (0x300, 0x304, 1) < 0) {
-		perror("ioperm failed (you should be root).");
+		HAL_ERROR (("ioperm failed (you should be root)."));
 		exit(1);
 	}
 
@@ -485,7 +488,7 @@ main (int argc, char *argv[])
 					    "      <arg name=\"brightness_value\" direction=\"out\" type=\"i\"/>\n"
 					    "    </method>\n",
 					    &err)) {
-		fprintf (stderr, "Cannot claim interface");
+		HAL_ERROR (("Cannot claim interface 'org.freedesktop.Hal.Device.LaptopPanel'"));
 		return -4;
 	}
 	if (!libhal_device_claim_interface (halctx, 
@@ -495,7 +498,7 @@ main (int argc, char *argv[])
 					    "      <arg name=\"brightness_value\" direction=\"out\" type=\"ai\"/>\n"
 					    "    </method>\n",
 					    &err)) {
-		fprintf (stderr, "Cannot claim interface");
+		HAL_ERROR (("Cannot claim interface 'org.freedesktop.Hal.Device.LightSensor'"));
 		return -4;
 	}
 	if (!libhal_device_claim_interface (halctx, 
@@ -508,7 +511,7 @@ main (int argc, char *argv[])
 					    "      <arg name=\"brightness_value\" direction=\"in\" type=\"i\"/>\n"
 					    "    </method>\n",
 					    &err)) {
-		fprintf (stderr, "Cannot claim interface");
+		HAL_ERROR (("Cannot claim interface 'org.freedesktop.Hal.Device.KeyboardBacklight'"));
 		return -4;
 	}
 
diff --git a/hald/linux2/addons/addon-pmu.c b/hald/linux2/addons/addon-pmu.c
index 2cbacce..68b59fe 100644
--- a/hald/linux2/addons/addon-pmu.c
+++ b/hald/linux2/addons/addon-pmu.c
@@ -37,7 +37,8 @@
 
 #include "libhal/libhal.h"
 
-#include "../probing/shared.h"
+#include "../../logger.h"
+#include "../../util_helper.h"
 
 int
 main (int argc, char *argv[])
@@ -54,7 +55,7 @@ main (int argc, char *argv[])
 
 	fd = -1;
 
-	_set_debug ();
+	setup_logger ();
 
 	udi = getenv ("UDI");
 	if (udi == NULL)
@@ -67,7 +68,7 @@ main (int argc, char *argv[])
 
 	/* initial state */
 	if ((strstate = getenv ("HAL_PROP_BUTTON_STATE_VALUE")) == NULL) {
-		dbg ("Cannot get HAL_PROP_BUTTON_STATE_VALUE");
+		HAL_ERROR (("Cannot get HAL_PROP_BUTTON_STATE_VALUE"));
 		goto out;
 	}
 	if (strcmp (strstate, "true") == 0)
@@ -76,7 +77,7 @@ main (int argc, char *argv[])
 		state = FALSE;
 
 	if ((fd = open ("/dev/adb", O_RDWR)) < 0) {
-                dbg ("Cannot open /dev/adb");
+                HAL_ERROR (("Cannot open /dev/adb"));
                 goto out;
 	}
 
@@ -92,14 +93,14 @@ main (int argc, char *argv[])
 		if (n == 2) {
 			rd = read (fd, buf, sizeof (buf));
 			if (rd <= 0) {
-				dbg ("Error reading from fd; read returned %d; err=%s", errno, strerror (errno));
+				HAL_ERROR (("Error reading from fd; read returned %d; err=%s", errno, strerror (errno)));
 				goto out;
 			}
 
 #if 0
 			int i;
 			
-			dbg ("Read 0x%02x bytes", rd);				
+			HAL_DEBUG (("Read 0x%02x bytes", rd));				
 			for (i = 0; i < rd; i++) {
 				dbg ("%02x : 0x%02x", i, buf[i]);
 			}
@@ -109,7 +110,7 @@ main (int argc, char *argv[])
 				new_state = (((buf[1]) & 0x01) != 0);
 
 				if (new_state != state) {
-					dbg ("lid state change: %d", new_state);
+					HAL_DEBUG (("lid state change: %d", new_state));
 					dbus_error_init (&error);
 					libhal_device_set_property_bool (
 						ctx, udi, "button.state.value", new_state, &error);
diff --git a/hald/linux2/addons/addon-storage.c b/hald/linux2/addons/addon-storage.c
index 83f4428..1660abc 100644
--- a/hald/linux2/addons/addon-storage.c
+++ b/hald/linux2/addons/addon-storage.c
@@ -42,7 +42,8 @@
 
 #include "libhal/libhal.h"
 
-#include "../probing/shared.h"
+#include "../../logger.h"
+#include "../../util_helper.h"
 
 static void 
 force_unmount (LibHalContext *ctx, const char *udi)
@@ -61,14 +62,14 @@ force_unmount (LibHalContext *ctx, const
 					    "org.freedesktop.Hal.Device.Volume",
 					    "Unmount");
 	if (msg == NULL) {
-		dbg ("Could not create dbus message for %s", udi);
+		HAL_ERROR (("Could not create dbus message for %s", udi));
 		goto out;
 	}
 
 
 	options = calloc (1, sizeof (char *));
 	if (options == NULL) {
-		dbg ("Could not allocate options array");
+		HAL_ERROR (("Could not allocate options array"));
 		goto out;
 	}
 
@@ -77,33 +78,31 @@ force_unmount (LibHalContext *ctx, const
 
 	device_file = libhal_device_get_property_string (ctx, udi, "block.device", NULL);
 	if (device_file != NULL) {
-		openlog ("hald", 0, LOG_DAEMON);
-		syslog (LOG_NOTICE, "forcibly attempting to lazy unmount %s as media was removed", device_file);
-		closelog ();
+		HAL_INFO(("forcibly attempting to lazy unmount %s as media was removed", device_file));
 		libhal_free_string (device_file);
 	}
 
 	if (!dbus_message_append_args (msg, 
 				       DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &options, num_options,
 				       DBUS_TYPE_INVALID)) {
-		dbg ("Could not append args to dbus message for %s", udi);
+		HAL_ERROR (("Could not append args to dbus message for %s", udi));
 		goto out;
 	}
 	
 	dbus_error_init (&error);
 	if (!(reply = dbus_connection_send_with_reply_and_block (dbus_connection, msg, -1, &error))) {
-		dbg ("Unmount failed for %s: %s : %s\n", udi, error.name, error.message);
+		HAL_ERROR (("Unmount failed for %s: %s : %s\n", udi, error.name, error.message));
 		dbus_error_free (&error);
 		goto out;
 	}
 
 	if (dbus_error_is_set (&error)) {
-		dbg ("Unmount failed for %s\n%s : %s\n", udi, error.name, error.message);
+		HAL_ERROR (("Unmount failed for %s\n%s : %s\n", udi, error.name, error.message));
 		dbus_error_free (&error);
 		goto out;
 	}
 
-	dbg ("Succesfully unmounted udi '%s'", udi);
+	HAL_DEBUG (("Succesfully unmounted udi '%s'", udi));
 
 out:
 	if (options != NULL)
@@ -142,7 +141,7 @@ unmount_cleartext_devices (LibHalContext
 			clear_udi = clear_devices[i];
 			dbus_error_init (&error);
 			if (libhal_device_get_property_bool (ctx, clear_udi, "volume.is_mounted", &error)) {
-				dbg ("Forcing unmount of child '%s' (crypto)", clear_udi);
+				HAL_DEBUG (("Forcing unmount of child '%s' (crypto)", clear_udi));
 				force_unmount (ctx, clear_udi);
 			}
 		}
@@ -178,7 +177,7 @@ unmount_childs (LibHalContext *ctx, cons
 
 				dbus_error_init (&error);
 				if (libhal_device_get_property_bool (ctx, vol_udi, "volume.is_mounted", &error)) {
-					dbg ("Forcing unmount of child '%s'", vol_udi);
+					HAL_DEBUG (("Forcing unmount of child '%s'", vol_udi));
 					force_unmount (ctx, vol_udi);
 				}
 
@@ -188,13 +187,13 @@ unmount_childs (LibHalContext *ctx, cons
 					DBusMessage *reply = NULL;
 
 					/* tear down mapping */
-					dbg ("Teardown crypto for '%s'", vol_udi);
+					HAL_DEBUG (("Teardown crypto for '%s'", vol_udi));
 
 					msg = dbus_message_new_method_call ("org.freedesktop.Hal", vol_udi,
 									    "org.freedesktop.Hal.Device.Volume.Crypto",
 									    "Teardown");
 					if (msg == NULL) {
-						dbg ("Could not create dbus message for %s", vol_udi);
+						HAL_ERROR (("Could not create dbus message for %s", vol_udi));
 						goto teardown_failed;
 					}
 
@@ -202,8 +201,8 @@ unmount_childs (LibHalContext *ctx, cons
 					if (!(reply = dbus_connection_send_with_reply_and_block (
 						      libhal_ctx_get_dbus_connection (ctx), msg, -1, &error)) || 
 					    dbus_error_is_set (&error)) {
-						dbg ("Teardown failed for %s: %s : %s\n", 
-						     udi, error.name, error.message);
+						HAL_DEBUG (("Teardown failed for %s: %s : %s\n", 
+						     udi, error.name, error.message));
 						dbus_error_free (&error);
 					}
 
@@ -291,7 +290,7 @@ main (int argc, char *argv[])
 	if ((drive_type = getenv ("HAL_PROP_STORAGE_DRIVE_TYPE")) == NULL)
 		goto out;
 
-	_set_debug ();
+	setup_logger ();
 
 	support_media_changed_str = getenv ("HAL_PROP_STORAGE_CDROM_SUPPORT_MEDIA_CHANGED");
 	if (support_media_changed_str != NULL && strcmp (support_media_changed_str, "true") == 0)
@@ -303,9 +302,9 @@ main (int argc, char *argv[])
 	if ((ctx = libhal_ctx_init_direct (&error)) == NULL)
 		goto out;
 
-	dbg ("**************************************************");
-	dbg ("Doing addon-storage for %s (bus %s) (drive_type %s) (udi %s)", device_file, bus, drive_type, udi);
-	dbg ("**************************************************");
+	HAL_DEBUG (("**************************************************"));
+	HAL_DEBUG (("Doing addon-storage for %s (bus %s) (drive_type %s) (udi %s)", device_file, bus, drive_type, udi));
+	HAL_DEBUG (("**************************************************"));
 
 	hal_set_proc_title ("hald-addon-storage: polling %s", device_file);
 
@@ -343,7 +342,7 @@ main (int argc, char *argv[])
 			}
 
 			if (fd < 0) {
-				dbg ("open failed for %s: %s", device_file, strerror (errno)); 
+				HAL_ERROR (("open failed for %s: %s", device_file, strerror (errno))); 
 				goto skip_check;
 			}
 
@@ -374,7 +373,7 @@ main (int argc, char *argv[])
 				break;
 
 			case -1:
-				dbg ("CDROM_DRIVE_STATUS failed: %s\n", strerror(errno));
+				HAL_ERROR (("CDROM_DRIVE_STATUS failed: %s\n", strerror(errno)));
 				break;
 
 			default:
@@ -416,7 +415,7 @@ main (int argc, char *argv[])
 				got_media = TRUE;
 				close (fd);
 			} else {
-				dbg ("open failed for %s: %s", device_file, strerror (errno)); 
+				HAL_ERROR (("open failed for %s: %s", device_file, strerror (errno))); 
 				close (fd);
 				goto skip_check;
 			}
@@ -427,7 +426,7 @@ main (int argc, char *argv[])
 			if (!got_media) {
 				DBusError error;
 				
-				dbg ("Media removal detected on %s", device_file);
+				HAL_DEBUG (("Media removal detected on %s", device_file));
 				libhal_device_set_property_bool (ctx, udi, "storage.removable.media_available", FALSE, &error);
 				
 				/* attempt to unmount all childs */
@@ -449,7 +448,7 @@ main (int argc, char *argv[])
 			if (got_media) {
 				DBusError error;
 
-				dbg ("Media insertion detected on %s", device_file);
+				HAL_DEBUG (("Media insertion detected on %s", device_file));
 				libhal_device_set_property_bool (ctx, udi, "storage.removable.media_available", TRUE, &error);				/* our probe will trigger the appropriate hotplug events */
 
 				/* could have a fs on the main block device; do a rescan to add it */
@@ -470,7 +469,7 @@ main (int argc, char *argv[])
 		else
 			media_status = MEDIA_STATUS_NO_MEDIA;
 
-		/*dbg ("polling %s; got media=%d", device_file, got_media);*/
+		/*HAL_DEBUG (("polling %s; got media=%d", device_file, got_media));*/
 
 	skip_check:
 		sleep (2);
diff --git a/hald/linux2/addons/addon-usb-csr.c b/hald/linux2/addons/addon-usb-csr.c
index 4ddc782..cd1747d 100644
--- a/hald/linux2/addons/addon-usb-csr.c
+++ b/hald/linux2/addons/addon-usb-csr.c
@@ -34,7 +34,8 @@
 #include <dbus/dbus-glib-lowlevel.h>
 
 #include "libhal/libhal.h"
-#include "../probing/shared.h"
+#include "../../logger.h"
+#include "../../util_helper.h"
 
 #define TIMEOUT         30L
 
@@ -79,7 +80,7 @@ property_cache_item_get (const char *hal
 	pci->bus_no_present = libhal_device_property_exists (halctx, hal_device_udi, 
 			"usb_device.bus_number", &err);
 	if (dbus_error_is_set (&err))
-		dbg ("Error: [%s]/[%s]", err.name, err.message);	
+		HAL_ERROR (("Error: [%s]/[%s]", err.name, err.message));	
 
 	if (pci->bus_no_present)
 		pci->bus_no = libhal_device_get_property_int (halctx, hal_device_udi, 
@@ -121,33 +122,33 @@ check_battery (const char *hal_device_ud
 	if (pci == NULL)
 		return;
 
-	dbg ("CSR device: [%s]", hal_device_udi);
+	HAL_DEBUG (("CSR device: [%s]", hal_device_udi));
 	is_dual = pci->csr_is_dual;
 
 	/* Which of subdevices to address */
-	dbg ("Is dual: %d", is_dual);
+	HAL_DEBUG (("Is dual: %d", is_dual));
 	addr = is_dual? 1<<8 : 0;
 
 	curr_device = find_device (hal_device_udi, pci);
 	if (curr_device == NULL)	{
-		fprintf (stderr, "Device %s not found", hal_device_udi);
+		HAL_ERROR (("Device %s not found", hal_device_udi));
 		return;
 	}
 
 	handle = usb_open (curr_device);
 	if (handle == NULL) {
-		perror ("Could not open usb device");
+		HAL_ERROR (("Could not open usb device"));
 		return;
 	}
 
 	if (!usb_control_msg (handle, 0xc0, 0x09, 0x03|addr, 0x00|addr,
 			 buf, 8, TIMEOUT) != 8)	{
 		if ((P0 == 0x3b) && (P4 == 0)) {
-			dbg ("Receiver busy, trying again later");
+			HAL_DEBUG (("Receiver busy, trying again later"));
 		} else {
 			int current_charge = P5 & 0x07;
 
-			dbg ("Charge level: %d->%d", pci->current_charge, current_charge);
+			HAL_DEBUG (("Charge level: %d->%d", pci->current_charge, current_charge));
 			if (current_charge != pci->current_charge) { 
 			pci->current_charge = current_charge; dbus_error_init (&err);
 		 		libhal_device_set_property_int (halctx, hal_device_udi, 
@@ -173,12 +174,12 @@ find_device (const char *hal_device_udi,
 
 	if (!(pci->bus_no_present && pci->port_no_present)) {
 		/* no sysfs path */
-		fprintf (stderr, "No hal bus number and/or port number");
+		HAL_ERROR (("No hal bus number and/or port number"));
 		return NULL;
 	}
 	snprintf (LUdirname, sizeof (LUdirname), "%03d", pci->bus_no);
 	snprintf (LUfname, sizeof (LUfname), "%03d",pci->port_no);
-	dbg ("Looking for: [%s][%s]", LUdirname, LUfname);
+	HAL_DEBUG (("Looking for: [%s][%s]", LUdirname, LUfname));
 
 	for (curr_bus = usb_busses; curr_bus != NULL; curr_bus = curr_bus->next) {
  		struct usb_device *curr_device;
@@ -191,10 +192,10 @@ find_device (const char *hal_device_udi,
 			/* dbg ("Checking port: [%s]", curr_device->filename); */
 			if (g_strcasecmp (LUfname, curr_device->filename))
 				continue;
-			dbg ("Matched device: [%s][%s][%04X:%04X]", curr_bus->dirname, 
+			HAL_DEBUG (("Matched device: [%s][%s][%04X:%04X]", curr_bus->dirname, 
 				curr_device->filename, 
 				curr_device->descriptor.idVendor, 
-				curr_device->descriptor.idProduct);
+				curr_device->descriptor.idProduct));
 			return curr_device;
 		}
 	}
@@ -204,7 +205,7 @@ find_device (const char *hal_device_udi,
 static gboolean
 check_all_batteries (gpointer data)
 {
-	dbg ("** Check batteries");
+	HAL_DEBUG (("** Check batteries"));
 	/* TODO: make it configurable (not to rescan every time) */
 	usb_find_busses ();
 	usb_find_devices ();
@@ -223,7 +224,7 @@ device_removed (LibHalContext *ctx, cons
 {
 	/* this device is removed */
 	if (is_the_device (hal_device_udi)) {
-		dbg ("** The device %s removed, exit", device_udi);
+		HAL_DEBUG (("** The device %s removed, exit", device_udi));
 		g_main_loop_quit (main_loop);
 	}
 }
@@ -238,7 +239,7 @@ property_modified (LibHalContext *ctx,
 	/* "Key" property modified */
 	if (!g_ascii_strcasecmp (key, "battery.command_interface")) {
 		if (is_removed) {
-			dbg ("** Main Property %s removed: %s", key, hal_device_udi);
+			HAL_DEBUG (("** Main Property %s removed: %s", key, hal_device_udi));
 			/* probably we'll have to exit if this is our device */
 			device_removed (ctx, hal_device_udi);
 		}
@@ -249,7 +250,7 @@ property_modified (LibHalContext *ctx,
 			if (!(g_ascii_strcasecmp (key, "usb_device.bus_number") &&
 			      g_ascii_strcasecmp (key, "usb_device.linux.device_number") &&
 	 		      g_ascii_strcasecmp (key, "battery.csr.is_dual"))) {
-				dbg ("** Property %s added/changed: %s", key, hal_device_udi);
+				HAL_DEBUG (("** Property %s added/changed: %s", key, hal_device_udi));
 				if (dev_props)
 					g_free (dev_props);
 				dev_props = property_cache_item_get (hal_device_udi);
@@ -263,20 +264,20 @@ main (int argc, char *argv[])
 	DBusError err;
 
 	hal_set_proc_title_init (argc, argv);
-	
-	_set_debug ();	
+
+	setup_logger ();	
 
 	device_udi = getenv ("UDI");
 
-	dbg ("device:[%s]", device_udi);
+	HAL_DEBUG (("device:[%s]", device_udi));
 	if (device_udi == NULL) {
-		fprintf (stderr, "No device specified");
+		HAL_ERROR (("No device specified"));
 		return -2;
 	}
 
 	dbus_error_init (&err);
 	if ((halctx = libhal_ctx_init_direct (&err)) == NULL) {
-		fprintf (stderr, "Cannot connect to hald");
+		HAL_ERROR (("Cannot connect to hald"));
 		return -3;
 	}
 
@@ -302,7 +303,7 @@ main (int argc, char *argv[])
 
 	/* Initial fillup */
 	dev_props = property_cache_item_get (device_udi);
-	dbg ("** Initial fillup done");
+	HAL_ERROR (("** Initial fillup done"));
 
 	/* init usb */
 	usb_init ();
@@ -323,6 +324,6 @@ main (int argc, char *argv[])
 	g_main_loop_run (main_loop);
 
 	libhal_ctx_shutdown (halctx, &err);
-	dbg ("** Addon exits normally");
+	HAL_ERROR (("** Addon exits normally"));
 	return 0;
 }
diff --git a/hald/linux2/apm.c b/hald/linux2/apm.c
index fc417ae..e855438 100644
--- a/hald/linux2/apm.c
+++ b/hald/linux2/apm.c
@@ -30,6 +30,7 @@
 #include "../device_info.h"
 #include "../logger.h"
 #include "../util.h"
+#include "../util_pm.h"
 
 #include "osspec_linux.h"
 
diff --git a/hald/linux2/ids.c b/hald/linux2/ids.c
index 35dcec2..7cb41f3 100644
--- a/hald/linux2/ids.c
+++ b/hald/linux2/ids.c
@@ -258,6 +258,21 @@ ids_find_pci (int vendor_id, int product
 	}
 }
 
+/** Free resources used by to store the PCI database
+ *
+ *  @param                      #FALSE if the PCI database wasn't loaded
+ */
+static dbus_bool_t
+pci_ids_free ()
+{
+	if (pci_ids != NULL) {
+		free (pci_ids);
+		pci_ids = NULL;
+		return TRUE;
+	}
+	return FALSE;
+}
+
 /** Load the PCI database used for mapping vendor, product, subsys_vendor
  *  and subsys_product numbers into names.
  *
@@ -290,8 +305,7 @@ pci_ids_load (const char *path)
 	num_read = fread (pci_ids, sizeof (char), pci_ids_len, fp);
 	if (pci_ids_len != num_read) {
 		HAL_ERROR (("Error loading PCI database file"));
-		free (pci_ids);
-		pci_ids = NULL;
+		pci_ids_free();
 		fclose(fp);
 		return FALSE;
 	}
@@ -300,25 +314,6 @@ pci_ids_load (const char *path)
 	return TRUE;
 }
 
-/** Free resources used by to store the PCI database
- *
- *  @param                      #FALSE if the PCI database wasn't loaded
- */
-static dbus_bool_t
-pci_ids_free ()
-{
-	if (pci_ids != NULL) {
-		free (pci_ids);
-		pci_ids = NULL;
-		return TRUE;
-	}
-	return FALSE;
-}
-
-
-
-
-
 /*==========================================================================*/
 
 /** Pointer to where the usb.ids file is loaded */
@@ -480,6 +475,21 @@ ids_find_usb (int vendor_id, int product
 	}
 }
 
+/** Free resources used by to store the USB database
+ *
+ *  @param                      #FALSE if the USB database wasn't loaded
+ */
+static dbus_bool_t
+usb_ids_free ()
+{
+	if (usb_ids != NULL) {
+		free (usb_ids);
+		usb_ids = NULL;
+		return TRUE;
+	}
+	return FALSE;
+}
+
 /** Load the USB database used for mapping vendor, product, subsys_vendor
  *  and subsys_product numbers into names.
  *
@@ -515,8 +525,7 @@ usb_ids_load (const char *path)
 	num_read = fread (usb_ids, sizeof (char), usb_ids_len, fp);
 	if (usb_ids_len != num_read) {
 		printf ("Error loading USB database file\n");
-		free (usb_ids);
-		usb_ids = NULL;
+		usb_ids_free ();
 		fclose(fp);
 		return FALSE;
 	}
@@ -525,20 +534,6 @@ usb_ids_load (const char *path)
 	return TRUE;
 }
 
-/** Free resources used by to store the USB database
- *
- *  @param                      #FALSE if the USB database wasn't loaded
- */
-static dbus_bool_t
-usb_ids_free ()
-{
-	if (usb_ids != NULL) {
-		free (usb_ids);
-		usb_ids = NULL;
-		return TRUE;
-	}
-	return FALSE;
-}
 
 void 
 ids_init (void)
diff --git a/hald/linux2/pmu.c b/hald/linux2/pmu.c
index 901e48e..892fff1 100644
--- a/hald/linux2/pmu.c
+++ b/hald/linux2/pmu.c
@@ -34,6 +34,7 @@
 #include "../hald_dbus.h"
 #include "../logger.h"
 #include "../util.h"
+#include "../util_pm.h"
 
 #include "hotplug.h"
 #include "osspec_linux.h"
diff --git a/hald/linux2/probing/Makefile.am b/hald/linux2/probing/Makefile.am
index d50f44e..a9f0342 100644
--- a/hald/linux2/probing/Makefile.am
+++ b/hald/linux2/probing/Makefile.am
@@ -13,27 +13,27 @@ libexec_PROGRAMS = hald-probe-input hald
 	           hald-probe-pc-floppy hald-probe-smbios hald-probe-serial
 endif
 
-hald_probe_smbios_SOURCES = probe-smbios.c shared.h
+hald_probe_smbios_SOURCES = probe-smbios.c ../../logger.c
 hald_probe_smbios_LDADD = $(top_builddir)/libhal/libhal.la
 
-hald_probe_printer_SOURCES = probe-printer.c shared.h
+hald_probe_printer_SOURCES = probe-printer.c ../../logger.c
 hald_probe_printer_LDADD = $(top_builddir)/libhal/libhal.la @GLIB_LIBS@
 #TODO : get rid of glib in hald_probe_printer
 
-hald_probe_input_SOURCES = probe-input.c shared.h
+hald_probe_input_SOURCES = probe-input.c ../../logger.c
 hald_probe_input_LDADD = $(top_builddir)/libhal/libhal.la
 
-hald_probe_hiddev_SOURCES = probe-hiddev.c shared.h
+hald_probe_hiddev_SOURCES = probe-hiddev.c ../../logger.c
 hald_probe_hiddev_LDADD = $(top_builddir)/libhal/libhal.la
 
-hald_probe_serial_SOURCES = probe-serial.c shared.h
+hald_probe_serial_SOURCES = probe-serial.c ../../logger.c
 hald_probe_serial_LDADD = $(top_builddir)/libhal/libhal.la
 
-hald_probe_storage_SOURCES = probe-storage.c linux_dvd_rw_utils.c linux_dvd_rw_utils.h shared.h
+hald_probe_storage_SOURCES = probe-storage.c linux_dvd_rw_utils.c linux_dvd_rw_utils.h ../../logger.c
 hald_probe_storage_LDADD = $(top_builddir)/libhal/libhal.la @GLIB_LIBS@ @VOLUME_ID_LIBS@
 
-hald_probe_pc_floppy_SOURCES = probe-pc-floppy.c
+hald_probe_pc_floppy_SOURCES = probe-pc-floppy.c ../../logger.c
 
-hald_probe_volume_SOURCES = probe-volume.c linux_dvd_rw_utils.c linux_dvd_rw_utils.h shared.h 
+hald_probe_volume_SOURCES = probe-volume.c linux_dvd_rw_utils.c ../../logger.c 
 hald_probe_volume_LDADD = $(top_builddir)/libhal/libhal.la @GLIB_LIBS@ @VOLUME_ID_LIBS@
 
diff --git a/hald/linux2/probing/probe-input.c b/hald/linux2/probing/probe-input.c
index 0c921ac..6a18990 100644
--- a/hald/linux2/probing/probe-input.c
+++ b/hald/linux2/probing/probe-input.c
@@ -38,7 +38,7 @@
 
 #include "libhal/libhal.h"
 
-#include "shared.h"
+#include "../../logger.h"
 
 /* we must use this kernel-compatible implementation */
 #define BITS_PER_LONG (sizeof(long) * 8)
@@ -56,17 +56,17 @@ check_abs (int fd, LibHalContext *ctx, c
 	DBusError error;
 
 	if (ioctl (fd, EVIOCGBIT(EV_ABS, sizeof (bitmask)), bitmask) < 0) {
-		dbg ("ioctl EVIOCGBIT for EV_ABS failed");
+		HAL_DEBUG (("ioctl EVIOCGBIT for EV_ABS failed"));
 		goto out;
 	}
 
 	if (ioctl (fd, EVIOCGBIT(EV_KEY, sizeof (bitmask_touch)), bitmask_touch) < 0) {
-		dbg ("ioctl EVIOCGBIT for EV_KEY failed");
+		HAL_DEBUG (("ioctl EVIOCGBIT for EV_KEY failed"));
 		goto out;
 	}
 	
 	if (!test_bit(ABS_X, bitmask) || !test_bit(ABS_Y, bitmask)) {
-		dbg ("missing x or y absolute axes");
+		HAL_DEBUG (("missing x or y absolute axes"));
 		goto out;
 	}
 
@@ -90,7 +90,7 @@ check_key (int fd, LibHalContext *ctx, c
 	DBusError error;
 
 	if (ioctl (fd, EVIOCGBIT(EV_KEY, sizeof (bitmask)), bitmask) < 0) {
-		dbg ("ioctl EVIOCGBIT for EV_KEY failed");
+		HAL_DEBUG (("ioctl EVIOCGBIT for EV_KEY failed"));
 		goto out;
 	}
 
@@ -120,12 +120,12 @@ check_rel (int fd, LibHalContext *ctx, c
 	DBusError error;
 
 	if (ioctl (fd, EVIOCGBIT(EV_REL, sizeof (bitmask)), bitmask) < 0) {
-		dbg ("ioctl EVIOCGBIT for EV_REL failed");
+		HAL_DEBUG (("ioctl EVIOCGBIT for EV_REL failed"));
 		goto out;
 	}
 
 	if (!test_bit (REL_X, bitmask) || !test_bit (REL_Y, bitmask)) {
-		dbg ("missing x or y relative axes");
+		HAL_DEBUG (("missing x or y relative axes"));
 		goto out;
 	}
 
@@ -149,7 +149,7 @@ main (int argc, char *argv[])
 	char name[128];
 	struct input_id id;
 
-	_set_debug ();
+	setup_logger ();
 
 	fd = -1;
 
@@ -168,12 +168,11 @@ main (int argc, char *argv[])
 	if (device_file == NULL)
 		goto out;
 
-	dbg ("Doing probe-input for %s (udi=%s)",
-	     device_file, udi);
+	HAL_DEBUG (("Doing probe-input for %s (udi=%s)", device_file, udi));
 
 	fd = open (device_file, O_RDONLY);
 	if (fd < 0) {
-		dbg ("Cannot open %s: %s", device_file, strerror (errno));
+		HAL_ERROR (("Cannot open %s: %s", device_file, strerror (errno)));
 		goto out;
 	}
 
@@ -181,12 +180,12 @@ main (int argc, char *argv[])
 	 * that we now aren't hotpluggable
 	 */
 	if (ioctl (fd, EVIOCGID, &id) < 0) {
-		dbg ("Error: EVIOCGID failed: %s\n", strerror(errno));
+		HAL_ERROR (("Error: EVIOCGID failed: %s\n", strerror(errno)));
 		goto out;
 	}
 	physical_device = getenv ("HAL_PROP_INPUT_PHYSICAL_DEVICE");
 
-	dbg ("probe-input: id.bustype=%i", id.bustype);
+	HAL_DEBUG (("probe-input: id.bustype=%i", id.bustype));
 	if (physical_device == NULL) {
 		switch (id.bustype) {
 		case BUS_I8042: /* x86 legacy port */
@@ -202,7 +201,7 @@ main (int argc, char *argv[])
 
 	/* only consider devices with the event interface */
 	if (ioctl (fd, EVIOCGNAME(sizeof (name)), name) < 0) {
-		dbg ("Error: EVIOCGNAME failed: %s\n", strerror(errno));
+		HAL_ERROR (("Error: EVIOCGNAME failed: %s\n", strerror(errno)));
 		goto out;
 	}
 	if (!libhal_device_set_property_string (ctx, udi, "info.product", name, &error))
diff --git a/hald/linux2/probing/probe-pc-floppy.c b/hald/linux2/probing/probe-pc-floppy.c
index 0a48c84..7a66987 100644
--- a/hald/linux2/probing/probe-pc-floppy.c
+++ b/hald/linux2/probing/probe-pc-floppy.c
@@ -39,7 +39,7 @@
 
 #include "libhal/libhal.h"
 
-#include "shared.h"
+#include "../../logger.h"
 
 int 
 main (int argc, char *argv[])
@@ -61,32 +61,32 @@ main (int argc, char *argv[])
 	if ((device_file = getenv ("HAL_PROP_BLOCK_DEVICE")) == NULL)
 		goto out;
 
-	_set_debug ();
+	setup_logger ();
 	
-	dbg ("Checking if %s is actually present", device_file);
+	HAL_DEBUG (("Checking if %s is actually present", device_file));
 	
 	/* Check that there actually is a drive at the other end */
 	fd = open (device_file, O_RDONLY | O_NONBLOCK);
 	if (fd < 0) {
-		dbg ("Could not open %s", device_file);
+		HAL_ERROR (("Could not open %s", device_file));
 		goto out;
 	}
 	
 	/* @todo Could use the name here */
 	ioctl (fd, FDRESET, NULL);
 	if (ioctl (fd, FDGETDRVTYP, name) != 0) {
-		dbg ("FDGETDRVTYP failed for %s", device_file);
+		HAL_ERROR (("FDGETDRVTYP failed for %s", device_file));
 		goto out;
 	}
-	dbg ("floppy drive name is '%s'", name);
+	HAL_DEBUG (("floppy drive name is '%s'", name));
 
 	if (ioctl (fd, FDPOLLDRVSTAT, &ds)) {
-		dbg ("FDPOLLDRVSTAT failed for %s", device_file);
+		HAL_ERROR (("FDPOLLDRVSTAT failed for %s", device_file));
 		goto out;
 	}
 	
 	if (ds.track < 0) {
-		dbg ("floppy drive %s seems not to exist", device_file);
+		HAL_ERROR (("floppy drive %s seems not to exist", device_file));
 		goto out;
 	}
 
diff --git a/hald/linux2/probing/probe-printer.c b/hald/linux2/probing/probe-printer.c
index 0da9c60..bec6e9b 100644
--- a/hald/linux2/probing/probe-printer.c
+++ b/hald/linux2/probing/probe-printer.c
@@ -36,7 +36,7 @@
 #include <glib.h>
 
 #include "libhal/libhal.h"
-#include "shared.h"
+#include "../../logger.h"
 
 /* Stolen from kernel 2.6.4, drivers/usb/class/usblp.c */
 #define IOCNR_GET_DEVICE_ID 1
@@ -65,28 +65,34 @@ main (int argc, char *argv[])
 	/* assume failure */
 	ret = 1;
 
+	setup_logger ();
+	
 	udi = getenv ("UDI");
-	if (udi == NULL)
+	if (udi == NULL) {
+		HAL_ERROR (("UDI not set"));	
 		goto out;
+	}
 
 	dbus_error_init (&error);
-	if ((ctx = libhal_ctx_init_direct (&error)) == NULL)
+	if ((ctx = libhal_ctx_init_direct (&error)) == NULL) {
+		HAL_ERROR (("ctx init failed"));
 		goto out;
+	}
 
-	_set_debug ();
-	
 	device_file = getenv ("HAL_PROP_PRINTER_DEVICE");
-	if (device_file == NULL)
+	if (device_file == NULL) {
+		HAL_ERROR (("device_file == NULL"));
 		goto out;
+	}
 
 	fd = open (device_file, O_RDONLY);
 	if (fd < 0) {
-		dbg ("Cannot open %s", device_file);
+		HAL_ERROR (("Cannot open %s", device_file));
 		goto out;
 	}
 
 	if (ioctl (fd, LPIOC_GET_DEVICE_ID (sizeof (device_id)), device_id) < 0) {
-		dbg ("Cannot do LPIOC_GET_DEVICE_ID on %s", device_file);
+		HAL_ERROR (("Cannot do LPIOC_GET_DEVICE_ID on %s", device_file));
 		goto out;
 	} else
 
@@ -96,7 +102,7 @@ main (int argc, char *argv[])
 	desc = NULL;
 	cmd = NULL;
 
-	dbg ("device_id = %s", device_id + 2);
+	HAL_DEBUG (("device_id = %s", device_id + 2));
 
 	props = g_strsplit (device_id+2, ";", 0);
 	for (iter = props; *iter != NULL; iter++) {
diff --git a/hald/linux2/probing/probe-serial.c b/hald/linux2/probing/probe-serial.c
index 3f53ef2..b70f82b 100644
--- a/hald/linux2/probing/probe-serial.c
+++ b/hald/linux2/probing/probe-serial.c
@@ -39,7 +39,7 @@
 
 #include "libhal/libhal.h"
 
-#include "shared.h"
+#include "../../logger.h"
 
 int 
 main (int argc, char *argv[])
@@ -54,30 +54,35 @@ main (int argc, char *argv[])
 
 	/* assume failure */
 	ret = 1;
+	
+	setup_logger ();
 
-	if ((udi = getenv ("UDI")) == NULL)
+	if ((udi = getenv ("UDI")) == NULL) {
+		HAL_ERROR (("UDI not set"));
 		goto out;
-	if ((device_file = getenv ("HAL_PROP_SERIAL_DEVICE")) == NULL)
+	}
+
+	if ((device_file = getenv ("HAL_PROP_SERIAL_DEVICE")) == NULL) {
+		HAL_ERROR (("HAL_PROP_SERIAL_DEVICE not set"));
 		goto out;
+	}
 
-	_set_debug ();
-	
-	dbg ("Checking if %s is actually present", device_file);
+	HAL_DEBUG (("Checking if %s is actually present", device_file));
 	
 	/* Check that there actually is a drive at the other end */
 	fd = open (device_file, O_RDONLY | O_NONBLOCK);
 	if (fd < 0) {
-		dbg ("Could not open %s", device_file);
+		HAL_ERROR (("Could not open %s", device_file));
 		goto out;
 	}
 	
 	if (ioctl (fd, TIOCGSERIAL, &ss)) {
-		dbg ("TIOCGSERIAL failed for %s", device_file);
+		HAL_ERROR (("TIOCGSERIAL failed for %s", device_file));
 		goto out;
 	}
 	
 	if (ss.type == 0) {
-		dbg ("serial port %s seems not to exist", device_file);
+		HAL_ERROR (("serial port %s seems not to exist", device_file));
 		goto out;
 	}
 
diff --git a/hald/linux2/probing/probe-smbios.c b/hald/linux2/probing/probe-smbios.c
index 6e20a68..2beb809 100644
--- a/hald/linux2/probing/probe-smbios.c
+++ b/hald/linux2/probing/probe-smbios.c
@@ -34,9 +34,10 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 
 #include "libhal/libhal.h"
-#include "shared.h"
+#include "../../logger.h"
 
 #define DMIPARSER_STATE_IGNORE		0
 #define DMIPARSER_STATE_BIOS		1
@@ -67,7 +68,7 @@ setstr (char *buf, char *str, char *prop
 		dbus_error_init (&error);
 		value = buf + strlen (str) + 1;
 		libhal_device_set_property_string (ctx, udi, prop, value, &error);
-		dbg ("Setting %s='%s'", prop, value);
+		HAL_DEBUG (("Setting %s='%s'", prop, value));
 		return TRUE;
 	}
 	return FALSE;
@@ -102,17 +103,17 @@ main (int argc, char *argv[])
 	/* assume failure */
 	ret = 1;
 
-	_set_debug ();
+	setup_logger ();
 	
 	udi = getenv ("UDI");
 	if (udi == NULL) {
-		dbg ("UDI not set");
+		HAL_ERROR (("UDI not set"));
 		goto out;
 	}
 
 	dbus_error_init (&error);
 	if ((ctx = libhal_ctx_init_direct (&error)) == NULL) {
-		dbg ("ctx init failed");
+		HAL_ERROR (("ctx init failed"));
 		goto out;
 	}
 
@@ -134,11 +135,11 @@ main (int argc, char *argv[])
 		execl ("/usr/sbin/dmidecode", "/usr/sbin/dmidecode", NULL);
 		
 		/* throw an error if we ever reach this point */
-		dbg ("Failed to execute dmidecode!");
+		HAL_ERROR (("Failed to execute dmidecode!"));
 		exit (1);
 		break;
 	case -1:
-		dbg ("Cannot fork!");
+		HAL_ERROR (("Cannot fork!"));
 		break;
 	}
 	
diff --git a/hald/linux2/probing/probe-storage.c b/hald/linux2/probing/probe-storage.c
index 9bfbbb0..1847fcb 100644
--- a/hald/linux2/probing/probe-storage.c
+++ b/hald/linux2/probing/probe-storage.c
@@ -40,13 +40,15 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/ioctl.h>
+#include <unistd.h>
 
 #include <glib.h>
 #include <libvolume_id.h>
 
 #include "libhal/libhal.h"
 #include "linux_dvd_rw_utils.h"
-#include "shared.h"
+
+#include "../../logger.h"
 
 static void vid_log(int priority, const char *file, int line, const char *format, ...)
 {
@@ -55,32 +57,10 @@ static void vid_log(int priority, const 
 
 	va_start(args, format);
 	vsnprintf(log_str, sizeof(log_str), format, args);
-	dbg("%s:%i %s", file, line, log_str);
+	logger_forward_debug("%s:%i %s", file, line, log_str);
 	va_end(args);
 }
 
-static char *
-strdup_valid_utf8 ( const char *String )
-{
-	char *endchar;
-	char *newString;
-	unsigned int count = 0;
-
-	if (String == NULL)
-		return NULL;
-
-	newString = g_strdup( String );
-
-	while (!g_utf8_validate (newString, -1, (const char **) &endchar)) {
-		*endchar = '?';
-		count++;
-	}
-
-	if (strlen(newString) == count)
-		return NULL;
-	else
-		return newString;
-}
 
 /** Check if a filesystem on a special device file is mounted
  *
@@ -148,7 +128,7 @@ main (int argc, char *argv[])
 	if ((sysfs_path = getenv ("HAL_PROP_LINUX_SYSFS_PATH")) == NULL)
 		goto out;
 
-	_set_debug ();
+	setup_logger ();
 
 	if (argc == 2 && strcmp (argv[1], "--only-check-for-media") == 0)
 		only_check_for_fs = TRUE;
@@ -159,8 +139,8 @@ main (int argc, char *argv[])
 	if ((ctx = libhal_ctx_init_direct (&error)) == NULL)
 		goto out;
 
-	dbg ("Doing probe-storage for %s (bus %s) (drive_type %s) (udi=%s) (--only-check-for-fs==%d)", 
-	     device_file, bus, drive_type, udi, only_check_for_fs);
+	HAL_DEBUG (("Doing probe-storage for %s (bus %s) (drive_type %s) (udi=%s) (--only-check-for-fs==%d)", 
+	     device_file, bus, drive_type, udi, only_check_for_fs));
 
 	if (!only_check_for_fs) {
 		/* Get properties for CD-ROM drive */
@@ -169,16 +149,16 @@ main (int argc, char *argv[])
 			int read_speed, write_speed;
 			char *write_speeds;
 			
-			dbg ("Doing open (\"%s\", O_RDONLY | O_NONBLOCK)", device_file);
+			HAL_DEBUG (("Doing open (\"%s\", O_RDONLY | O_NONBLOCK)", device_file));
 			fd = open (device_file, O_RDONLY | O_NONBLOCK);
 			if (fd < 0) {
-				dbg ("Cannot open %s: %s", device_file, strerror (errno));
+				HAL_ERROR (("Cannot open %s: %s", device_file, strerror (errno)));
 				goto out;
 			}
-			dbg ("Returned from open(2)");
+			HAL_DEBUG (("Returned from open(2)"));
 
 			if (ioctl (fd, CDROM_SET_OPTIONS, CDO_USE_FFLAGS) < 0) {
-				dbg ("Error: CDROM_SET_OPTIONS failed: %s\n", strerror(errno));
+				HAL_ERROR (("Error: CDROM_SET_OPTIONS failed: %s\n", strerror(errno)));
 				close (fd);
 				goto out;
 			}
@@ -219,7 +199,7 @@ main (int argc, char *argv[])
 				libhal_device_set_property_bool (ctx, udi, "storage.cdrom.dvd", TRUE, &error);
 
 				profile = get_dvd_r_rw_profile (fd);
-				dbg ("get_dvd_r_rw_profile returned: %d", profile);
+				HAL_DEBUG (("get_dvd_r_rw_profile returned: %d", profile));
 
 				if (profile & DRIVE_CDROM_CAPS_DVDRW)
 					libhal_device_set_property_bool (ctx, udi, "storage.cdrom.dvdrw", TRUE, &error);
@@ -280,7 +260,7 @@ main (int argc, char *argv[])
 		int got_media;
 		int drive;
 
-		dbg ("Checking for optical disc on %s", device_file);
+		HAL_DEBUG (("Checking for optical disc on %s", device_file));
 
 		support_media_changed_str = getenv ("HAL_PROP_STORAGE_CDROM_SUPPORT_MEDIA_CHANGED");
 		if (support_media_changed_str != NULL && strcmp (support_media_changed_str, "true") == 0)
@@ -288,7 +268,7 @@ main (int argc, char *argv[])
 		else
 			support_media_changed = FALSE;
 
-		dbg ("Doing open (\"%s\", O_RDONLY | O_NONBLOCK | O_EXCL)", device_file);
+		HAL_DEBUG (("Doing open (\"%s\", O_RDONLY | O_NONBLOCK | O_EXCL)", device_file));
 		fd = open (device_file, O_RDONLY | O_NONBLOCK | O_EXCL);
 
 		if (fd < 0 && errno == EBUSY) {
@@ -303,12 +283,12 @@ main (int argc, char *argv[])
 			if (!is_mounted (device_file))
 				goto out;
 
-			dbg ("Doing open (\"%s\", O_RDONLY | O_NONBLOCK)", device_file);
+			HAL_DEBUG (("Doing open (\"%s\", O_RDONLY | O_NONBLOCK)", device_file));
 			fd = open (device_file, O_RDONLY | O_NONBLOCK);
 		}
 
 		if (fd < 0) {
-			dbg ("open failed for %s: %s", device_file, strerror (errno));
+			HAL_DEBUG (("open failed for %s: %s", device_file, strerror (errno)));
 			goto out;
 		}
 
@@ -341,7 +321,7 @@ main (int argc, char *argv[])
 			break;
 			
 		case -1:
-			dbg ("Error: CDROM_DRIVE_STATUS failed: %s\n", strerror(errno));
+			HAL_ERROR (("Error: CDROM_DRIVE_STATUS failed: %s\n", strerror(errno)));
 			break;
 			
 		default:
@@ -369,21 +349,21 @@ main (int argc, char *argv[])
 		size_t main_device_len;
 		uint64_t size;
 
-		dbg ("Checking for file system on %s", device_file);
+		HAL_DEBUG (("Checking for file system on %s", device_file));
 
 		/* See if we got a file system on the main block device - which 
 		 * means doing a data (non O_NONBLOCK) open - this might fail, 
 		 * especially if we don't have any media...
 		 */
-		dbg ("Doing open (\"%s\", O_RDONLY)", device_file);
+		HAL_DEBUG (("Doing open (\"%s\", O_RDONLY)", device_file));
 		fd = open (device_file, O_RDONLY);
 		if (fd < 0) {
-			dbg ("Cannot open %s: %s", device_file, strerror (errno));
+			HAL_DEBUG (("Cannot open %s: %s", device_file, strerror (errno)));
 			/* no media */
 			libhal_device_set_property_bool (ctx, udi, "storage.removable.media_available", FALSE, &error);
 			goto out;
 		}
-		dbg ("Returned from open(2)");
+		HAL_DEBUG (("Returned from open(2)"));
 
 		/* if we get to here, we have media */
 		libhal_device_set_property_bool (ctx, udi, "storage.removable.media_available", TRUE, &error);
@@ -399,15 +379,15 @@ main (int argc, char *argv[])
 			goto out;
 		main_device = &main_device[1];
 		main_device_len = strlen (main_device);
-		dbg ("look for existing partitions for %s", main_device);
+		HAL_DEBUG (("look for existing partitions for %s", main_device));
 		if ((dir = g_dir_open (sysfs_path, 0, NULL)) == NULL) {
-			dbg ("failed to open sysfs dir");
+			HAL_DEBUG (("failed to open sysfs dir"));
 			goto out;
 		}
 		while ((partition = g_dir_read_name (dir)) != NULL) {
 			if (strncmp (main_device, partition, main_device_len) == 0 &&
 			    isdigit (partition[main_device_len])) {
-				dbg ("partition %s found, skip probing for filesystem", partition);
+				HAL_DEBUG (("partition %s found, skip probing for filesystem", partition));
 				g_dir_close (dir);
 				goto out;
 			}
diff --git a/hald/linux2/probing/probe-volume.c b/hald/linux2/probing/probe-volume.c
index b70bd55..318ee46 100644
--- a/hald/linux2/probing/probe-volume.c
+++ b/hald/linux2/probing/probe-volume.c
@@ -45,7 +45,7 @@
 
 #include "libhal/libhal.h"
 #include "linux_dvd_rw_utils.h"
-#include "shared.h"
+#include "../../logger.h"
 
 static void vid_log(int priority, const char *file, int line, const char *format, ...)
 {
@@ -54,7 +54,7 @@ static void vid_log(int priority, const 
 
 	va_start(args, format);
 	vsnprintf(log_str, sizeof(log_str), format, args);
-	dbg("%s:%i %s", file, line, log_str);
+	logger_forward_debug("%s:%i %s", file, line, log_str);
 	va_end(args);
 }
 
@@ -131,11 +131,11 @@ probe_msdos_part_table(int fd)
 	} __attribute__((packed)) *part;
 
 	if (lseek(fd, 0, SEEK_SET) < 0) {
-		dbg("lseek failed (%s)", strerror(errno));
+		HAL_DEBUG (("lseek failed (%s)", strerror(errno)));
 		return NULL;
 	}
 	if (read(fd, &buf, BSIZE) < BSIZE) {
-		dbg("read failed (%s)", strerror(errno));
+		HAL_DEBUG (("read failed (%s)", strerror(errno)));
 		return NULL;
 	}
 	if (memcmp(&buf[MSDOS_SIG_OFF], MSDOS_MAGIC, 2) != 0)
@@ -169,12 +169,12 @@ probe_msdos_part_table(int fd)
 		dbg ("part %d -> type=%d off=%lld size=%lld", i, part[i].sys_ind, poff, plen);
 
 		if (is_extended(part[i].sys_ind)) {
-			dbg("found extended partition at 0x%llx", (unsigned long long) poff);
+			HAL_DEBUG (("found extended partition at 0x%llx", (unsigned long long) poff));
 			if (extended == 0)
 				extended = poff;
 		} else {
-			dbg("found 0x%x primary data partition at 0x%llx, len 0x%llx",
-			    part[i].sys_ind, (unsigned long long) poff, (unsigned long long) plen);
+			HAL_DEBUG (("found 0x%x primary data partition at 0x%llx, len 0x%llx",
+			    part[i].sys_ind, (unsigned long long) poff, (unsigned long long) plen));
 		}
 	}
 
@@ -186,17 +186,17 @@ probe_msdos_part_table(int fd)
 		uint64_t oldnext;
 
 		if (limit-- == 0) {
-			dbg("extended chain limit reached");
+			HAL_DEBUG(("extended chain limit reached"));
 			break;
 		}
 
-		dbg("read 0x%llx (%llu)", next, next);
+		HAL_DEBUG (("read 0x%llx (%llu)", next, next));
 		if (lseek(fd, next, SEEK_SET) < 0) {
-			dbg("lseek failed (%s)", strerror(errno));
+			HAL_DEBUG(("lseek failed (%s)", strerror(errno)));
 			return NULL;
 		}
 		if (read(fd, &buf, BSIZE) < BSIZE) {
-			dbg("read failed (%s)", strerror(errno));
+			HAL_DEBUG(("read failed (%s)", strerror(errno)));
 			return NULL;
 		}
 		if (memcmp(&buf[MSDOS_SIG_OFF], MSDOS_MAGIC, 2) != 0)
@@ -214,12 +214,12 @@ probe_msdos_part_table(int fd)
 				continue;
 
 			if (is_extended(part[i].sys_ind)) {
-				dbg("found extended partition (chain) at 0x%llx", (unsigned long long) poff);
+				HAL_DEBUG(("found extended partition (chain) at 0x%llx", (unsigned long long) poff));
 				if (next == 0)
 					next = extended + poff;
 			} else {
-				dbg("found 0x%x logical data partition at 0x%llx, len 0x%llx",
-					part[i].sys_ind, (unsigned long long) poff, (unsigned long long) plen);
+				HAL_DEBUG(("found 0x%x logical data partition at 0x%llx, len 0x%llx",
+					part[i].sys_ind, (unsigned long long) poff, (unsigned long long) plen));
 
 				partition_id_index[partition_count].part_type = part[i].sys_ind;
 				partition_id_index[partition_count].start = oldnext + poff;
@@ -265,22 +265,22 @@ set_volume_id_values (LibHalContext *ctx
 	}
 
 	libhal_changeset_set_property_string (changes, "volume.fsusage", usage);
-	dbg ("volume.fsusage = '%s'", usage);
+	HAL_DEBUG (("volume.fsusage = '%s'", usage));
 
 	libhal_changeset_set_property_string (changes, "volume.fstype", vid->type);
-	dbg ("volume.fstype = '%s'", vid->type);
+	HAL_DEBUG(("volume.fstype = '%s'", vid->type));
 	if (vid->type_version[0] != '\0') {
 		libhal_changeset_set_property_string (changes, "volume.fsversion", vid->type_version);
-		dbg ("volume.fsversion = '%s'", vid->type_version);
+		HAL_DEBUG(("volume.fsversion = '%s'", vid->type_version));
 	}
 	libhal_changeset_set_property_string (changes, "volume.uuid", vid->uuid);
-	dbg ("volume.uuid = '%s'", vid->uuid);
+	HAL_DEBUG(("volume.uuid = '%s'", vid->uuid));
 
 	/* we need to be sure for a utf8 valid label, because dbus accept only utf8 valid strings */
 	volume_label = strdup_valid_utf8 (vid->label);
 	if( volume_label != NULL ) {
 		libhal_changeset_set_property_string (changes, "volume.label", volume_label);
-		dbg ("volume.label = '%s'", volume_label);
+		HAL_DEBUG(("volume.label = '%s'", volume_label));
 		
 		if (strlen(volume_label) > 0) {	
 			libhal_changeset_set_property_string (changes, "info.product", volume_label);
@@ -331,7 +331,7 @@ advanced_disc_detect (LibHalContext *ctx
 	lseek (fd, 0x8080, SEEK_CUR);
 	if (read (fd, &bs, 2) != 2)
 	{
-		dbg ("Advanced probing on %s failed while reading block size", device_file);
+		HAL_DEBUG(("Advanced probing on %s failed while reading block size", device_file));
 		goto out;
 	}
 
@@ -339,7 +339,7 @@ advanced_disc_detect (LibHalContext *ctx
 	lseek (fd, 2, SEEK_CUR);
 	if (read (fd, &ts, 2) != 2)
 	{
-		dbg ("Advanced probing on %s failed while reading path table size", device_file);
+		HAL_DEBUG(("Advanced probing on %s failed while reading path table size", device_file));
 		goto out;
 	}
 
@@ -347,7 +347,7 @@ advanced_disc_detect (LibHalContext *ctx
 	lseek (fd, 6, SEEK_CUR);
 	if (read (fd, &tl, 4) != 4)
 	{
-		dbg ("Advanced probing on %s failed while reading path table block", device_file);
+		HAL_DEBUG(("Advanced probing on %s failed while reading path table block", device_file));
 		goto out;
 	}
 
@@ -360,7 +360,7 @@ advanced_disc_detect (LibHalContext *ctx
 		/* get the length of the filename of the current entry */
 		if (read (fd, &len_di, 1) != 1)
 		{
-			dbg ("Advanced probing on %s failed, cannot read more entries", device_file);
+			HAL_DEBUG(("Advanced probing on %s failed, cannot read more entries", device_file));
 			break;
 		}
 
@@ -369,14 +369,14 @@ advanced_disc_detect (LibHalContext *ctx
 		lseek (fd, 5, SEEK_CUR);
 		if (read (fd, &parent, 2) != 2)
 		{
-			dbg ("Advanced probing on %s failed, couldn't read parent entry", device_file);
+			HAL_DEBUG(("Advanced probing on %s failed, couldn't read parent entry", device_file));
 			break;
 		}
 		
 		/* read the name */
 		if (read (fd, dirname, len_di) != len_di)
 		{
-			dbg ("Advanced probing on %s failed, couldn't read the entry name", device_file);
+			HAL_DEBUG(("Advanced probing on %s failed, couldn't read the entry name", device_file));
 			break;
 		}
 		dirname[len_di] = 0;
@@ -396,19 +396,19 @@ advanced_disc_detect (LibHalContext *ctx
 			if (!strcmp (dirname, "VIDEO_TS"))
 			{
 				libhal_changeset_set_property_bool (changes, "volume.disc.is_videodvd", TRUE);
-				dbg ("Disc in %s is a Video DVD", device_file);
+				HAL_DEBUG(("Disc in %s is a Video DVD", device_file));
 				break;
 			}
 			else if (!strcmp (dirname, "VCD"))
 			{
 				libhal_changeset_set_property_bool (changes, "volume.disc.is_vcd", TRUE);
-				dbg ("Disc in %s is a Video CD", device_file);
+				HAL_DEBUG(("Disc in %s is a Video CD", device_file));
 				break;
 			}
 			else if (!strcmp (dirname, "SVCD"))
 			{
 				libhal_changeset_set_property_bool (changes, "volume.disc.is_svcd", TRUE);
-				dbg ("Disc in %s is a Super Video CD", device_file);
+				HAL_DEBUG(("Disc in %s is a Super Video CD", device_file));
 				break;
 			}
 		}
@@ -481,7 +481,7 @@ main (int argc, char *argv[])
 	else
 		is_disc = FALSE;
 
-	_set_debug ();
+	setup_logger ();
 
 	dbus_error_init (&error);
 	if ((ctx = libhal_ctx_init_direct (&error)) == NULL)
@@ -489,11 +489,11 @@ main (int argc, char *argv[])
 
 	changeset = libhal_device_new_changeset (udi);
 	if (changeset == NULL) {
-		dbg ("Cannot initialize changeset");
+		HAL_DEBUG(("Cannot initialize changeset"));
 		goto out;
 	}
 
-	dbg ("Doing probe-volume for %s\n", device_file);
+	HAL_DEBUG(("Doing probe-volume for %s\n", device_file));
 
 	fd = open (device_file, O_RDONLY);
 	if (fd < 0)
@@ -501,11 +501,11 @@ main (int argc, char *argv[])
 
 	/* block size and total size */
 	if (ioctl (fd, BLKSSZGET, &block_size) == 0) {
-		dbg ("volume.block_size = %d", block_size);
+		HAL_DEBUG(("volume.block_size = %d", block_size));
 		libhal_changeset_set_property_int (changeset, "volume.block_size", block_size);
 	}
 	if (ioctl (fd, BLKGETSIZE64, &vol_size) == 0) {
-		dbg ("volume.size = %llu", vol_size);
+		HAL_DEBUG(("volume.size = %llu", vol_size));
 		libhal_changeset_set_property_uint64 (changeset, "volume.size", vol_size);
 	} else
 		vol_size = 0;
@@ -536,33 +536,33 @@ main (int argc, char *argv[])
 		switch (type) {
 		case CDS_AUDIO:		/* audio CD */
 			libhal_changeset_set_property_bool (changeset, "volume.disc.has_audio", TRUE);
-			dbg ("Disc in %s has audio", device_file);
+			HAL_DEBUG(("Disc in %s has audio", device_file));
 			should_probe_for_fs = FALSE;
 			break;
 		case CDS_MIXED:		/* mixed mode CD */
 			libhal_changeset_set_property_bool (changeset, "volume.disc.has_audio", TRUE);
 			libhal_changeset_set_property_bool (changeset, "volume.disc.has_data", TRUE);
-			dbg ("Disc in %s has audio+data", device_file);
+			HAL_DEBUG(("Disc in %s has audio+data", device_file));
 			break;
 		case CDS_DATA_1:	/* data CD */
 		case CDS_DATA_2:
 		case CDS_XA_2_1:
 		case CDS_XA_2_2:
 			libhal_changeset_set_property_bool (changeset, "volume.disc.has_data", TRUE);
-			dbg ("Disc in %s has data", device_file);
+			HAL_DEBUG(("Disc in %s has data", device_file));
 			advanced_disc_detect (ctx, udi, changeset, fd, device_file);
 			break;
 		case CDS_NO_INFO:	/* blank or invalid CD */
 			libhal_changeset_set_property_bool (changeset, "volume.disc.is_blank", TRUE);
 			/* set the volume size to 0 if disc is blank and not as 4 from BLKGETSIZE64 */
 			libhal_changeset_set_property_int (changeset, "volume.block_size", 0);
-			dbg ("Disc in %s is blank", device_file);
+			HAL_DEBUG(("Disc in %s is blank", device_file));
 			should_probe_for_fs = FALSE;
 			break;
 			
 		default:		/* should never see this */
 			libhal_changeset_set_property_string (changeset, "volume.disc_type", "unknown");
-			dbg ("Disc in %s returned unknown CDROM_DISC_STATUS", device_file);
+			HAL_DEBUG(("Disc in %s returned unknown CDROM_DISC_STATUS", device_file));
 			should_probe_for_fs = FALSE;
 			break;
 		}
@@ -571,7 +571,7 @@ main (int argc, char *argv[])
 		 * http://www.t10.org/drafts.htm#mmc5
 		 */
 		type = get_disc_type (fd);
-		dbg ("get_disc_type returned 0x%02x", type);
+		HAL_DEBUG(("get_disc_type returned 0x%02x", type));
 		if (type != -1) {
 			switch (type) {
 			case 0x08: /* CD-ROM */
@@ -641,7 +641,7 @@ main (int argc, char *argv[])
 		}
 
 		if (get_disc_capacity_for_type (fd, type, &capacity) == 0) {
-			dbg ("volume.disc.capacity = %llu", capacity);
+			HAL_DEBUG(("volume.disc.capacity = %llu", capacity));
 			libhal_changeset_set_property_uint64 (changeset, "volume.disc.capacity", capacity);
 		}
 
@@ -664,7 +664,7 @@ main (int argc, char *argv[])
 			unsigned int vol_session_count = 0;
 
 			vol_session_count = toc_hdr.cdth_trk1;
-			dbg ("volume_session_count = %u", vol_session_count);
+			HAL_DEBUG(("volume_session_count = %u", vol_session_count));
 
 			/* read session header */
 			memset (&toc_entr, 0x00, sizeof (toc_entr));
@@ -672,7 +672,7 @@ main (int argc, char *argv[])
 			toc_entr.cdte_format = CDROM_LBA;
 			if (ioctl (fd, CDROMREADTOCENTRY, &toc_entr) == 0)
 				if ((toc_entr.cdte_ctrl & CDROM_DATA_TRACK) == 4) {
-					dbg ("last session starts at block = %u", toc_entr.cdte_addr.lba);
+					HAL_DEBUG(("last session starts at block = %u", toc_entr.cdte_addr.lba));
 					vol_probe_offset = toc_entr.cdte_addr.lba * block_size;
 				}
 		}
diff --git a/hald/linux2/probing/shared.h b/hald/linux2/probing/shared.h
deleted file mode 100644
index 3805b71..0000000
--- a/hald/linux2/probing/shared.h
+++ /dev/null
@@ -1,174 +0,0 @@
-
-#ifndef SHARED_H
-#define SHARED_H
-
-#include <time.h>
-#include <sys/time.h>
-#include <pwd.h>
-#include <grp.h>
-
-#include <sys/types.h>
-#include <sys/syslog.h>
-#include <unistd.h>
-#include <pwd.h>
-#include <grp.h>
-
-static dbus_bool_t is_verbose = FALSE;
-static dbus_bool_t use_syslog = FALSE;
-
-static void
-_do_dbg (const char *format, va_list args)
-{
-	char buf[512];
-	char tbuf[256];
-	struct timeval tnow;
-	struct tm *tlocaltime;
-	struct timezone tzone;
-	static pid_t pid = -1;
-
-	if (!is_verbose)
-		return;
-
-	if ((int) pid == -1)
-		pid = getpid ();
-
-	vsnprintf (buf, sizeof (buf), format, args);
-
-	gettimeofday (&tnow, &tzone);
-	tlocaltime = localtime (&tnow.tv_sec);
-	strftime (tbuf, sizeof (tbuf), "%H:%M:%S", tlocaltime);
-
-	if (use_syslog)
-		syslog (LOG_INFO, "%d: %s.%03d: %s", pid, tbuf, (int)(tnow.tv_usec/1000), buf);
-	else
-		fprintf (stderr, "%d: %s.%03d: %s", pid, tbuf, (int)(tnow.tv_usec/1000), buf);
-
-	va_end (args);
-}
-
-static void
-_dbg (const char *format, ...)
-{
-	va_list args;
-	va_start (args, format);
-	_do_dbg (format, args);
-}
-
-static void
-_set_debug ()
-{
-        if ((getenv ("HALD_VERBOSE")) != NULL)
-                is_verbose = TRUE;
-
-        if ((getenv ("HALD_USE_SYSLOG")) != NULL)
-                use_syslog = TRUE;
-}
-
-#define dbg(format, arg...)							\
-	do {									\
-		_dbg ("%s:%d: " format "\n", __FILE__, __LINE__, ## arg); \
-	} while (0)
-
-/** Drop root privileges: Set the running user id to HAL_USER and
- *  group to HAL_GROUP, and optionally retain auxiliary groups of HAL_USER.
- */
-static void
-drop_privileges (int keep_auxgroups)
-{
-	struct passwd *pw = NULL;
-	struct group *gr = NULL;
-
-	/* determine user id */
-	pw = getpwnam (HAL_USER);
-	if (!pw)  {
-		dbg ("drop_privileges: user " HAL_USER " does not exist");
-		exit (-1);
-	}
-
-	/* determine primary group id */
-	gr = getgrnam (HAL_GROUP);
-	if (!gr) {
-		dbg ("drop_privileges: group " HAL_GROUP " does not exist");
-		exit (-1);
-	}
-
-	if (keep_auxgroups) {
-		if (initgroups (HAL_USER, gr->gr_gid)) {
-			dbg ("drop_privileges: could not initialize groups");
-			exit (-1);
-		}
-	}
-
-	if (setgid (gr->gr_gid)) {
-		dbg ("drop_privileges: could not set group id");
-		exit (-1);
-	}
-
-	if (setuid (pw->pw_uid)) {
-		dbg ("drop_privileges: could not set user id");
-		exit (-1);
-	}
-}
-
-#ifdef __linux__
-extern char **environ;
-#endif
-
-static char **argv_buffer = NULL;
-static size_t argv_size = 0;
-
-static void
-hal_set_proc_title_init (int argc, char *argv[])
-{
-#ifdef __linux__
-	unsigned int i;
-	char **new_environ, *endptr;
-
-	/* This code is really really ugly. We make some memory layout
-	 * assumptions and reuse the environment array as memory to store
-	 * our process title in */
-	
-	for (i = 0; environ[i] != NULL; i++)
-		;
-	
-	endptr = i ? environ[i-1] + strlen (environ[i-1]) : argv[argc-1] + strlen (argv[argc-1]);
-	
-	argv_buffer = argv;
-	argv_size = endptr - argv_buffer[0];
-	
-	/* Make a copy of environ */
-	
-	new_environ = malloc (sizeof(char*) * (i + 1));
-	for (i = 0; environ[i] != NULL; i++)
-		new_environ[i] = strdup (environ[i]);
-	new_environ[i] = NULL;
-	
-	environ = new_environ;
-#endif
-}
-
-/* this code borrowed from avahi-daemon's setproctitle.c (LGPL v2) */
-static void
-hal_set_proc_title (const char *format, ...)
-{
-#ifdef __linux__
-	size_t len;
-	va_list ap;
-
-	if (argv_buffer == NULL)
-		goto out;
-		
-	va_start (ap, format);
-	vsnprintf (argv_buffer[0], argv_size, format, ap);
-	va_end (ap);
- 	
-	len = strlen (argv_buffer[0]);
- 	   
-	memset (argv_buffer[0] + len, 0, argv_size - len);
-	argv_buffer[1] = NULL;
-out:
-	;
-#endif
-}
-
-#endif /* SHARED_H */
diff --git a/hald/logger.c b/hald/logger.c
index f3a5cde..6cd7d01 100644
--- a/hald/logger.c
+++ b/hald/logger.c
@@ -4,6 +4,7 @@
  * logger.c : Logging 
  *
  * Copyright (C) 2003 David Zeuthen, <david at fubar.dk>
+ * Copyright (C) 2006 Danny Kukawka, <danny.kukawka at web.de>
  *
  * Licensed under the Academic Free License version 2.1
  *
@@ -34,6 +35,7 @@
 #include <time.h>
 #include <sys/time.h>
 #include <syslog.h>
+#include <unistd.h>
 
 #include "logger.h"
 
@@ -50,6 +52,7 @@ static const char *file;
 static int line;
 static const char *function;
 
+static int log_pid  = 0;
 static int is_enabled = 1;
 static int syslog_enabled = 0;
 
@@ -90,6 +93,25 @@ logger_disable_syslog (void)
 	syslog_enabled = 0;
 }
 
+/** allow setup logger from a addon/prober via the env 
+ *
+ */
+void
+setup_logger (void)
+{
+        if ((getenv ("HALD_VERBOSE")) != NULL) {
+                is_enabled = 1;
+		log_pid = 1;
+	}
+        else
+                is_enabled = 0;
+
+        if ((getenv ("HALD_USE_SYSLOG")) != NULL)
+		syslog_enabled = 1;
+        else
+                syslog_enabled = 0;
+}
+
 /** Setup logging entry
  *
  *  @param  priority            Logging priority, one of HAL_LOGPRI_*
@@ -118,9 +140,11 @@ logger_emit (const char *format, ...)
 	char buf[512];
 	char *pri;
 	char tbuf[256];
+	char logmsg[1024];
 	struct timeval tnow;
 	struct tm *tlocaltime;
 	struct timezone tzone;
+	static pid_t pid = -1;
 
 	if (!is_enabled)
 		return;
@@ -129,44 +153,52 @@ logger_emit (const char *format, ...)
 	vsnprintf (buf, sizeof (buf), format, args);
 
 	switch (priority) {
-	case HAL_LOGPRI_TRACE:
-		pri = "[T]";
-		break;
-	case HAL_LOGPRI_DEBUG:
-		pri = "[D]";
-		break;
-	case HAL_LOGPRI_INFO:
-		pri = "[I]";
-		break;
-	case HAL_LOGPRI_WARNING:
-		pri = "[W]";
-		break;
-	default:		/* explicit fallthrough */
-	case HAL_LOGPRI_ERROR:
-		pri = "[E]";
-		break;
+		case HAL_LOGPRI_TRACE:
+			pri = "[T]";
+			break;
+		case HAL_LOGPRI_DEBUG:
+			pri = "[D]";
+			break;
+		case HAL_LOGPRI_INFO:
+			pri = "[I]";
+			break;
+		case HAL_LOGPRI_WARNING:
+			pri = "[W]";
+			break;
+		default:		/* explicit fallthrough */
+		case HAL_LOGPRI_ERROR:
+			pri = "[E]";
+			break;
 	}
 
 	gettimeofday (&tnow, &tzone);
 	tlocaltime = localtime (&tnow.tv_sec);
 	strftime (tbuf, sizeof (tbuf), "%H:%M:%S", tlocaltime);
 
+	if (log_pid) {
+        	if ((int) pid == -1)
+                	pid = getpid ();
+		snprintf (logmsg, sizeof(logmsg), "[%d]: %s.%03d %s %s:%d: %s\n", pid, tbuf, (int)(tnow.tv_usec/1000), pri, file, line, buf);
+	} else {
+		snprintf (logmsg, sizeof(logmsg), "%s.%03d %s %s:%d: %s\n", tbuf, (int)(tnow.tv_usec/1000), pri, file, line, buf);
+	}
+		
 	/** @todo Make programmatic interface to logging */
 	if (priority != HAL_LOGPRI_TRACE && !syslog_enabled ) {
-		fprintf (stderr, "%s.%03d %s %s:%d: %s\n", tbuf, (int)(tnow.tv_usec/1000), pri, file, line, buf);
+		fprintf (stderr, "%s", logmsg );
 	} else if (priority != HAL_LOGPRI_TRACE && syslog_enabled ) {   
 		/* use syslog for debug/log messages if HAL started as daemon */
 		switch (priority) {
 			case HAL_LOGPRI_DEBUG:
 			case HAL_LOGPRI_INFO:
-				syslog(LOG_INFO, "%s.%03d %s %s:%d: %s\n", tbuf, (int)(tnow.tv_usec/1000), pri, file, line, buf );
-				break;			
+				syslog(LOG_INFO, "%s", logmsg );
+				break;
 			case HAL_LOGPRI_WARNING:
-				syslog(LOG_WARNING, "%s.%03d %s %s:%d: %s\n", tbuf, (int)(tnow.tv_usec/1000), pri, file, line, buf );
+				syslog(LOG_WARNING, "%s", logmsg );
 				break;
 			default:		 /* explicit fallthrough */
 			case HAL_LOGPRI_ERROR:
-				syslog(LOG_ERR, "%s.%03d %s %s:%d: %s\n", tbuf, (int)(tnow.tv_usec/1000), pri, file, line, buf );
+				syslog(LOG_ERR, "%s", logmsg );
 				break;
 		}
 	}
@@ -174,5 +206,37 @@ logger_emit (const char *format, ...)
 	va_end (args);
 }
 
+void
+//logger_forward_debug (const char *format, va_list args)
+logger_forward_debug (const char *format, ...)
+{
+	va_list args;
+        char buf[512];
+        char tbuf[256];
+        struct timeval tnow;
+        struct tm *tlocaltime;
+        struct timezone tzone;
+        static pid_t pid = -1;
+
+        if (!is_enabled)
+                return;
+
+        if ((int) pid == -1)
+                pid = getpid ();
+
+	va_start (args, format);
+        vsnprintf (buf, sizeof (buf), format, args);
+
+        gettimeofday (&tnow, &tzone);
+        tlocaltime = localtime (&tnow.tv_sec);
+        strftime (tbuf, sizeof (tbuf), "%H:%M:%S", tlocaltime);
+
+        if (syslog_enabled)
+                syslog (LOG_INFO, "%d: %s.%03d: %s", pid, tbuf, (int)(tnow.tv_usec/1000), buf);
+        else
+                fprintf (stderr, "%d: %s.%03d: %s", pid, tbuf, (int)(tnow.tv_usec/1000), buf);
+
+        va_end (args);
+}
 
 /** @} */
diff --git a/hald/logger.h b/hald/logger.h
index f88a58d..4bfc7d6 100644
--- a/hald/logger.h
+++ b/hald/logger.h
@@ -49,6 +49,8 @@ enum {
 void logger_setup (int priority, const char *file, int line, const char *function);
 
 void logger_emit (const char *format, ...);
+//void logger_forward_debug (const char *format, va_list args);
+void logger_forward_debug (const char *format, ...);
 
 void logger_enable (void);
 void logger_disable (void);
@@ -56,6 +58,8 @@ void logger_disable (void);
 void logger_enable_syslog (void);
 void logger_disable_syslog (void);
 
+void setup_logger (void);
+
 #ifdef __SUNPRO_C
 #define __FUNCTION__ __func__
 #endif
diff --git a/hald/util.c b/hald/util.c
index 8f3233b..e2cf5aa 100644
--- a/hald/util.c
+++ b/hald/util.c
@@ -48,167 +48,11 @@
 #include "osspec.h"
 #include "logger.h"
 #include "hald.h"
+#include "hald_runner.h"
+#include "hald_dbus.h"
 #include "device_info.h"
 
-#include "hald_dbus.h"
 #include "util.h"
-#include "hald_runner.h"
-
-typedef struct {
-	int last_level;
-	int last_chargeRate;
-	time_t last_time;
-} batteryInfo;
-
-GHashTable *saved_battery_info = NULL;
-
-/** Given all the required parameters, this function will return the percentage
- *  charge remaining. There are lots of checks here as ACPI is often broken.
- *
- *  @param  id                  Optional ID given to this battery. Unused at present.
- *  @param  chargeLevel         The current charge level of the battery (typically mWh)
- *  @param  chargeLastFull      The last "full" charge of the battery (typically mWh)
- *  @return                     Percentage, -1 if invalid
- */
-int 
-util_compute_percentage_charge (const char *id,
-			     int chargeLevel,
-			     int chargeLastFull)
-{
-	int percentage;
-	/* make sure we have chargelevel */
-	if (chargeLevel <= 0) {
-		HAL_WARNING (("chargeLevel %i, returning -1!", chargeLevel));
-		return -1;
-	}
-	/* make sure not division by zero */
-	if (chargeLastFull > 0)
-		percentage = ((double) chargeLevel / (double) chargeLastFull) * 100;
-	else {
-		HAL_WARNING (("chargeLastFull %i, percentage returning -1!", chargeLastFull));
-		return -1;
-	}
-	/* Some bios's will report this higher than 100, limit it here */
-	if (percentage > 100) {
-		HAL_WARNING (("Percentage %i, returning 100!", percentage));
-		return 100;
-	}
-	/* Something really isn't right if we get a negative... */
-	if (percentage < 0) {
-		HAL_WARNING (("Percentage %i, returning -1!", percentage));
-		return -1;
-	}
-	return percentage;
-}
-
-/** Given all the required parameters, this function will return the number 
- *  of seconds until the battery is charged (if charging) or the number
- *  of seconds until empty (if discharging)
- *
- *  @param  id                  Optional ID given to this battery. Unused at present.
- *  @param  chargeRate          The "rate" (typically mW)
- *  @param  chargeLevel         The current charge level of the battery (typically mWh)
- *  @param  chargeLastFull      The last "full" charge of the battery (typically mWh)
- *  @param  isDischarging       If battery is discharging
- *  @param  isCharging          If battery is charging
- *  @param  guessChargeRate     If ignore chargeRate and guess them.
- *  @return                     Number of seconds, or -1 if invalid
- */
-int 
-util_compute_time_remaining (const char *id,
-			     int chargeRate,
-			     int chargeLevel,
-			     int chargeLastFull,
-			     gboolean isDischarging,
-			     gboolean isCharging,
-			     gboolean guessChargeRate)
-{
-	int remaining_time = 0;
-
-	/* should not get negative values */
-	if (chargeRate < 0 || chargeLevel < 0 || chargeLastFull < 0) {
-		HAL_WARNING (("chargeRate, chargeLevel or chargeLastFull < 0, returning -1"));
-		return -1;
-	}
-	/* batteries cannot charge and discharge at the same time */
-	if (isDischarging && isCharging) {
-		HAL_WARNING (("isDischarging & isCharging TRUE, returning -1"));
-		return -1;
-	}
-	/* 
-	 * Some laptops don't supply any rate info, but that's no reason for HAL not
-	 * to. We use the current and previous chargeLevel to estimate the rate.
-	 * The info is stored in a GHashTable because there could be more than one battery.
-	 */
-	if (chargeRate == 0 || guessChargeRate) {
-		batteryInfo *battery_info;
-		time_t cur_time = time(NULL);
-
-		/* Initialize the save_battery_info GHashTable */
-		if (!saved_battery_info) 
-			saved_battery_info = g_hash_table_new(g_str_hash, g_str_equal);
-
-		if ((battery_info = g_hash_table_lookup(saved_battery_info, id))) {
-			/* check this to prevent division by zero */
-			if ((cur_time == battery_info->last_time) || (chargeLevel == battery_info->last_level)) {
-				/* if we can't calculate because nothing changed, use last 
-				 * chargeRate to prevent removing battery.remaining_time.
-				 */
-				chargeRate = battery_info->last_chargeRate;
-			} else {
-				chargeRate = ((chargeLevel - battery_info->last_level) * 60 * 60) / (cur_time - battery_info->last_time);
-				/*
-				 * During discharging chargeRate would be negative, which would
-				 * mess up the the calculation below, so we make sure it's always
-				 * positive.
-				 */ 
-				chargeRate = (chargeRate > 0) ? chargeRate : -chargeRate;
-	
-				battery_info->last_level = chargeLevel;
-				battery_info->last_time = cur_time;
-				battery_info->last_chargeRate = chargeRate;
-			}
-		} else {
-			battery_info = g_new0(batteryInfo, 1);
-			g_hash_table_insert(saved_battery_info, (char*) id, battery_info);
-
-			battery_info->last_level = chargeLevel;
-			battery_info->last_time = cur_time;
-			battery_info->last_chargeRate = 0;
- 			return -1;
-		}
-	} 
-
-	if (chargeRate == 0)
-		return -1;
-
-	if (isDischarging) { 
-		remaining_time = ((double) chargeLevel / (double) chargeRate) * 60 * 60;
-	} else if (isCharging) {
-		/* 
-		 * Some ACPI BIOS's don't update chargeLastFull, 
-		 * so return 0 as we don't know how much more there is left
-		 */
-		if (chargeLevel > chargeLastFull ) {
-			HAL_WARNING (("chargeLevel > chargeLastFull, returning -1"));
-			return -1;
-		}
-		remaining_time = ((double) (chargeLastFull - chargeLevel) / (double) chargeRate) * 60 * 60;
-	}
-	
-	/* This shouldn't happen, but check for completeness */
-	if (remaining_time < 0) {
-		HAL_WARNING (("remaining_time %i, returning -1", remaining_time));
-		remaining_time = -1;
-	}
-	/* Battery life cannot be above 60 hours */
-	else if (remaining_time > 60*60*60) {
-		HAL_WARNING (("remaining_time *very* high, returning -1"));
-		remaining_time = -1;
-	}
-
-	return remaining_time;
-}
 
 gboolean 
 hal_util_remove_trailing_slash (gchar *path)
@@ -1072,6 +916,7 @@ hal_util_strdup_valid_utf8 (const char *
 {
 	char *endchar;
 	char *newstr;
+	unsigned int count = 0;
 
 	if (str == NULL)
 		return NULL;
@@ -1080,8 +925,13 @@ hal_util_strdup_valid_utf8 (const char *
 
 	while (!g_utf8_validate (newstr, -1, (const char **) &endchar)) {
 		*endchar = '?';
+		count++;
 	}
-	return newstr;
+	
+	if (strlen(newstr) == count)
+		return NULL;
+	else
+		return newstr;
 }
 
 void
@@ -1240,3 +1090,5 @@ out:
 
 	return found;
 }
+
+
diff --git a/hald/util.h b/hald/util.h
index 98d0ea3..b410453 100644
--- a/hald/util.h
+++ b/hald/util.h
@@ -41,11 +41,6 @@
 #define HAL_PATH_MAX 512
 #define HAL_HELPER_TIMEOUT 10000
 
-int util_compute_time_remaining (const char *id, int chargeRate, int chargeLevel, int chargeLastFull, 
-				 gboolean isDischarging, gboolean isCharging, gboolean guessChargeRate);
-
-int util_compute_percentage_charge (const char *id, int chargeLevel, int chargeLastFull);
-
 gboolean hal_util_remove_trailing_slash (gchar *path);
 
 const gchar *hal_util_get_last_element (const gchar *s);
diff --git a/hald/util_helper.c b/hald/util_helper.c
new file mode 100644
index 0000000..5a83d8b
--- /dev/null
+++ b/hald/util_helper.c
@@ -0,0 +1,143 @@
+/***************************************************************************
+ *
+ * util_helper.c - HAL utilities for helper (as e.g. prober/addons) et al. 
+ *
+ * Copyright (C) 2006 David Zeuthen, <david at fubar.dk>
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ **************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <grp.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
+#include <time.h>
+#include <pwd.h>
+#include <unistd.h>
+
+#include "logger.h"
+
+#include "util_helper.h"
+
+#ifdef __linux__
+extern char **environ;
+#endif
+
+static char **argv_buffer = NULL;
+static size_t argv_size = 0;
+
+/** Drop root privileges: Set the running user id to HAL_USER and
+ *  group to HAL_GROUP, and optionally retain auxiliary groups of HAL_USER.
+ */
+void
+drop_privileges (int keep_auxgroups)
+{
+	struct passwd *pw = NULL;
+	struct group *gr = NULL;
+
+	/* determine user id */
+	pw = getpwnam (HAL_USER);
+	if (!pw)  {
+		HAL_DEBUG (("drop_privileges: user " HAL_USER " does not exist"));
+		exit (-1);
+	}
+
+	/* determine primary group id */
+	gr = getgrnam (HAL_GROUP);
+	if (!gr) {
+		HAL_DEBUG (("drop_privileges: group " HAL_GROUP " does not exist"));
+		exit (-1);
+	}
+
+	if (keep_auxgroups) {
+		if (initgroups (HAL_USER, gr->gr_gid)) {
+			HAL_DEBUG(("drop_privileges: could not initialize groups"));
+			exit (-1);
+		}
+	}
+
+	if (setgid (gr->gr_gid)) {
+		HAL_DEBUG (("drop_privileges: could not set group id"));
+		exit (-1);
+	}
+
+	if (setuid (pw->pw_uid)) {
+		HAL_DEBUG (("drop_privileges: could not set user id"));
+		exit (-1);
+	}
+}
+
+void
+hal_set_proc_title_init (int argc, char *argv[])
+{
+#ifdef __linux__
+	unsigned int i;
+	char **new_environ, *endptr;
+
+	/* This code is really really ugly. We make some memory layout
+	 * assumptions and reuse the environment array as memory to store
+	 * our process title in */
+	
+	for (i = 0; environ[i] != NULL; i++)
+		;
+	
+	endptr = i ? environ[i-1] + strlen (environ[i-1]) : argv[argc-1] + strlen (argv[argc-1]);
+	
+	argv_buffer = argv;
+	argv_size = endptr - argv_buffer[0];
+	
+	/* Make a copy of environ */
+	
+	new_environ = malloc (sizeof(char*) * (i + 1));
+	for (i = 0; environ[i] != NULL; i++)
+		new_environ[i] = strdup (environ[i]);
+	new_environ[i] = NULL;
+	
+	environ = new_environ;
+#endif
+}
+
+/* this code borrowed from avahi-daemon's setproctitle.c (LGPL v2) */
+void
+hal_set_proc_title (const char *format, ...)
+{
+#ifdef __linux__
+	size_t len;
+	va_list ap;
+
+	if (argv_buffer == NULL)
+		goto out;
+		
+	va_start (ap, format);
+	vsnprintf (argv_buffer[0], argv_size, format, ap);
+	va_end (ap);
+ 	
+	len = strlen (argv_buffer[0]);
+ 	   
+	memset (argv_buffer[0] + len, 0, argv_size - len);
+	argv_buffer[1] = NULL;
+out:
+	;
+#endif
+}
+
diff --git a/hald/util_helper.h b/hald/util_helper.h
new file mode 100644
index 0000000..b9309f4
--- /dev/null
+++ b/hald/util_helper.h
@@ -0,0 +1,33 @@
+/***************************************************************************
+ *
+ * util_helper.h - HAL utilities for helper (as e.g. prober/addons) et al.
+ *
+ * Copyright (C) 2006 David Zeuthen, <david at fubar.dk>
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ **************************************************************************/
+
+
+#ifndef UTIL_HELPER_H
+#define UTIL_HELPER_H
+
+void drop_privileges (int keep_auxgroups);
+void hal_set_proc_title_init (int argc, char *argv[]);
+void hal_set_proc_title (const char *format, ...);
+
+#endif /* UTIL_HELPER_H */
diff --git a/hald/util_pm.c b/hald/util_pm.c
new file mode 100644
index 0000000..6b613b1
--- /dev/null
+++ b/hald/util_pm.c
@@ -0,0 +1,194 @@
+/***************************************************************************
+ * CVSID: $Id$
+ *
+ * utili_pm.c - Various Powermanagement related utilities
+ *
+ * Copyright (C) 2005 Richard Hughes <richard at hughsie.com>
+ * Copyright (C) 2005 Danny Kukawka <danny.kukawka at web.de>
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ **************************************************************************/
+
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+#include <ctype.h>
+#include <stdint.h>
+
+#include <glib.h>
+
+#include "logger.h"
+
+#include "util_pm.h"
+
+typedef struct {
+	int last_level;
+	int last_chargeRate;
+	time_t last_time;
+} batteryInfo;
+
+GHashTable *saved_battery_info = NULL;
+
+/** Given all the required parameters, this function will return the percentage
+ *  charge remaining. There are lots of checks here as ACPI is often broken.
+ *
+ *  @param  id                  Optional ID given to this battery. Unused at present.
+ *  @param  chargeLevel         The current charge level of the battery (typically mWh)
+ *  @param  chargeLastFull      The last "full" charge of the battery (typically mWh)
+ *  @return                     Percentage, -1 if invalid
+ */
+int 
+util_compute_percentage_charge (const char *id,
+			     int chargeLevel,
+			     int chargeLastFull)
+{
+	int percentage;
+	/* make sure we have chargelevel */
+	if (chargeLevel <= 0) {
+		HAL_WARNING (("chargeLevel %i, returning -1!", chargeLevel));
+		return -1;
+	}
+	/* make sure not division by zero */
+	if (chargeLastFull > 0)
+		percentage = ((double) chargeLevel / (double) chargeLastFull) * 100;
+	else {
+		HAL_WARNING (("chargeLastFull %i, percentage returning -1!", chargeLastFull));
+		return -1;
+	}
+	/* Some bios's will report this higher than 100, limit it here */
+	if (percentage > 100) {
+		HAL_WARNING (("Percentage %i, returning 100!", percentage));
+		return 100;
+	}
+	/* Something really isn't right if we get a negative... */
+	if (percentage < 0) {
+		HAL_WARNING (("Percentage %i, returning -1!", percentage));
+		return -1;
+	}
+	return percentage;
+}
+
+/** Given all the required parameters, this function will return the number 
+ *  of seconds until the battery is charged (if charging) or the number
+ *  of seconds until empty (if discharging)
+ *
+ *  @param  id                  Optional ID given to this battery. Unused at present.
+ *  @param  chargeRate          The "rate" (typically mW)
+ *  @param  chargeLevel         The current charge level of the battery (typically mWh)
+ *  @param  chargeLastFull      The last "full" charge of the battery (typically mWh)
+ *  @param  isDischarging       If battery is discharging
+ *  @param  isCharging          If battery is charging
+ *  @param  guessChargeRate     If ignore chargeRate and guess them.
+ *  @return                     Number of seconds, or -1 if invalid
+ */
+int 
+util_compute_time_remaining (const char *id,
+			     int chargeRate,
+			     int chargeLevel,
+			     int chargeLastFull,
+			     gboolean isDischarging,
+			     gboolean isCharging,
+			     gboolean guessChargeRate)
+{
+	int remaining_time = 0;
+
+	/* should not get negative values */
+	if (chargeRate < 0 || chargeLevel < 0 || chargeLastFull < 0) {
+		HAL_WARNING (("chargeRate, chargeLevel or chargeLastFull < 0, returning -1"));
+		return -1;
+	}
+	/* batteries cannot charge and discharge at the same time */
+	if (isDischarging && isCharging) {
+		HAL_WARNING (("isDischarging & isCharging TRUE, returning -1"));
+		return -1;
+	}
+	/* 
+	 * Some laptops don't supply any rate info, but that's no reason for HAL not
+	 * to. We use the current and previous chargeLevel to estimate the rate.
+	 * The info is stored in a GHashTable because there could be more than one battery.
+	 */
+	if (chargeRate == 0 || guessChargeRate) {
+		batteryInfo *battery_info;
+		time_t cur_time = time(NULL);
+
+		/* Initialize the save_battery_info GHashTable */
+		if (!saved_battery_info) 
+			saved_battery_info = g_hash_table_new(g_str_hash, g_str_equal);
+
+		if ((battery_info = g_hash_table_lookup(saved_battery_info, id))) {
+			/* check this to prevent division by zero */
+			if ((cur_time == battery_info->last_time) || (chargeLevel == battery_info->last_level)) {
+				/* if we can't calculate because nothing changed, use last 
+				 * chargeRate to prevent removing battery.remaining_time.
+				 */
+				chargeRate = battery_info->last_chargeRate;
+			} else {
+				chargeRate = ((chargeLevel - battery_info->last_level) * 60 * 60) / (cur_time - battery_info->last_time);
+				/*
+				 * During discharging chargeRate would be negative, which would
+				 * mess up the the calculation below, so we make sure it's always
+				 * positive.
+				 */ 
+				chargeRate = (chargeRate > 0) ? chargeRate : -chargeRate;
+	
+				battery_info->last_level = chargeLevel;
+				battery_info->last_time = cur_time;
+				battery_info->last_chargeRate = chargeRate;
+			}
+		} else {
+			battery_info = g_new0(batteryInfo, 1);
+			g_hash_table_insert(saved_battery_info, (char*) id, battery_info);
+
+			battery_info->last_level = chargeLevel;
+			battery_info->last_time = cur_time;
+			battery_info->last_chargeRate = 0;
+ 			return -1;
+		}
+	} 
+
+	if (chargeRate == 0)
+		return -1;
+
+	if (isDischarging) { 
+		remaining_time = ((double) chargeLevel / (double) chargeRate) * 60 * 60;
+	} else if (isCharging) {
+		/* 
+		 * Some ACPI BIOS's don't update chargeLastFull, 
+		 * so return 0 as we don't know how much more there is left
+		 */
+		if (chargeLevel > chargeLastFull ) {
+			HAL_WARNING (("chargeLevel > chargeLastFull, returning -1"));
+			return -1;
+		}
+		remaining_time = ((double) (chargeLastFull - chargeLevel) / (double) chargeRate) * 60 * 60;
+	}
+	
+	/* This shouldn't happen, but check for completeness */
+	if (remaining_time < 0) {
+		HAL_WARNING (("remaining_time %i, returning -1", remaining_time));
+		remaining_time = -1;
+	}
+	/* Battery life cannot be above 60 hours */
+	else if (remaining_time > 60*60*60) {
+		HAL_WARNING (("remaining_time *very* high, returning -1"));
+		remaining_time = -1;
+	}
+
+	return remaining_time;
+}
+
diff --git a/hald/util_pm.h b/hald/util_pm.h
new file mode 100644
index 0000000..92ddef4
--- /dev/null
+++ b/hald/util_pm.h
@@ -0,0 +1,35 @@
+/***************************************************************************
+ * CVSID: $Id$
+ *
+ * util_pm.h - Various Powermanagement related  utilities
+ *
+ * Copyright (C) 2005 Richard Hughes <richard at hughsie.com>
+ * Copyright (C) 2005 Danny Kukawka <danny.kukawka at web.de>
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ **************************************************************************/
+
+#ifndef UTIL_PM_H
+#define UTIL_PM_H
+
+int util_compute_time_remaining (const char *id, int chargeRate, int chargeLevel, int chargeLastFull, 
+				 gboolean isDischarging, gboolean isCharging, gboolean guessChargeRate);
+
+int util_compute_percentage_charge (const char *id, int chargeLevel, int chargeLastFull);
+
+#endif /* UTIL__PM_H */



More information about the hal-commit mailing list