It prints to stderr and that's not what we want necesserily;
using msg_*err gives us more control.
Signed-off-by: Stefan Tauner <stefan.tauner(a)student.tuwien.ac.at>
---
cli_output.c | 2 +-
flashrom.c | 9 +++++----
physmap.c | 23 +++++++++++------------
3 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/cli_output.c b/cli_output.c
index 54b09a6..476b2bf 100644
--- a/cli_output.c
+++ b/cli_output.c
@@ -50,7 +50,7 @@ int open_logfile(const char * const filename)
return 1;
}
if ((logfile = fopen(filename, "w")) == NULL) {
- perror(filename);
+ msg_gerr("Error: opening log file \"%s\" failed: %s\n", filename, strerror(errno));
return 1;
}
return 0;
diff --git a/flashrom.c b/flashrom.c
index 14bb1b3..c11f723 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -29,6 +29,7 @@
#endif
#include <string.h>
#include <stdlib.h>
+#include <errno.h>
#include <ctype.h>
#include <getopt.h>
#if HAVE_UTSNAME == 1
@@ -1158,11 +1159,11 @@ int read_buf_from_file(unsigned char *buf, unsigned long size,
struct stat image_stat;
if ((image = fopen(filename, "rb")) == NULL) {
- perror(filename);
+ msg_gerr("Error: opening file \"%s\" failed: %s\n", filename, strerror(errno));
return 1;
}
if (fstat(fileno(image), &image_stat) != 0) {
- perror(filename);
+ msg_gerr("Error: getting metadata of file \"%s\" failed: %s\n", filename, strerror(errno));
fclose(image);
return 1;
}
@@ -1174,7 +1175,7 @@ int read_buf_from_file(unsigned char *buf, unsigned long size,
}
numbytes = fread(buf, 1, size, image);
if (fclose(image)) {
- perror(filename);
+ msg_gerr("Error: closing file \"%s\" failed: %s\n", filename, strerror(errno));
return 1;
}
if (numbytes != size) {
@@ -1196,7 +1197,7 @@ int write_buf_to_file(unsigned char *buf, unsigned long size,
return 1;
}
if ((image = fopen(filename, "wb")) == NULL) {
- perror(filename);
+ msg_gerr("Error: opening file \"%s\" failed: %s\n", filename, strerror(errno));
return 1;
}
diff --git a/physmap.c b/physmap.c
index 5aa9874..4ebfb06 100644
--- a/physmap.c
+++ b/physmap.c
@@ -172,7 +172,7 @@ static void *sys_physmap_rw_uncached(unsigned long phys_addr, size_t len)
if (-1 == fd_mem) {
/* Open the memory device UNCACHED. Important for MMIO. */
if (-1 == (fd_mem = open(MEM_DEV, O_RDWR | O_SYNC))) {
- perror("Critical error: open(" MEM_DEV ")");
+ msg_perr("Critical error: open(" MEM_DEV "): %s\n", strerror(errno));
exit(2);
}
}
@@ -192,8 +192,7 @@ static void *sys_physmap_ro_cached(unsigned long phys_addr, size_t len)
if (-1 == fd_mem_cached) {
/* Open the memory device CACHED. */
if (-1 == (fd_mem_cached = open(MEM_DEV, O_RDWR))) {
- msg_perr("Critical error: open(" MEM_DEV "): %s",
- strerror(errno));
+ msg_perr("Critical error: open(" MEM_DEV "): %s\n", strerror(errno));
exit(2);
}
}
@@ -250,7 +249,7 @@ static void *physmap_common(const char *descr, unsigned long phys_addr,
descr = "memory";
msg_perr("Error accessing %s, 0x%lx bytes at 0x%08lx\n", descr,
(unsigned long)len, phys_addr);
- perror(MEM_DEV " mmap failed");
+ msg_perr(MEM_DEV " mmap failed: %s\n", strerror(errno));
#ifdef __linux__
if (EINVAL == errno) {
msg_perr("In Linux this error can be caused by the CONFIG_NONPROMISC_DEVMEM (<2.6.27),\n");
@@ -302,7 +301,7 @@ msr_t rdmsr(int addr)
msr_t msr = { 0xffffffff, 0xffffffff };
if (lseek(fd_msr, (off_t) addr, SEEK_SET) == -1) {
- perror("Could not lseek() to MSR");
+ msg_perr("Could not lseek() MSR: %s\n", strerror(errno));
close(fd_msr);
exit(1);
}
@@ -315,7 +314,7 @@ msr_t rdmsr(int addr)
if (errno != EIO) {
// A severe error.
- perror("Could not read() MSR");
+ msg_perr("Could not read() MSR: %s\n", strerror(errno));
close(fd_msr);
exit(1);
}
@@ -330,13 +329,13 @@ int wrmsr(int addr, msr_t msr)
buf[1] = msr.hi;
if (lseek(fd_msr, (off_t) addr, SEEK_SET) == -1) {
- perror("Could not lseek() to MSR");
+ msg_perr("Could not lseek() MSR: %s\n", strerror(errno));
close(fd_msr);
exit(1);
}
if (write(fd_msr, buf, 8) != 8 && errno != EIO) {
- perror("Could not write() MSR");
+ msg_perr("Could not write() MSR: %s\n", strerror(errno));
close(fd_msr);
exit(1);
}
@@ -362,7 +361,7 @@ int setup_cpu_msr(int cpu)
fd_msr = open(msrfilename, O_RDWR);
if (fd_msr < 0) {
- perror("Error while opening /dev/cpu/0/msr");
+ msg_perr("Error while opening %s: %s\n", msrfilename, strerror(errno));
msg_pinfo("Did you run 'modprobe msr'?\n");
return -1;
}
@@ -404,7 +403,7 @@ msr_t rdmsr(int addr)
args.msr = addr;
if (ioctl(fd_msr, CPU_RDMSR, &args) < 0) {
- perror("CPU_RDMSR");
+ msg_perr("Error while executing CPU_RDMSR ioctl: %s\n", strerror(errno));
close(fd_msr);
exit(1);
}
@@ -423,7 +422,7 @@ int wrmsr(int addr, msr_t msr)
args.data = (((uint64_t)msr.hi) << 32) | msr.lo;
if (ioctl(fd_msr, CPU_WRMSR, &args) < 0) {
- perror("CPU_WRMSR");
+ msg_perr("Error while executing CPU_WRMSR ioctl: %s\n", strerror(errno));
close(fd_msr);
exit(1);
}
@@ -445,7 +444,7 @@ int setup_cpu_msr(int cpu)
fd_msr = open(msrfilename, O_RDWR);
if (fd_msr < 0) {
- perror("Error while opening /dev/cpu0");
+ msg_perr("Error while opening %s: %s\n", msrfilename, strerror(errno));
msg_pinfo("Did you install ports/sysutils/devcpu?\n");
return -1;
}
--
Kind regards, Stefan Tauner