diff options
author | Danny Kukawka <danny.kukawka@web.de> | 2006-08-21 20:16:07 +0200 |
---|---|---|
committer | Danny Kukawka <danny.kukawka@web.de> | 2006-08-21 20:16:07 +0200 |
commit | 9f92b65ab9398476afc53e70a2173de53f2b4495 (patch) | |
tree | 7249cf396a2217dd320c7a70aa3d39ed985b3e3c /hald/linux2 | |
parent | 5c3da435c0e367266e9d7d5be28d72117bb77541 (diff) |
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)
Diffstat (limited to 'hald/linux2')
-rw-r--r-- | hald/linux2/acpi.c | 1 | ||||
-rw-r--r-- | hald/linux2/addons/Makefile.am | 57 | ||||
-rw-r--r-- | hald/linux2/addons/addon-acpi-buttons-toshiba.c | 23 | ||||
-rw-r--r-- | hald/linux2/addons/addon-acpi.c | 32 | ||||
-rw-r--r-- | hald/linux2/addons/addon-hid-ups.c | 9 | ||||
-rw-r--r-- | hald/linux2/addons/addon-keyboard.c | 6 | ||||
-rw-r--r-- | hald/linux2/addons/addon-macbookpro-backlight.c | 29 | ||||
-rw-r--r-- | hald/linux2/addons/addon-pmu.c | 15 | ||||
-rw-r--r-- | hald/linux2/addons/addon-storage.c | 51 | ||||
-rw-r--r-- | hald/linux2/addons/addon-usb-csr.c | 47 | ||||
-rw-r--r-- | hald/linux2/apm.c | 1 | ||||
-rw-r--r-- | hald/linux2/ids.c | 69 | ||||
-rw-r--r-- | hald/linux2/pmu.c | 1 | ||||
-rw-r--r-- | hald/linux2/probing/Makefile.am | 16 | ||||
-rw-r--r-- | hald/linux2/probing/probe-input.c | 27 | ||||
-rw-r--r-- | hald/linux2/probing/probe-pc-floppy.c | 16 | ||||
-rw-r--r-- | hald/linux2/probing/probe-printer.c | 24 | ||||
-rw-r--r-- | hald/linux2/probing/probe-serial.c | 23 | ||||
-rw-r--r-- | hald/linux2/probing/probe-smbios.c | 15 | ||||
-rw-r--r-- | hald/linux2/probing/probe-storage.c | 68 | ||||
-rw-r--r-- | hald/linux2/probing/probe-volume.c | 84 | ||||
-rw-r--r-- | hald/linux2/probing/shared.h | 174 |
22 files changed, 304 insertions, 484 deletions
diff --git a/hald/linux2/acpi.c b/hald/linux2/acpi.c index 3751573d..4274d77e 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 33cdd9cd..19c229d7 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 908cf4ec..7252759e 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 220d71d7..4b193212 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 *eventfp) 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 *eventfp) 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 *eventfp) 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 4a47db22..1361ed6d 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 29afcb0e..a054ac97 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 c97211bb..f25a555a 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 2cbacce6..68b59fe9 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 83f44285..1660abcd 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 char *udi) "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 char *udi) 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 *ctx, const char *udi) 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, const char *udi) 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, const char *udi) 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, const char *udi) 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 4ddc7821..cd1747dc 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_device_udi) 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_udi, PropertyCacheItem *pci) 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, PropertyCacheItem *pci) 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, PropertyCacheItem *pci) /* 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, PropertyCacheItem *pci) 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, const char *hal_device_udi) { /* 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 fc417ae3..e8554382 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 35dcec2a..7cb41f30 100644 --- a/hald/linux2/ids.c +++ b/hald/linux2/ids.c @@ -258,6 +258,21 @@ ids_find_pci (int vendor_id, int product_id, } } +/** 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_id, } } +/** 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 901e48eb..892fff14 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 d50f44e5..a9f0342e 100644 --- a/hald/linux2/probing/Makefile.am +++ b/hald/linux2/probing/Makefile.am @@ -13,27 +13,27 @@ libexec_PROGRAMS = hald-probe-input hald-probe-hiddev hald-probe-storage hald-pr 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 0c921ac3..6a18990d 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, const char *udi) 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, const char *udi) 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, const char *udi) 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 0a48c846..7a66987e 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 0da9c603..bec6e9bb 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 3f53ef2c..b70f82ba 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 6e20a684..2beb8096 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 9bfbbb0a..1847fcb9 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 char *file, int line, const char *format 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 b70bd55f..318ee46c 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 char *file, int line, const char *format 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, const char *udi, LibHalChangeSet *chan } 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, const char *udi, LibHalChangeSet *chan 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, const char *udi, LibHalChangeSet *chan 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, const char *udi, LibHalChangeSet *chan 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, const char *udi, LibHalChangeSet *chan /* 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, const char *udi, LibHalChangeSet *chan 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, const char *udi, LibHalChangeSet *chan 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 3805b717..00000000 --- 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 */ |