summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--pci.c10
-rw-r--r--usb.c22
3 files changed, 40 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 9fa8535..7e6fb47 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2002-07-16 17:07 tvignaud
+
+ * ChangeLog, ldetect.spec, libldetect-private.h, lspcidrake.c,
+ pci.c: - pci.c: add the ability to read pci devices list from a
+ file instead of /proc/bus/pci/devices
+
+ - spec: prepare for next release
+
+ - add ChangeLog
+
2002-07-16 16:54 tvignaud
* libldetect-private.h, lspcidrake.c, usb.c: - move usb devices
diff --git a/pci.c b/pci.c
index 6482de7..fba8ad4 100644
--- a/pci.c
+++ b/pci.c
@@ -1,3 +1,5 @@
+#include <unistd.h>
+#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -16,8 +18,14 @@ extern struct pciusb_entries pci_probe(int probe_type) {
struct pciusb_entries r;
r.entries = malloc(sizeof(struct pciusb_entry) * MAX_DEVICES);
- if (!(f = fopen(proc_pci_path, "r")))
+ if (!(f = fopen(proc_pci_path, "r"))) {
+ char *err_msg;
+ asprintf(&err_msg, "unable to open \"%s\"\n"
+ "You may have passed a wrong argument to the \"-p\" option.\n"
+ "fopen() sets errno to", proc_pci_path);
+ perror(err_msg);
exit(1);
+ }
for (r.nb = 0; fgets(buf, sizeof(buf) - 1, f) && r.nb < MAX_DEVICES; r.nb++) {
struct pciusb_entry *e = &r.entries[r.nb];
diff --git a/usb.c b/usb.c
index cbeea25..c41ca00 100644
--- a/usb.c
+++ b/usb.c
@@ -1,3 +1,5 @@
+#include <unistd.h>
+#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -16,8 +18,26 @@ extern struct pciusb_entries usb_probe(void) {
struct pciusb_entries r;
struct pciusb_entry *e = NULL;
- if (!(f = fopen(proc_usb_path, "r")))
+ if (access(proc_pci_path, R_OK) != 0) {
+ printf( "TOTO\n");
exit(1);
+ }
+
+ if (!(f = fopen(proc_usb_path, "r"))) {
+ char *err_msg;
+ if (proc_usb_path==NULL || strcmp(proc_usb_path, "/proc/bus/usb/devices")) {
+ asprintf(&err_msg, "unable to open \"%s\"\n"
+ "You may have passed a wrong argument to the \"-u\" option.\n"
+ "fopen() sets errno to", proc_usb_path);
+ perror(err_msg);
+ } /*else {
+ asprintf(&err_msg, "unable to open \"%s\"\n"
+ "You should enable the usb service (as root, type 'service usb start'.\n"
+ "fopen() sets errno to", proc_usb_path);
+ perror(err_msg);
+ } */
+ exit(1);
+ }
for(r.nb = line = 0; fgets(buf, sizeof(buf) - 1, f) && r.nb < psizeof(t); line++) {
if (buf[0] == 'P') {