got rid of all uses of strerror
This required some minor refactoring of other things and there were some
other small cleanups I noticed along the way.
diff --git a/aos/linux_code/logging/binary_log_file.cc b/aos/linux_code/logging/binary_log_file.cc
index ff3df68..2738c16 100644
--- a/aos/linux_code/logging/binary_log_file.cc
+++ b/aos/linux_code/logging/binary_log_file.cc
@@ -1,7 +1,6 @@
#include "aos/linux_code/logging/binary_log_file.h"
#include <stdio.h>
-#include <errno.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
@@ -43,8 +42,7 @@
struct stat info;
if (fstat(fd_, &info) == -1) {
- LOG(FATAL, "fstat(%d, %p) failed with %d: %s\n", fd_, &info, errno,
- strerror(errno));
+ PLOG(FATAL, "fstat(%d, %p) failed", fd_, &info);
}
bool r = offset_ == static_cast<off_t>(info.st_size - kPageSize);
is_last_page_ = r ? 2 : 1;
@@ -54,32 +52,27 @@
void LogFileAccessor::MapNextPage() {
if (writable_) {
if (ftruncate(fd_, offset_ + kPageSize) == -1) {
- LOG(FATAL, "ftruncate(%d, %zd) failed with %d: %s. aborting\n", fd_,
- kPageSize, errno, strerror(errno));
+ PLOG(FATAL, "ftruncate(%d, %zd) failed", fd_, kPageSize);
}
}
current_ = static_cast<char *>(
mmap(NULL, kPageSize, PROT_READ | (writable_ ? PROT_WRITE : 0),
MAP_SHARED, fd_, offset_));
if (current_ == MAP_FAILED) {
- LOG(FATAL,
- "mmap(NULL, %zd, PROT_READ [ | PROT_WRITE], MAP_SHARED, %d, %jd)"
- " failed with %d: %s\n",
- kPageSize, fd_, static_cast<intmax_t>(offset_), errno,
- strerror(errno));
+ PLOG(FATAL,
+ "mmap(NULL, %zd, PROT_READ [ | PROT_WRITE], MAP_SHARED, %d, %jd)"
+ " failed", kPageSize, fd_, static_cast<intmax_t>(offset_));
}
if (madvise(current_, kPageSize, MADV_SEQUENTIAL | MADV_WILLNEED) == -1) {
- LOG(WARNING, "madvise(%p, %zd, MADV_SEQUENTIAL | MADV_WILLNEED)"
- " failed with %d: %s\n",
- current_, kPageSize, errno, strerror(errno));
+ PLOG(WARNING, "madvise(%p, %zd, MADV_SEQUENTIAL | MADV_WILLNEED) failed",
+ current_, kPageSize);
}
offset_ += kPageSize;
}
void LogFileAccessor::Unmap(void *location) {
if (munmap(location, kPageSize) == -1) {
- LOG(FATAL, "munmap(%p, %zd) failed with %d: %s. aborting\n", location,
- kPageSize, errno, strerror(errno));
+ PLOG(FATAL, "munmap(%p, %zd) failed", location, kPageSize);
}
is_last_page_ = 0;
position_ = 0;
@@ -137,23 +130,23 @@
action.sa_flags = SA_RESETHAND | SA_SIGINFO;
struct sigaction previous_bus, previous_segv;
if (sigaction(SIGBUS, &action, &previous_bus) == -1) {
- LOG(FATAL, "sigaction(SIGBUS(=%d), %p, %p) failed with %d: %s\n",
- SIGBUS, &action, &previous_bus, errno, strerror(errno));
+ PLOG(FATAL, "sigaction(SIGBUS(=%d), %p, %p) failed",
+ SIGBUS, &action, &previous_bus);
}
if (sigaction(SIGSEGV, &action, &previous_segv) == -1) {
- LOG(FATAL, "sigaction(SIGSEGV(=%d), %p, %p) failed with %d: %s\n",
- SIGSEGV, &action, &previous_segv, errno, strerror(errno));
+ PLOG(FATAL, "sigaction(SIGSEGV(=%d), %p, %p) failed",
+ SIGSEGV, &action, &previous_segv);
}
char __attribute__((unused)) c = current()[0];
if (sigaction(SIGBUS, &previous_bus, NULL) == -1) {
- LOG(FATAL, "sigaction(SIGBUS(=%d), %p, NULL) failed with %d: %s\n",
- SIGBUS, &previous_bus, errno, strerror(errno));
+ PLOG(FATAL, "sigaction(SIGBUS(=%d), %p, NULL) failed",
+ SIGBUS, &previous_bus);
}
if (sigaction(SIGSEGV, &previous_segv, NULL) == -1) {
- LOG(FATAL, "sigaction(SIGSEGV(=%d), %p, NULL) failed with %d: %s\n",
- SIGSEGV, &previous_segv, errno, strerror(errno));
+ PLOG(FATAL, "sigaction(SIGSEGV(=%d), %p, NULL) failed",
+ SIGSEGV, &previous_segv);
}
} else {
if (fault_address == current()) {
@@ -173,9 +166,8 @@
MapNextPage();
if (futex_set_value(static_cast<mutex *>(static_cast<void *>(
&temp[position()])), 2) == -1) {
- LOG(WARNING,
- "futex_set_value(%p, 2) failed with %d: %s. readers will hang\n",
- &temp[position()], errno, strerror(errno));
+ PLOG(WARNING, "readers will hang because futex_set_value(%p, 2) failed",
+ &temp[position()]);
}
Unmap(temp);
}
diff --git a/aos/linux_code/logging/binary_log_writer.cc b/aos/linux_code/logging/binary_log_writer.cc
index 37a069b..0013dd4 100644
--- a/aos/linux_code/logging/binary_log_writer.cc
+++ b/aos/linux_code/logging/binary_log_writer.cc
@@ -75,8 +75,7 @@
}
closedir(d);
} else {
- aos::Die("could not open directory %s because of %d (%s).\n", directory,
- errno, strerror(errno));
+ PDie("could not open directory %s", directory);
}
char previous[512];
@@ -90,8 +89,7 @@
printf("Could not find aos_log-current\n");
}
if (asprintf(filename, "%s/aos_log-%03d", directory, fileindex) == -1) {
- aos::Die("couldn't create final name because of %d (%s)\n",
- errno, strerror(errno));
+ PDie("couldn't create final name");
}
LOG(INFO, "Created log file (aos_log-%d) in directory (%s). Previous file "
"was (%s).\n",
@@ -114,19 +112,13 @@
AllocateLogName(&tmp, folder);
char *tmp2;
if (asprintf(&tmp2, "%s/aos_log-current", folder) == -1) {
- fprintf(stderr,
- "BinaryLogReader: couldn't create symlink name because of %d (%s)."
- " not creating current symlink\n", errno, strerror(errno));
+ PLOG(WARNING, "couldn't create current symlink name");
} else {
if (unlink(tmp2) == -1 && (errno != EROFS && errno != ENOENT)) {
- fprintf(stderr,
- "BinaryLogReader: warning: unlink('%s') failed"
- " because of %d (%s)\n",
- tmp2, errno, strerror(errno));
+ LOG(WARNING, "unlink('%s') failed", tmp2);
}
if (symlink(tmp, tmp2) == -1) {
- fprintf(stderr, "BinaryLogReader: warning: symlink('%s', '%s') failed"
- " because of %d (%s)\n", tmp, tmp2, errno, strerror(errno));
+ PLOG(WARNING, "symlink('%s', '%s') failed", tmp, tmp2);
}
free(tmp2);
}
@@ -134,10 +126,7 @@
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
free(tmp);
if (fd == -1) {
- fprintf(stderr,
- "BinaryLogReader: couldn't open file '%s' because of %d (%s)."
- " exiting\n", tmp, errno, strerror(errno));
- return EXIT_FAILURE;
+ PLOG(FATAL, "opening file '%s' failed", tmp);
}
LogFileWriter writer(fd);
diff --git a/aos/linux_code/logging/linux_interface.cc b/aos/linux_code/logging/linux_interface.cc
index d039c70..9889c07 100644
--- a/aos/linux_code/logging/linux_interface.cc
+++ b/aos/linux_code/logging/linux_interface.cc
@@ -20,8 +20,7 @@
char thread_name_array[kThreadNameLength + 1];
if (prctl(PR_GET_NAME, thread_name_array) != 0) {
- Die("prctl(PR_GET_NAME, %p) failed with %d: %s\n",
- thread_name_array, errno, strerror(errno));
+ PDie("prctl(PR_GET_NAME, %p) failed", thread_name_array);
}
thread_name_array[sizeof(thread_name_array) - 1] = '\0';
::std::string thread_name(thread_name_array);
diff --git a/aos/linux_code/logging/log_displayer.cc b/aos/linux_code/logging/log_displayer.cc
index 0bb3508..071a87e 100644
--- a/aos/linux_code/logging/log_displayer.cc
+++ b/aos/linux_code/logging/log_displayer.cc
@@ -5,7 +5,6 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <inttypes.h>
-#include <errno.h>
#include <algorithm>
@@ -146,10 +145,7 @@
int fd = open(filename, O_RDONLY);
if (fd == -1) {
- fprintf(stderr,
- "error: couldn't open file '%s' for reading because of %s\n",
- filename, strerror(errno));
- exit(EXIT_FAILURE);
+ PLOG(FATAL, "couldn't open file '%s' for reading", filename);
}
::aos::logging::linux_code::LogFileReader reader(fd);