mirror of
https://github.com/ZoiteChat/zoitechat.git
synced 2026-12-05 06:22:18 +00:00
improve hardware probes+ legacy cleanup
This commit is contained in:
2 files changed
+36
-18
No files matched your search
@@ -116,7 +116,7 @@ read_hex_file (const char *path, guint *value)
|
|||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
parsed = g_ascii_strtoull (contents, &end, 16);
|
parsed = g_ascii_strtoull (contents, &end, 16);
|
||||||
if (errno != 0 || end == contents)
|
if (errno != 0 || end == contents || *end != '\0' || parsed > G_MAXUINT || contents[0] == '-')
|
||||||
{
|
{
|
||||||
g_free (contents);
|
g_free (contents);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@@ -535,19 +535,22 @@ scan_pci_devices (void)
|
|||||||
gpus = g_ptr_array_new_with_free_func (g_free);
|
gpus = g_ptr_array_new_with_free_func (g_free);
|
||||||
chipsets = g_ptr_array_new_with_free_func (g_free);
|
chipsets = g_ptr_array_new_with_free_func (g_free);
|
||||||
|
|
||||||
|
dir = g_dir_open ("/sys/bus/pci/devices", 0, NULL);
|
||||||
#ifdef HAVE_LIBPCI
|
#ifdef HAVE_LIBPCI
|
||||||
/* We only need name lookup: autodetection can exit the client if sysfs
|
/* Only initialize the explicit sysfs method when PCI is visible. Never
|
||||||
* is hidden in a sandbox and libpci tries privileged access methods.
|
* use autodetection or ask libpci to probe/configure a device. */
|
||||||
* Explicit sysfs initialization installs callbacks without probing. */
|
if (dir)
|
||||||
if (pci_lookup_method ("linux-sysfs") >= 0)
|
|
||||||
{
|
{
|
||||||
pacc = pci_alloc ();
|
int method = pci_lookup_method ("linux-sysfs");
|
||||||
pacc->method = pci_lookup_method ("linux-sysfs");
|
if (method >= 0)
|
||||||
pci_init (pacc);
|
{
|
||||||
|
pacc = pci_alloc ();
|
||||||
|
pacc->method = method;
|
||||||
|
pci_init (pacc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
dir = g_dir_open ("/sys/bus/pci/devices", 0, NULL);
|
|
||||||
if (dir)
|
if (dir)
|
||||||
{
|
{
|
||||||
while ((entry = g_dir_read_name (dir)) != NULL)
|
while ((entry = g_dir_read_name (dir)) != NULL)
|
||||||
@@ -614,8 +617,9 @@ scan_pci_devices (void)
|
|||||||
g_free (gpu_name);
|
g_free (gpu_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (class_subclass == 0x0600)
|
else if (class_subclass == 0x0600 || class_subclass == 0x0601)
|
||||||
{
|
{
|
||||||
|
/* Include host bridges and ISA/LPC bridges. */
|
||||||
ptr_array_add_unique (chipsets, name);
|
ptr_array_add_unique (chipsets, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -821,7 +825,8 @@ sysinfo_backend_get_uptime (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
uptime = g_ascii_strtod (contents, &end);
|
uptime = g_ascii_strtod (contents, &end);
|
||||||
if (end == contents || uptime <= 0.0)
|
/* Comparisons also reject NaN, infinity and out-of-range conversions. */
|
||||||
|
if (end == contents || !(uptime >= 0.0 && uptime < (double) G_MAXINT64))
|
||||||
{
|
{
|
||||||
g_free (contents);
|
g_free (contents);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
@@ -51,12 +51,18 @@ static struct device *scan_device(struct pci_dev *p)
|
|||||||
d = g_new0 (struct device, 1);
|
d = g_new0 (struct device, 1);
|
||||||
d->dev = p;
|
d->dev = p;
|
||||||
if (!pci_read_block(p, 0, d->config, how_much))
|
if (!pci_read_block(p, 0, d->config, how_much))
|
||||||
exit(1);
|
{
|
||||||
|
g_free (d);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
if (how_much < 128 && (d->config[PCI_HEADER_TYPE] & 0x7f) == PCI_HEADER_TYPE_CARDBUS)
|
if (how_much < 128 && (d->config[PCI_HEADER_TYPE] & 0x7f) == PCI_HEADER_TYPE_CARDBUS)
|
||||||
{
|
{
|
||||||
/* For cardbus bridges, we need to fetch 64 bytes more to get the full standard header... */
|
/* For cardbus bridges, we need to fetch 64 bytes more to get the full standard header... */
|
||||||
if (!pci_read_block(p, 64, d->config+64, 64))
|
if (!pci_read_block(p, 64, d->config+64, 64))
|
||||||
exit(1);
|
{
|
||||||
|
g_free (d);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
how_much = 128;
|
how_much = 128;
|
||||||
}
|
}
|
||||||
d->config_cnt = how_much;
|
d->config_cnt = how_much;
|
||||||
@@ -116,6 +122,14 @@ int pci_find_by_class(u16 *class, char *vendor, char *device)
|
|||||||
}
|
}
|
||||||
|
|
||||||
pci_cleanup(pacc);
|
pci_cleanup(pacc);
|
||||||
|
pacc = NULL;
|
||||||
|
/* Free the cached configuration buffers after libpci is done with them. */
|
||||||
|
while (first_dev)
|
||||||
|
{
|
||||||
|
d = first_dev;
|
||||||
|
first_dev = d->next;
|
||||||
|
g_free (d);
|
||||||
|
}
|
||||||
return nomatch;
|
return nomatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,8 +156,7 @@ void pci_find_fullname(char *fullname, char *vendor, char *device)
|
|||||||
position = strstr(buffer, vendor);
|
position = strstr(buffer, vendor);
|
||||||
position += 6;
|
position += 6;
|
||||||
g_strlcpy(vendorname, position, sizeof (vendorname));
|
g_strlcpy(vendorname, position, sizeof (vendorname));
|
||||||
position = strstr(vendorname, "\n");
|
g_strchomp (vendorname);
|
||||||
*(position) = '\0';
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -155,9 +168,9 @@ void pci_find_fullname(char *fullname, char *vendor, char *device)
|
|||||||
position += 6;
|
position += 6;
|
||||||
g_strlcpy(devicename, position, sizeof (devicename));
|
g_strlcpy(devicename, position, sizeof (devicename));
|
||||||
position = strstr(devicename, " (");
|
position = strstr(devicename, " (");
|
||||||
if (position == NULL)
|
if (position)
|
||||||
position = strstr(devicename, "\n");
|
*position = '\0';
|
||||||
*(position) = '\0';
|
g_strchomp (devicename);
|
||||||
cardfound = 1;
|
cardfound = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user