diff options
author | Jonathan Nieder <jrnieder@gmail.com> | 2012-02-24 21:57:34 -0600 |
---|---|---|
committer | Dave Airlie <airlied@redhat.com> | 2012-03-09 09:43:22 +0000 |
commit | c8cc4a4626b803f0ce2229651381f6f89f6b5c10 (patch) | |
tree | b85f09474c57d949d60f089ce2452b1d012001c5 /radeontool.c | |
parent | 6f8be87e4e07a314709992fa0533949bb4014914 (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>
Diffstat (limited to 'radeontool.c')
-rw-r--r-- | radeontool.c | 23 |
1 files changed, 17 insertions, 6 deletions
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; |