summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTing-Wei Lan <lantw@src.gnome.org>2018-01-06 03:26:39 +0800
committerRichard Hughes <richard@hughsie.com>2018-01-16 14:05:10 +0000
commit03f9c6170e70628fbea40d2ab7085b10baa0dc0d (patch)
tree0992393d86027fb476eb831e9a4d76eac21eb093
parent083152519879761379295dcec165a1889465a4d4 (diff)
downloadcolord-03f9c6170e70628fbea40d2ab7085b10baa0dc0d.tar.gz
Make udev hwdb optional by using pnp.ids as fallback
FreeBSD libudev-devd doesn't implement udev hwdb, and I cannot find any way to do the conversion in the FreeBSD source tree. Therefore, the fallback code removed in commit c9650c0bb7324c32d82fa6d7d898e236f10ea63b is brought back to use the pnp.ids file.
-rw-r--r--lib/colord/cd-edid.c24
-rw-r--r--meson.build4
-rw-r--r--meson_options.txt1
3 files changed, 29 insertions, 0 deletions
diff --git a/lib/colord/cd-edid.c b/lib/colord/cd-edid.c
index 3e75a8f..a5e2328 100644
--- a/lib/colord/cd-edid.c
+++ b/lib/colord/cd-edid.c
@@ -106,6 +106,7 @@ cd_edid_get_monitor_name (CdEdid *edid)
static gchar *
cd_edid_convert_pnp_id_to_string (const gchar *pnp_id)
{
+#ifndef PNP_IDS
gchar *vendor = NULL;
struct udev_hwdb *hwdb = NULL;
struct udev_list_entry *e;
@@ -140,6 +141,29 @@ out:
if (udev != NULL)
udev_unref (udev);
return vendor;
+#else
+ g_autofree gchar *data = NULL;
+
+ /* load pnp.ids */
+ if (!g_file_get_contents (PNP_IDS, &data, NULL, NULL))
+ return NULL;
+ if (data == NULL)
+ return NULL;
+
+ /* get the vendor name from the tab delimited data */
+ for (gchar *idx = data; idx != NULL; ) {
+ if (strncmp (idx, pnp_id, 3) == 0) {
+ gchar *idx2 = g_strstr_len (idx, -1, "\n");
+ if (idx2 != NULL)
+ *idx2 = '\0';
+ return g_strdup (idx + 4);
+ }
+ idx = g_strstr_len (idx, -1, "\n");
+ if (idx != NULL)
+ idx++;
+ }
+ return NULL;
+#endif
}
/**
diff --git a/meson.build b/meson.build
index ead7a7d..0e90342 100644
--- a/meson.build
+++ b/meson.build
@@ -182,6 +182,10 @@ if get_option('with-daemon-user') == 'root'
message('RUNNING THIS AS root IS NOT A GOOD IDEA SEE --with-daemon-user')
endif
+if get_option('with-pnp-ids') != ''
+ conf.set_quoted('PNP_IDS', get_option('with-pnp-ids'))
+endif
+
polkit = dependency('polkit-gobject-1', version : '>= 0.103')
if polkit.version().version_compare('>= 0.114')
conf.set('POLKIT_HAS_AUTOPTR_MACROS', '1')
diff --git a/meson_options.txt b/meson_options.txt
index 05aa12a..1731380 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -11,5 +11,6 @@ option('enable-print-profiles', type : 'boolean', value : false, description : '
option('enable-tests', type : 'boolean', value : true, description : 'Build self tests')
option('enable-installed-tests', type : 'boolean', value : false, description : 'Install tests')
option('with-daemon-user', type : 'string', value : 'root', description : 'User for running the colord daemon')
+option('with-pnp-ids', type : 'string', value : '', description : 'Location of pnp.ids if hwdb is not available')
option('enable-man', type : 'boolean', value : true, description : 'Generate man pages')
option('enable-docs', type : 'boolean', value : true, description : 'Generate documentation')