summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2012-02-24 21:57:34 -0600
committerDave Airlie <airlied@redhat.com>2012-03-09 09:43:22 +0000
commitc8cc4a4626b803f0ce2229651381f6f89f6b5c10 (patch)
treeb85f09474c57d949d60f089ce2452b1d012001c5
parent6f8be87e4e07a314709992fa0533949bb4014914 (diff)
include errno string in more messages
Introduce a die_error() helper that includes strerror in a fatal error message and use it where possible. In particular, when running radeontool as non-root, instead of the cryptic fatal error: mapping ctrl region the operator will get a more helpful diagnosis: fatal error: cannot map ctrl region: Permission denied Inspired by a patch by Tormod Volden. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Dave Airlie <airlied@redhat.com>
-rw-r--r--avivotool.c38
-rw-r--r--radeonreg.c23
-rw-r--r--radeontool.c23
3 files changed, 58 insertions, 26 deletions
diff --git a/avivotool.c b/avivotool.c
index 2f7d4e5..02ee6cc 100644
--- a/avivotool.c
+++ b/avivotool.c
@@ -68,6 +68,13 @@ static void die(const char *why)
exit(-1);
}
+static void die_error(int err, const char *why)
+{
+ fprintf(stderr, "fatal error: %s: %s\n", why, strerror(err));
+ pci_system_cleanup();
+ exit(-1);
+}
+
static void radeon_set(unsigned long offset, const char *name, unsigned int value)
{
if (debug)
@@ -668,10 +675,8 @@ void radeon_dump_img(char *type)
i = 0;
while (i < len) {
ret = write(STDOUT_FILENO, &(fb[i]), len - i);
- if (ret < 0) {
- fprintf(stderr, "write died: %s\n", strerror(errno));
- die("writing to stdout");
- }
+ if (ret < 0)
+ die_error(errno, "writing to stdout");
i += ret;
}
@@ -694,10 +699,8 @@ void radeon_load_img(char *type)
i = 0;
while (i < len) {
ret = read(STDIN_FILENO, &(fb[i]), len - i);
- if (ret < 0) {
- fprintf(stderr, "read died: %s\n", strerror(errno));
- die("reading from stdin");
- }
+ if (ret < 0)
+ die_error(errno, "reading from stdin");
i += ret;
}
@@ -1795,10 +1798,12 @@ static int map_radeon_mem(void)
struct pci_device_iterator *iter;
struct pci_device *device;
pciaddr_t fb_size, ctrl_base, ctrl_size;
- int i = 0;
+ int i = 0, ret;
- if (pci_system_init() != 0) {
- fprintf(stderr, "error: failed to initialise libpciaccess\n");
+ ret = pci_system_init();
+ if (ret) {
+ fprintf(stderr, "error: failed to initialise libpciaccess: %s\n",
+ strerror(ret));
return -1;
}
@@ -1858,9 +1863,14 @@ static int map_radeon_mem(void)
ctrl_base = device->regions[2].base_addr;
ctrl_size = device->regions[2].size;
- if (!ctrl_size || pci_device_map_range(device, ctrl_base, ctrl_size,
- PCI_DEV_MAP_FLAG_WRITABLE, (void **) &ctrl_mem)) {
- fprintf(stderr, "error: mapping ctrl region\n");
+ if (!ctrl_size) {
+ fprintf(stderr, "error: missing ctrl region\n");
+ return -1;
+ }
+ ret = pci_device_map_range(device, ctrl_base, ctrl_size,
+ PCI_DEV_MAP_FLAG_WRITABLE, (void **) &ctrl_mem);
+ if (ret) {
+ fprintf(stderr, "error: cannot map ctrl region: %s\n", strerror(ret));
return -1;
}
diff --git a/radeonreg.c b/radeonreg.c
index 7b76351..0dc14fe 100644
--- a/radeonreg.c
+++ b/radeonreg.c
@@ -50,6 +50,13 @@ static void die(const char *why)
exit(-1);
}
+static void die_error(int err, const char *why)
+{
+ fprintf(stderr, "fatal error: %s: %s\n", why, strerror(err));
+ pci_system_cleanup();
+ exit(-1);
+}
+
static void radeon_set(unsigned long offset, const char *name, unsigned int value)
{
@@ -364,10 +371,11 @@ static int map_radeon_mem(void)
struct pci_device_iterator *iter;
struct pci_device *device;
pciaddr_t fb_base, fb_size, ctrl_base, ctrl_size;
- int i = 0;
+ int i = 0, ret;
- if (pci_system_init() != 0)
- die("failed to initialise libpciaccess");
+ ret = pci_system_init();
+ if (ret)
+ die_error(ret, "failed to initialise libpciaccess");
#if 0
match.vendor_id = 0x1002;
@@ -412,9 +420,12 @@ static int map_radeon_mem(void)
ctrl_base = device->regions[2].base_addr;
ctrl_size = device->regions[2].size;
- if (!ctrl_size || pci_device_map_range(device, ctrl_base, ctrl_size,
- PCI_DEV_MAP_FLAG_WRITABLE, (void **) &ctrl_mem))
- die("mapping ctrl region");
+ if (!ctrl_size)
+ die("missing ctrl region");
+ ret = pci_device_map_range(device, ctrl_base, ctrl_size,
+ PCI_DEV_MAP_FLAG_WRITABLE, (void **) &ctrl_mem);
+ if (ret)
+ die_error(ret, "cannot map ctrl region");
fb_base = device->regions[0].base_addr;
fb_size = device->regions[0].size;
diff --git a/radeontool.c b/radeontool.c
index dbab763..bf1dc3c 100644
--- a/radeontool.c
+++ b/radeontool.c
@@ -42,6 +42,13 @@ static void die(const char *why)
exit(-1);
}
+static void die_error(int err, const char *why)
+{
+ fprintf(stderr, "fatal error: %s: %s\n", why, strerror(err));
+ pci_system_cleanup();
+ exit(-1);
+}
+
static unsigned int radeon_get(unsigned long offset, const char *name)
{
unsigned int value;
@@ -916,10 +923,11 @@ static void map_radeon_cntl_mem(void)
struct pci_device_iterator *iter;
struct pci_device *device;
pciaddr_t fb_base, fb_size, ctrl_base, ctrl_size;
- int i = 0;
+ int i = 0, ret;
- if (pci_system_init() != 0)
- die("failed to initialise libpciaccess");
+ ret = pci_system_init();
+ if (ret)
+ die_error(ret, "failed to initialise libpciaccess");
match.domain = PCI_MATCH_ANY;
match.bus = PCI_MATCH_ANY;
@@ -949,9 +957,12 @@ static void map_radeon_cntl_mem(void)
ctrl_base = device->regions[2].base_addr;
ctrl_size = device->regions[2].size;
- if (!ctrl_size || pci_device_map_range(device, ctrl_base, ctrl_size,
- PCI_DEV_MAP_FLAG_WRITABLE, (void **) &ctrl_mem))
- die("mapping ctrl region");
+ if (!ctrl_size)
+ die("missing ctrl region");
+ ret = pci_device_map_range(device, ctrl_base, ctrl_size,
+ PCI_DEV_MAP_FLAG_WRITABLE, (void **) &ctrl_mem);
+ if (ret)
+ die_error(ret, "cannot map ctrl region");
fb_base = device->regions[0].base_addr;
fb_size = device->regions[0].size;