Author: stefanct Date: Sun Apr 7 15:08:30 2013 New Revision: 1668 URL: http://flashrom.org/trac/flashrom/changeset/1668
Log: Get rid of perror().
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@student.tuwien.ac.at Acked-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Modified: trunk/cli_output.c trunk/flashrom.c trunk/physmap.c
Modified: trunk/cli_output.c ============================================================================== --- trunk/cli_output.c Fri Apr 5 10:06:10 2013 (r1667) +++ trunk/cli_output.c Sun Apr 7 15:08:30 2013 (r1668) @@ -50,7 +50,7 @@ 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;
Modified: trunk/flashrom.c ============================================================================== --- trunk/flashrom.c Fri Apr 5 10:06:10 2013 (r1667) +++ trunk/flashrom.c Sun Apr 7 15:08:30 2013 (r1668) @@ -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 @@ 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 @@ } 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 @@ return 1; } if ((image = fopen(filename, "wb")) == NULL) { - perror(filename); + msg_gerr("Error: opening file "%s" failed: %s\n", filename, strerror(errno)); return 1; }
Modified: trunk/physmap.c ============================================================================== --- trunk/physmap.c Fri Apr 5 10:06:10 2013 (r1667) +++ trunk/physmap.c Sun Apr 7 15:08:30 2013 (r1668) @@ -172,7 +172,7 @@ 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 @@ 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 @@ 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 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 @@
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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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; }