1 diff --git a/configure.in b/configure.in
2 index 0b6734c..647c0c6 100644
5 @@ -46,20 +46,10 @@ AC_ARG_WITH([pid-file],
6 AS_HELP_STRING([--with-pid-file=<file>],
7 [PID file for HAL daemon]))
10 - AS_HELP_STRING([--with-hwdata=<dir>],
11 - [Where PCI and USB IDs are found]))
12 -AC_ARG_WITH([pci-ids],
13 - AS_HELP_STRING([--with-pci-ids=<dir>],
14 - [Where PCI IDs are found (overrides --with-hwdata)]))
15 AC_ARG_WITH([usb-ids],
16 AS_HELP_STRING([--with-usb-ids=<dir>],
17 [Where USB IDs are found (overrides --with-hwdata)]))
19 -AC_ARG_ENABLE([pci-ids],
20 - AS_HELP_STRING([--disable-pci-ids],
21 - [Do not build with PCI IDs support]),
22 - [enable_pci_ids=$enableval], [enable_pci_ids=yes])
23 AC_ARG_ENABLE([usb-ids],
24 AS_HELP_STRING([--disable-usb-ids],
25 [Do not build with USB IDs support]),
26 @@ -73,34 +63,10 @@ AC_ARG_WITH([socket-dir],
27 AS_HELP_STRING([--with-socket-dir=<dir>],
28 [Location of the HAL D-BUS listening sockets (auto)]))
30 -if ! test -z "$with_hwdata" ; then
31 - PCI_IDS_DIR="$with_hwdata"
32 - USB_IDS_DIR="$with_hwdata"
34 -if ! test -z "$with_pci_ids" ; then
35 - PCI_IDS_DIR="$with_pci_ids"
37 if ! test -z "$with_usb_ids" ; then
38 USB_IDS_DIR="$with_usb_ids"
41 -if test "x$enable_pci_ids" = "xno" ; then
44 - if test -z "$PCI_IDS_DIR"; then
45 - for dir in /usr/share/hwdata /usr/share/misc /usr/share /var/lib/misc; do
46 - AC_CHECK_FILE([$dir/pci.ids], [PCI_IDS_DIR=$dir])
48 - if test -z "$PCI_IDS_DIR"; then
49 - AC_MSG_ERROR([cannot find pci.ids. Use --with-pci-ids to specify location])
51 - AC_MSG_WARN([autodetected pci.ids in $PCI_IDS_DIR])
55 - AC_DEFINE([USE_PCI_IDS], [1], [Whether pci.ids is to be used])
58 if test "x$enable_usb_ids" = "xno" ; then
61 @@ -125,9 +91,7 @@ else
62 AC_DEFINE([USE_PNP_IDS], [1], [Whether builtin PNP IDs are to be used])
65 -AC_SUBST(PCI_IDS_DIR)
67 -AC_SUBST(USE_PCI_IDS)
71 @@ -422,11 +386,13 @@ AC_ARG_WITH([libpci],
72 [], [with_libpci=yes])
76 if test "x$with_libpci" != xno ; then
78 AC_CHECK_HEADERS([pci/pci.h],
79 - [AC_CHECK_LIB([pci], [pci_init], [USE_LIBPCI="yes"], [], [-lz])])
81 + [AC_CHECK_LIB([pci], [pci_init], [USE_LIBPCI="yes" PCI_LIBS="-lpci -lz"], [], [-lz])])
84 AM_CONDITIONAL([HAVE_LIBPCI], [test "x$USE_LIBPCI" = "xyes"])
86 AC_ARG_WITH([backend],
87 @@ -979,7 +945,6 @@ echo "
88 localstatedir: ${localstatedir}
90 dbus-1 system.d dir: ${DBUS_SYS_DIR}
91 - pci.ids dir: ${PCI_IDS_DIR}
92 usb.ids dir: ${USB_IDS_DIR}
95 diff --git a/hald/Makefile.am b/hald/Makefile.am
96 index ea396f6..fbf2d5d 100644
97 --- a/hald/Makefile.am
98 +++ b/hald/Makefile.am
99 @@ -12,7 +12,6 @@ AM_CPPFLAGS = \
100 -DPACKAGE_SCRIPT_DIR=\""$(libdir)/hal/scripts"\" \
101 -DHALD_SOCKET_DIR=\""$(HALD_SOCKET_DIR)"\" \
102 -DHALD_PID_FILE=\""$(HALD_PID_FILE)"\" \
103 - -DPCI_IDS_DIR=\""$(PCI_IDS_DIR)"\" \
104 -DUSB_IDS_DIR=\""$(USB_IDS_DIR)"\" \
106 @GLIB_CFLAGS@ @DBUS_CFLAGS@ @POLKIT_CFLAGS@
107 @@ -73,7 +72,7 @@ if HAVE_CONKIT
108 hald_SOURCES += ck-tracker.h ck-tracker.c
111 -hald_LDADD = @GLIB_LIBS@ @DBUS_LIBS@ @POLKIT_LIBS@ -lm @HALD_OS_LIBS@ $(top_builddir)/hald/$(HALD_BACKEND)/libhald_$(HALD_BACKEND).la
112 +hald_LDADD = @PCI_LIBS@ @GLIB_LIBS@ @DBUS_LIBS@ @POLKIT_LIBS@ -lm @HALD_OS_LIBS@ $(top_builddir)/hald/$(HALD_BACKEND)/libhald_$(HALD_BACKEND).la
114 #### Init scripts fun
115 SCRIPT_IN_FILES=haldaemon.in
116 diff --git a/hald/ids.c b/hald/ids.c
117 index 9949eab..b8dc344 100644
125 -/** Pointer to where the pci.ids file is loaded */
126 -static char *pci_ids = NULL;
128 -/** Length of data store at at pci_ids */
129 -static size_t pci_ids_len;
132 -/** Iterator position into pci_ids */
133 -static size_t pci_ids_iter_pos;
134 +#include <pci/pci.h>
136 -/** Initialize the pci.ids line iterator to the beginning of the file */
138 -pci_ids_line_iter_init ()
140 - pci_ids_iter_pos = 0;
142 +/** Pointer to where the pci.ids file is loaded */
143 +static struct pci_access *pacc = NULL;
145 /** Maximum length of lines in pci.ids */
146 #define PCI_IDS_MAX_LINE_LEN 512
149 - * pci_ids_line_iter_get_line:
150 - * @line_len: Pointer to where number of bytes in line will
152 - * Returns: Pointer to the line; only valid until the
153 - * next invocation of this function
155 - * Get the next line from pci.ids
158 -pci_ids_line_iter_get_line (unsigned int *line_len)
161 - static char line[PCI_IDS_MAX_LINE_LEN];
164 - pci_ids_iter_pos < pci_ids_len &&
165 - i < PCI_IDS_MAX_LINE_LEN - 1 &&
166 - pci_ids[pci_ids_iter_pos] != '\n'; i++, pci_ids_iter_pos++) {
167 - line[i] = pci_ids[pci_ids_iter_pos];
171 - if (line_len != NULL)
174 - pci_ids_iter_pos++;
180 - * pci_ids_line_iter_has_more:
182 - * Returns: #TRUE iff there are more lines to process
184 - * See if there are more lines to process in pci.ids
187 -pci_ids_line_iter_has_more ()
189 - return pci_ids_iter_pos < pci_ids_len;
196 * @vendor_id: PCI vendor id or 0 if unknown
197 * @product_id: PCI product id or 0 if unknown
198 @@ -131,199 +76,64 @@ ids_find_pci (int vendor_id, int product_id,
199 char **vendor_name, char **product_name,
200 char **subsys_vendor_name, char **subsys_product_name)
204 - unsigned int line_len;
205 - unsigned int num_tabs;
210 - dbus_bool_t vendor_matched = FALSE;
211 - dbus_bool_t product_matched = FALSE;
212 static char store_vn[PCI_IDS_MAX_LINE_LEN];
213 static char store_pn[PCI_IDS_MAX_LINE_LEN];
214 static char store_svn[PCI_IDS_MAX_LINE_LEN];
215 static char store_spn[PCI_IDS_MAX_LINE_LEN];
217 - snprintf (rep_vi, 8, "%04x", vendor_id);
218 - snprintf (rep_pi, 8, "%04x", product_id);
219 - snprintf (rep_svi, 8, "%04x", subsys_vendor_id);
220 - snprintf (rep_spi, 8, "%04x", subsys_product_id);
223 *product_name = NULL;
224 *subsys_vendor_name = NULL;
225 *subsys_product_name = NULL;
227 - for (pci_ids_line_iter_init (); pci_ids_line_iter_has_more ();) {
228 - line = pci_ids_line_iter_get_line (&line_len);
230 - /* skip lines with no content */
234 - /* skip comments */
235 - if (line[0] == '#')
238 - /* count number of tabs */
240 - for (i = 0; i < line_len; i++) {
241 - if (line[i] != '\t')
246 - switch (num_tabs) {
249 - vendor_matched = FALSE;
251 - /* first check subsys_vendor_id, if haven't done
253 - if (*subsys_vendor_name == NULL
254 - && subsys_vendor_id != 0) {
255 - if ((*((dbus_uint32_t *) line)) ==
256 - (*((dbus_uint32_t *) rep_svi))) {
258 - for (i = 4; i < line_len; i++) {
259 - if (!isspace (line[i]))
262 - strncpy (store_svn, line + i,
263 - PCI_IDS_MAX_LINE_LEN);
264 - *subsys_vendor_name = store_svn;
268 - /* check vendor_id */
269 - if (vendor_id != 0) {
270 - if (memcmp (line, rep_vi, 4) == 0) {
272 - vendor_matched = TRUE;
274 - for (i = 4; i < line_len; i++) {
275 - if (!isspace (line[i]))
278 - strncpy (store_vn, line + i,
279 - PCI_IDS_MAX_LINE_LEN);
280 - *vendor_name = store_vn;
287 - product_matched = FALSE;
289 - /* product names */
290 - if (!vendor_matched)
293 - /* check product_id */
294 - if (product_id != 0) {
295 - if (memcmp (line + 1, rep_pi, 4) == 0) {
298 - product_matched = TRUE;
300 - for (i = 5; i < line_len; i++) {
301 - if (!isspace (line[i]))
304 - strncpy (store_pn, line + i,
305 - PCI_IDS_MAX_LINE_LEN);
306 - *product_name = store_pn;
312 - /* subsystem_vendor subsystem_product */
313 - if (!vendor_matched || !product_matched)
316 - /* check product_id */
317 - if (subsys_vendor_id != 0
318 - && subsys_product_id != 0) {
319 - if (memcmp (line + 2, rep_svi, 4) == 0
320 - && memcmp (line + 7, rep_spi,
323 - for (i = 11; i < line_len; i++) {
324 - if (!isspace (line[i]))
327 - strncpy (store_spn, line + i,
328 - PCI_IDS_MAX_LINE_LEN);
329 - *subsys_product_name = store_spn;
340 + if (vendor_id == 0)
342 + *vendor_name = pci_lookup_name (pacc, store_vn, sizeof(store_vn),
343 + PCI_LOOKUP_VENDOR, vendor_id, product_id);
344 + if (*vendor_name == NULL)
347 + if (product_id == 0)
349 + *product_name = pci_lookup_name (pacc, store_pn, sizeof(store_pn),
350 + PCI_LOOKUP_DEVICE, vendor_id, product_id);
351 + if (*product_name == NULL)
354 + if (subsys_vendor_id == 0)
356 + *subsys_vendor_name = pci_lookup_name (pacc, store_svn, sizeof(store_svn),
357 + PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, subsys_vendor_id);
358 + if (*subsys_vendor_name == NULL)
361 + if (subsys_product_id == 0)
363 + *subsys_product_name = pci_lookup_name (pacc, store_spn, sizeof(store_spn),
364 + PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_DEVICE, subsys_vendor_id, subsys_product_id);
365 + if (*subsys_product_name == NULL)
372 - * @path: Path of the pci.ids file, e.g. /usr/share/hwdata/pci.ids
374 - * Returns: #TRUE if the file was succesfully loaded
376 - * Load the PCI database used for mapping vendor, product, subsys_vendor
377 - * and subsys_product numbers into names.
380 -pci_ids_load (const char *path)
382 +pci_ids_error (char *msg, ...)
385 - struct stat statbuf;
390 - if (stat (path, &statbuf) != 0) {
391 - HAL_WARNING (("Couldn't stat pci.ids file '%s', errno=%d: %s", path, errno, strerror (errno)));
394 - pci_ids_len = statbuf.st_size;
396 - fd = open (path, O_RDONLY);
398 - HAL_WARNING (("Couldn't open pci.ids file '%s', errno=%d: %s", path, errno, strerror (errno)));
402 - pci_ids = mmap (NULL, pci_ids_len, PROT_READ, MAP_SHARED, fd, 0);
403 - if (pci_ids == MAP_FAILED) {
404 - HAL_WARNING (("Couldn't mmap pci.ids file '%s', errno=%d: %s", path, errno, strerror (errno)));
415 + va_start (args, msg);
416 + logger_setup (HAL_LOGPRI_ERROR, __FILE__, __LINE__, __FUNCTION__);
417 + logger_emit_var (msg, args);
424 - /* Load /usr/share/hwdata/pci.ids */
425 - pci_ids_load (PCI_IDS_DIR "/pci.ids");
426 + pacc = pci_alloc();
427 + pacc->error = pci_ids_error;
431 -#endif /*USE_PCI_IDS*/
434 /*==========================================================================*/
436 diff --git a/hald/ids.h b/hald/ids.h
437 index 7773211..e0a8679 100644
447 void pci_ids_init (void);
449 @@ -38,7 +38,7 @@ ids_find_pci (int vendor_id, int product_id,
450 char **vendor_name, char **product_name,
451 char **subsys_vendor_name, char **subsys_product_name);
453 -#else /*USE_PCI_IDS*/
455 static inline void pci_ids_init (void) {return;};
458 @@ -46,7 +46,7 @@ ids_find_pci (int vendor_id, int product_id,
459 int subsys_vendor_id, int subsys_product_id,
460 char **vendor_name, char **product_name,
461 char **subsys_vendor_name, char **subsys_product_name) {return;}
462 -#endif /*USE_PCI_IDS*/
467 diff --git a/hald/logger.c b/hald/logger.c
468 index a2d04b5..c23ea71 100644
471 @@ -138,16 +138,15 @@ logger_setup (int _priority, const char *_file, int _line, const char *_function
477 * @format: Message format string, printf style
478 - * @...: Parameters for message, printf style
479 + * @args: Parameters for message, vprintf style
484 -logger_emit (const char *format, ...)
485 +logger_emit_var (const char *format, va_list args)
491 @@ -160,7 +159,6 @@ logger_emit (const char *format, ...)
495 - va_start (args, format);
496 vsnprintf (buf, sizeof (buf), format, args);
499 @@ -213,7 +211,21 @@ logger_emit (const char *format, ...)
507 + * @format: Message format string, printf style
508 + * @...: Parameters for message, printf style
510 + * Emit logging entry
513 +logger_emit (const char *format, ...)
516 + va_start (args, format);
517 + logger_emit_var (format, args);
521 diff --git a/hald/logger.h b/hald/logger.h
522 index f32216c..dd55eb5 100644
525 @@ -30,6 +30,7 @@ extern "C" {
533 @@ -45,6 +46,7 @@ enum {
534 void logger_setup (int priority, const char *file, int line, const char *function);
536 void logger_emit (const char *format, ...);
537 +void logger_emit_var (const char *format, va_list args);
538 /* void logger_forward_debug (const char *format, va_list args); */
539 void logger_forward_debug (const char *format, ...);
541 @@ -72,7 +74,7 @@ void setup_logger (void);
542 /** Warning level logging macro */
543 #define HAL_WARNING(expr) do {logger_setup(HAL_LOGPRI_WARNING, __FILE__, __LINE__, __FUNCTION__); logger_emit expr; } while(0)
545 -/** Error leve logging macro */
546 +/** Error level logging macro */
547 #define HAL_ERROR(expr) do {logger_setup(HAL_LOGPRI_ERROR, __FILE__, __LINE__, __FUNCTION__); logger_emit expr; } while(0)
549 /** Macro for terminating the program on an unrecoverable error */