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/configuration.cc b/aos/linux_code/configuration.cc
index 2fd5150..55fff84 100644
--- a/aos/linux_code/configuration.cc
+++ b/aos/linux_code/configuration.cc
@@ -1,7 +1,6 @@
 #include "aos/linux_code/configuration.h"
 
 #include <string.h>
-#include <errno.h>
 #include <stdlib.h>
 #include <sys/types.h>
 #include <netinet/in.h>
@@ -21,24 +20,24 @@
 // set the IP address when running tests from the test.
 const char *const kLinuxNetInterface = "eth0";
 const in_addr *DoGetOwnIPAddress() {
-    static const char *kOverrideVariable = "FRC971_IP_OVERRIDE";
-    const char *override_ip = getenv(kOverrideVariable);
-    if (override_ip != NULL) {
-        LOG(INFO, "Override IP is %s\n", override_ip);
-        static in_addr r;
-        if (inet_aton(override_ip, &r) != 0) {
-            return &r;
-        } else {
-            LOG(WARNING, "error parsing %s value '%s'\n", kOverrideVariable, override_ip);
-        }
+  static const char *kOverrideVariable = "FRC971_IP_OVERRIDE";
+  const char *override_ip = getenv(kOverrideVariable);
+  if (override_ip != NULL) {
+    LOG(INFO, "Override IP is %s\n", override_ip);
+    static in_addr r;
+    if (inet_aton(override_ip, &r) != 0) {
+      return &r;
     } else {
-        LOG(INFO, "Couldn't get environmental variable.\n");
+      LOG(WARNING, "error parsing %s value '%s'\n",
+          kOverrideVariable, override_ip);
     }
+  } else {
+    LOG(INFO, "Couldn't get environmental variable.\n");
+  }
 
   ifaddrs *addrs;
   if (getifaddrs(&addrs) != 0) {
-    LOG(FATAL, "getifaddrs(%p) failed with %d: %s\n", &addrs,
-        errno, strerror(errno));
+    PLOG(FATAL, "getifaddrs(%p) failed", &addrs);
   }
   // Smart pointers don't work very well for iterating through a linked list,
   // but it does do a very nice job of making sure that addrs gets freed.
@@ -71,8 +70,7 @@
       if (ret != -1) {
         LOG(WARNING, "it returned %zd, not -1\n", ret);
       }
-      LOG(FATAL, "readlink(\"/proc/self/exe\", %p, %zu) failed with %d: %s\n",
-          r, size, errno, strerror(errno));
+      PLOG(FATAL, "readlink(\"/proc/self/exe\", %p, %zu) failed", r, size);
     }
     if (ret < size) {
       void *last_slash = memrchr(r, '/', ret);
diff --git a/aos/linux_code/init.cc b/aos/linux_code/init.cc
index e8bcba1..05004a2 100644
--- a/aos/linux_code/init.cc
+++ b/aos/linux_code/init.cc
@@ -24,15 +24,14 @@
   if (set_for_root || !am_root) {
     struct rlimit64 rlim;
     if (getrlimit64(resource, &rlim) == -1) {
-      Die("%s-init: getrlimit64(%d) failed with %d (%s)\n",
-          program_invocation_short_name, resource, errno, strerror(errno));
+      PDie("%s-init: getrlimit64(%d) failed",
+           program_invocation_short_name, resource);
     }
     rlim.rlim_cur = soft;
     if (setrlimit64(resource, &rlim) == -1) {
-      Die("%s-init: setrlimit64(%d, {cur=%ju,max=%ju})"
-          " failed with %d (%s)\n", program_invocation_short_name,
-          resource, (uintmax_t)rlim.rlim_cur, (uintmax_t)rlim.rlim_max,
-          errno, strerror(errno));
+      PDie("%s-init: setrlimit64(%d, {cur=%ju,max=%ju}) failed",
+           program_invocation_short_name, resource, (uintmax_t)rlim.rlim_cur,
+           (uintmax_t)rlim.rlim_max);
     }
   }
 }
@@ -48,8 +47,7 @@
 int LockAllMemory() {
   InitStart();
   if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1) {
-    Die("%s-init: mlockall failed with %d (%s)\n",
-        program_invocation_short_name, errno, strerror(errno));
+    PDie("%s-init: mlockall failed", program_invocation_short_name);
   }
 
   // Forces the memory pages for all the stack space that we're ever going to
@@ -65,10 +63,7 @@
 // non-realtime processes.
 void DoInitNRT(aos_core_create create) {
   InitStart();
-  if (aos_core_create_shared_mem(create)) {
-    Die("%s-init: creating shared memory reference failed\n",
-        program_invocation_short_name);
-  }
+  aos_core_create_shared_mem(create);
   logging::linux_code::Register();
 }
 
@@ -89,8 +84,7 @@
     struct sched_param param;
     param.sched_priority = 30 + relative_priority;
     if (sched_setscheduler(0, SCHED_FIFO, &param) != 0) {
-      Die("%s-init: setting SCHED_FIFO failed with %d (%s)\n",
-          program_invocation_short_name, errno, strerror(errno));
+      PDie("%s-init: setting SCHED_FIFO failed", program_invocation_short_name);
     }
   } else {
     fprintf(stderr, "%s not doing realtime initialization because environment"
@@ -103,10 +97,7 @@
 }
 
 void Cleanup() {
-  if (aos_core_free_shared_mem()) {
-    Die("%s-init: freeing shared mem failed\n",
-        program_invocation_short_name);
-  }
+  aos_core_free_shared_mem();
 }
 
 void WriteCoreDumps() {
diff --git a/aos/linux_code/ipc_lib/aos_sync.c b/aos/linux_code/ipc_lib/aos_sync.c
index 2245436..204322f 100644
--- a/aos/linux_code/ipc_lib/aos_sync.c
+++ b/aos/linux_code/ipc_lib/aos_sync.c
@@ -1,6 +1,5 @@
 #include "aos/linux_code/ipc_lib/aos_sync.h"
 
-#include <stdio.h>
 #include <linux/futex.h>
 #include <unistd.h>
 #include <sys/syscall.h>
@@ -10,6 +9,8 @@
 #include <string.h>
 #include <inttypes.h>
 
+#include "aos/common/logging/logging.h"
+
 // TODO(brians): Inline these in the new PI version.
 #define cmpxchg(ptr, o, n) __sync_val_compare_and_swap(ptr, o, n)
 static inline uint32_t xchg(mutex *pointer, uint32_t value) {
@@ -151,31 +152,21 @@
 
 void mutex_unlock(mutex *m) {
   /* Unlock, and if not contended then exit. */
-  //printf("mutex_unlock(%p) => %d \n",m,*m);
   switch (xchg(m, 0)) {
     case 0:
-      fprintf(stderr, "sync: multiple unlock of %p. aborting\n", m);
-      printf("see stderr\n");
-      abort();
+      LOG(FATAL, "multiple unlock of %p\n", m);
     case 1:
-      //printf("mutex_unlock return(%p) => %d \n",m,*m);
       break;
     case 2: {
       const int ret = sys_futex_wake(m, 1);
       if (ret < 0) {
-        fprintf(stderr, "sync: waking 1 from %p failed with %d: %s\n",
-                m, -ret, strerror(-ret));
-        printf("see stderr\n");
-        abort();
+        PELOG(FATAL, -ret, "waking 1 from %p failed", m);
       } else {
         break;
       }
     }
     default:
-      fprintf(stderr, "sync: got a garbage value from mutex %p. aborting\n",
-          m);
-      printf("see stderr\n");
-      abort();
+      LOG(FATAL, "got a garbage value from mutex %p\n", m);
   }
 }
 int mutex_trylock(mutex *m) {
@@ -232,11 +223,8 @@
       if (__builtin_expect(*c == wait_start, 0)) {
         // Try again if it was because of a signal.
         if (ret == -EINTR) continue;
-        fprintf(stderr, "FUTEX_WAIT(%p, %"PRIu32", NULL, NULL, 0) failed"
-                " with %d: %s\n",
-                c, wait_start, -ret, strerror(-ret));
-        printf("see stderr\n");
-        abort();
+        PELOG(FATAL, -ret, "FUTEX_WAIT(%p, %" PRIu32 ", NULL, NULL, 0) failed",
+              c, wait_start);
       }
     }
     // Relock the mutex now that we're done waiting.
@@ -251,11 +239,7 @@
         // Try again if it was because of a signal or somebody else unlocked it
         // before we went to sleep.
         if (ret == -EINTR || ret == -EWOULDBLOCK) continue;
-        fprintf(stderr, "sync: FUTEX_WAIT(%p, 2, NULL, NULL, 0)"
-                " failed with %d: %s\n",
-                m, -ret, strerror(-ret));
-        printf("see stderr\n");
-        abort();
+        PELOG(FATAL, -ret, "FUTEX_WAIT(%p, 2, NULL, NULL, 0) failed", m);
       }
     }
     return;
@@ -270,11 +254,7 @@
   // Wake at most 1 person who is waiting in the kernel.
   const int ret = sys_futex_wake(c, 1);
   if (ret < 0) {
-    fprintf(stderr, "sync: FUTEX_WAKE(%p, 1, NULL, NULL, 0)"
-        " failed with %d: %s\n",
-        c, -ret, strerror(-ret));
-    printf("see stderr\n");
-    abort();
+    PELOG(FATAL, -ret, "FUTEX_WAKE(%p, 1, NULL, NULL, 0) failed", c);
   }
 }
 
@@ -285,10 +265,6 @@
   // mutex anyways.
   const int ret = sys_futex_requeue(c, 1, INT_MAX, m);
   if (ret < 0) {
-    fprintf(stderr, "sync: FUTEX_REQUEUE(%p, 1, INT_MAX, %p, 0)"
-        " failed with %d: %s\n",
-        c, m, -ret, strerror(-ret));
-    printf("see stderr\n");
-    abort();
+    PELOG(FATAL, -ret, "FUTEX_REQUEUE(%p, 1, INT_MAX, %p, 0) failed", c, m);
   }
 }
diff --git a/aos/linux_code/ipc_lib/ipc_lib.gyp b/aos/linux_code/ipc_lib/ipc_lib.gyp
index fe8b2e0..9b1e712 100644
--- a/aos/linux_code/ipc_lib/ipc_lib.gyp
+++ b/aos/linux_code/ipc_lib/ipc_lib.gyp
@@ -6,6 +6,9 @@
       'sources': [
         'aos_sync.c',
       ],
+      'dependencies': [
+        '<(AOS)/build/aos.gyp:logging_interface',
+      ],
     },
     {
       'target_name': 'core_lib',
@@ -29,6 +32,7 @@
       ],
       'dependencies': [
         'aos_sync',
+        '<(AOS)/build/aos.gyp:logging_interface',
       ],
       'export_dependent_settings': [
         'aos_sync',
diff --git a/aos/linux_code/ipc_lib/ipc_stress_test.cc b/aos/linux_code/ipc_lib/ipc_stress_test.cc
index 3067a20..c1dcb83 100644
--- a/aos/linux_code/ipc_lib/ipc_stress_test.cc
+++ b/aos/linux_code/ipc_lib/ipc_stress_test.cc
@@ -82,20 +82,16 @@
 void __attribute__((noreturn)) DoRunTest(
     Shared *shared, const char *(*test)[kTestMaxArgs], int pipes[2]) {
   if (close(pipes[0]) == -1) {
-    Die("close(%d) of read end of pipe failed with %d: %s\n",
-        pipes[0], errno, strerror(errno));
+    PDie("close(%d) of read end of pipe failed", pipes[0]);
   }
   if (close(STDIN_FILENO) == -1) {
-    Die("close(STDIN_FILENO(=%d)) failed with %d: %s\n",
-        STDIN_FILENO, errno, strerror(errno));
+    PDie("close(STDIN_FILENO(=%d)) failed", STDIN_FILENO);
   }
   if (dup2(pipes[1], STDOUT_FILENO) == -1) {
-    Die("dup2(%d, STDOUT_FILENO(=%d)) failed with %d: %s\n",
-        pipes[1], STDOUT_FILENO, errno, strerror(errno));
+    PDie("dup2(%d, STDOUT_FILENO(=%d)) failed", pipes[1], STDOUT_FILENO);
   }
   if (dup2(pipes[1], STDERR_FILENO) == -1) {
-    Die("dup2(%d, STDERR_FILENO(=%d)) failed with %d: %s\n",
-        pipes[1], STDERR_FILENO, errno, strerror(errno));
+    PDie("dup2(%d, STDERR_FILENO(=%d)) failed", pipes[1], STDERR_FILENO);
   }
 
   size_t size = kTestMaxArgs;
@@ -120,8 +116,7 @@
   }
   args[size] = NULL;
   execv(executable.c_str(), const_cast<char *const *>(args));
-  Die("execv(%s, %p) failed with %d: %s\n",
-      executable.c_str(), args, errno, strerror(errno));
+  PDie("execv(%s, %p) failed", executable.c_str(), args);
 }
 
 void DoRun(Shared *shared) {
@@ -133,18 +128,17 @@
   int pipes[2];
   while (time::Time::Now() < shared->stop_time) {
     if (pipe(pipes) == -1) {
-      Die("pipe(%p) failed with %d: %s\n", &pipes, errno, strerror(errno));
+      PDie("pipe(%p) failed", &pipes);
     }
     switch (fork()) {
       case 0:  // in runner
         DoRunTest(shared, test, pipes);
       case -1:
-        Die("fork() failed with %d: %s\n", errno, strerror(errno));
+        PDie("fork() failed");
     }
 
     if (close(pipes[1]) == -1) {
-      Die("close(%d) of write end of pipe failed with %d: %s\n",
-          pipes[1], errno, strerror(errno));
+      PDie("close(%d) of write end of pipe failed", pipes[1]);
     }
 
     ::std::string output;
@@ -153,13 +147,11 @@
       ssize_t ret = read(pipes[0], &buffer, sizeof(buffer));
       if (ret == 0) {  // EOF
         if (close(pipes[0]) == -1) {
-          Die("close(%d) of pipe at EOF failed with %d: %s\n",
-              pipes[0], errno, strerror(errno));
+          PDie("close(%d) of pipe at EOF failed", pipes[0]);
         }
         break;
       } else if (ret == -1) {
-        Die("read(%d, %p, %zd) failed with %d: %s\n",
-            pipes[0], &buffer, sizeof(buffer), errno, strerror(errno));
+        PDie("read(%d, %p, %zd) failed", pipes[0], &buffer, sizeof(buffer));
       }
       output += ::std::string(buffer, ret);
     }
@@ -168,8 +160,7 @@
     while (true) {
       if (wait(&status) == -1) {
         if (errno == EINTR) continue;
-        Die("wait(%p) in child failed with %d: %s\n",
-            &status, errno, strerror(errno));
+        PDie("wait(%p) in child failed", &status);
       } else {
         break;
       }
@@ -207,7 +198,7 @@
       DoRun(shared);
       _exit(EXIT_SUCCESS);
     case -1:
-      Die("fork() of child failed with %d: %s\n", errno, strerror(errno));
+      PDie("fork() of child failed");
   }
 }
 
@@ -222,7 +213,7 @@
   char *temp = strdup(argv[0]);
   if (asprintf(const_cast<char **>(&shared->path),
                "%s/../tests", dirname(temp)) == -1) {
-    Die("asprintf failed with %d: %s\n", errno, strerror(errno));
+    PDie("asprintf failed");
   }
   free(temp);
 
@@ -237,7 +228,7 @@
       if (errno == EINTR) {
         --i;
       } else {
-        Die("wait(%p) failed with %d: %s\n", &status, errno, strerror(errno));
+        PDie("wait(%p) failed", &status);
       }
     }
     if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
diff --git a/aos/linux_code/ipc_lib/mutex.cpp b/aos/linux_code/ipc_lib/mutex.cpp
index 47fc92a..8c98204 100644
--- a/aos/linux_code/ipc_lib/mutex.cpp
+++ b/aos/linux_code/ipc_lib/mutex.cpp
@@ -1,7 +1,6 @@
 #include "aos/common/mutex.h"
 
 #include <inttypes.h>
-#include <errno.h>
 #include <stdio.h>
 #include <string.h>
 
@@ -20,8 +19,7 @@
 
 void Mutex::Lock() {
   if (mutex_grab(&impl_) != 0) {
-    LOG(FATAL, "mutex_grab(%p(=%" PRIu32 ")) failed because of %d: %s\n",
-        &impl_, impl_, errno, strerror(errno));
+    PLOG(FATAL, "mutex_grab(%p(=%" PRIu32 ")) failed", &impl_, impl_);
   }
 }
 
diff --git a/aos/linux_code/ipc_lib/raw_queue_test.cc b/aos/linux_code/ipc_lib/raw_queue_test.cc
index 67b687a..4196286 100644
--- a/aos/linux_code/ipc_lib/raw_queue_test.cc
+++ b/aos/linux_code/ipc_lib/raw_queue_test.cc
@@ -89,8 +89,7 @@
         if (errno == ESRCH) {
           printf("process %jd was already dead\n", static_cast<intmax_t>(pid_));
         } else {
-          fprintf(stderr, "kill(SIGKILL, %jd) failed with %d: %s\n",
-                  static_cast<intmax_t>(pid_), errno, strerror(errno));
+          PLOG(FATAL, "kill(SIGKILL, %jd) failed", static_cast<intmax_t>(pid_));
         }
         return;
       }
@@ -174,7 +173,7 @@
         mutex_unlock(lock);
         exit(EXIT_SUCCESS);
       case -1:  // parent failure
-        LOG(ERROR, "fork() failed with %d: %s\n", errno, strerror(errno));
+        PLOG(ERROR, "fork() failed");
         return std::unique_ptr<ForkedProcess>();
       default:  // parent
         return std::unique_ptr<ForkedProcess>(new ForkedProcess(pid, lock));
diff --git a/aos/linux_code/ipc_lib/shared_mem.c b/aos/linux_code/ipc_lib/shared_mem.c
index c368e38..a132233 100644
--- a/aos/linux_code/ipc_lib/shared_mem.c
+++ b/aos/linux_code/ipc_lib/shared_mem.c
@@ -10,6 +10,7 @@
 #include <stdlib.h>
 
 #include "aos/linux_code/ipc_lib/core_lib.h"
+#include "aos/common/logging/logging.h"
 
 // the path for the shared memory segment. see shm_open(3) for restrictions
 #define AOS_SHM_NAME "/aos_shared_mem"
@@ -37,7 +38,7 @@
 struct aos_core *global_core = NULL;
 
 // TODO(brians): madvise(2) it to put this shm in core dumps.
-int aos_core_create_shared_mem(enum aos_core_create to_create) {
+void aos_core_create_shared_mem(enum aos_core_create to_create) {
   static struct aos_core global_core_data;
   global_core = &global_core_data;
 
@@ -59,8 +60,7 @@
       if (shm == -1 && errno == EEXIST) {
         printf("shared_mem: going to shm_unlink(%s)\n", global_core->shm_name);
         if (shm_unlink(global_core->shm_name) == -1) {
-          fprintf(stderr, "shared_mem: shm_unlink(%s) failed with of %d: %s\n",
-                  global_core->shm_name, errno, strerror(errno));
+          PLOG(WARNING, "shm_unlink(%s) failed", global_core->shm_name);
           break;
         }
       } else {
@@ -73,46 +73,35 @@
     global_core->owner = 0;
   }
   if (shm == -1) {
-    fprintf(stderr, "shared_mem:"
-                    " shm_open(%s, O_RDWR [| O_CREAT | O_EXCL, 0|0666)"
-                    " failed with %d: %s\n",
-            global_core->shm_name, errno, strerror(errno));
-    return -1;
+    PLOG(FATAL, "shm_open(%s, O_RDWR [| O_CREAT | O_EXCL, 0|0666) failed",
+         global_core->shm_name);
   }
   if (global_core->owner) {
     if (ftruncate(shm, SIZEOFSHMSEG) == -1) {
-      fprintf(stderr, "shared_mem: fruncate(%d, 0x%zx) failed with %d: %s\n",
-        shm, (size_t)SIZEOFSHMSEG, errno, strerror(errno));
-      return -1;
+      PLOG(FATAL, "fruncate(%d, 0x%zx) failed", shm, (size_t)SIZEOFSHMSEG);
     }
   }
   void *shm_address = mmap(
       (void *)SHM_START, SIZEOFSHMSEG, PROT_READ | PROT_WRITE,
       MAP_SHARED | MAP_FIXED | MAP_LOCKED | MAP_POPULATE, shm, 0);
   if (shm_address == MAP_FAILED) {
-    fprintf(stderr, "shared_mem: mmap(%p, 0x%zx, stuff, stuff, %d, 0) failed"
-            " with %d: %s\n",
-            (void *)SHM_START, (size_t)SIZEOFSHMSEG, shm,
-            errno, strerror(errno));
-    return -1;
+    PLOG(FATAL, "shared_mem: mmap(%p, 0x%zx, stuff, stuff, %d, 0) failed",
+         (void *)SHM_START, (size_t)SIZEOFSHMSEG, shm);
   }
   printf("shared_mem: shm at: %p\n", shm_address);
   if (close(shm) == -1) {
-    printf("shared_mem: close(%d(=shm) failed with %d: %s\n",
-        shm, errno, strerror(errno));
+    PLOG(WARNING, "close(%d(=shm) failed", shm);
   }
   if (shm_address != (void *)SHM_START) {
-    fprintf(stderr, "shared_mem: shm isn't at hard-coded %p. at %p instead\n",
+    LOG(FATAL, "shm isn't at hard-coded %p. at %p instead\n",
         (void *)SHM_START, shm_address);
-    return -1;
   }
-  int r = aos_core_use_address_as_shared_mem(shm_address, SIZEOFSHMSEG);
-  fprintf(stderr, "shared_mem: end of create_shared_mem owner=%d r=%d\n",
-          global_core->owner, r);
-  return r;
+  aos_core_use_address_as_shared_mem(shm_address, SIZEOFSHMSEG);
+  LOG(INFO, "shared_mem: end of create_shared_mem owner=%d\n",
+          global_core->owner);
 }
 
-int aos_core_use_address_as_shared_mem(void *address, size_t size) {
+void aos_core_use_address_as_shared_mem(void *address, size_t size) {
   global_core->mem_struct = address;
   global_core->size = size;
   global_core->shared_mem =
@@ -123,28 +112,22 @@
     futex_set(&global_core->mem_struct->creation_condition);
   } else {
     if (futex_wait(&global_core->mem_struct->creation_condition) != 0) {
-      fprintf(stderr, "waiting on creation_condition failed\n");
-      return -1;
+      LOG(FATAL, "waiting on creation_condition failed\n");
     }
   }
-  return 0;
 }
 
-int aos_core_free_shared_mem(){
+void aos_core_free_shared_mem() {
   void *shm_address = global_core->shared_mem;
-      if (munmap((void *)SHM_START, SIZEOFSHMSEG) == -1) {
-          fprintf(stderr, "shared_mem: munmap(%p, 0x%zx) failed with %d: %s\n",
-        shm_address, (size_t)SIZEOFSHMSEG, errno, strerror(errno));
-          return -1;
-      }
-  if (global_core->owner) {
-        if (shm_unlink(global_core->shm_name)) {
-          fprintf(stderr, "shared_mem: shm_unlink(%s) failed with %d: %s\n",
-                  global_core->shm_name, errno, strerror(errno));
-            return -1;
-        }
+  if (munmap((void *)SHM_START, SIZEOFSHMSEG) == -1) {
+    PLOG(FATAL, "munmap(%p, 0x%zx) failed", shm_address,
+         (size_t)SIZEOFSHMSEG);
   }
-  return 0;
+  if (global_core->owner) {
+    if (shm_unlink(global_core->shm_name)) {
+      PLOG(FATAL, "shared_mem: shm_unlink(%s) failed", global_core->shm_name);
+    }
+  }
 }
 
 int aos_core_is_init(void) {
diff --git a/aos/linux_code/ipc_lib/shared_mem.h b/aos/linux_code/ipc_lib/shared_mem.h
index edab4d0..6968df7 100644
--- a/aos/linux_code/ipc_lib/shared_mem.h
+++ b/aos/linux_code/ipc_lib/shared_mem.h
@@ -66,10 +66,10 @@
 // should be set correctly there.
 // The owner should verify that the first sizeof(mutex) of data is set to 0
 // before passing the memory to this function.
-int aos_core_use_address_as_shared_mem(void *address, size_t size);
+void aos_core_use_address_as_shared_mem(void *address, size_t size);
 
-int aos_core_create_shared_mem(enum aos_core_create to_create);
-int aos_core_free_shared_mem(void);
+void aos_core_create_shared_mem(enum aos_core_create to_create);
+void aos_core_free_shared_mem(void);
 
 // Returns whether or not the shared memory system is active.
 int aos_core_is_init(void);
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);
 
diff --git a/aos/linux_code/output/HTTPServer.cpp b/aos/linux_code/output/HTTPServer.cpp
index 1703d39..d18572b 100644
--- a/aos/linux_code/output/HTTPServer.cpp
+++ b/aos/linux_code/output/HTTPServer.cpp
@@ -5,6 +5,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <string.h>
+#include <errno.h>
 
 #include <memory>
 
@@ -81,8 +82,8 @@
                    const char *directory) {
   char *temp;
   if (asprintf(&temp, "%s/%s", directory, path) == -1) {
-    LOG(WARNING, "asprintf(%p, \"%%s/%%s\", %p, %p) failed with %d: %s\n",
-        &temp, directory, path, errno, strerror(errno));
+    PLOG(WARNING, "asprintf(%p, \"%%s/%%s\", %p, %p) failed",
+         &temp, directory, path);
     evhttp_send_error(request, HTTP_INTERNAL, NULL);
     return -1;
   }
@@ -93,8 +94,7 @@
       evhttp_send_error(request, HTTP_NOTFOUND, NULL);
       return -1;
     }
-    LOG(ERROR, "open('%s', 0) failed with %d: %s\n", filename.get(),
-        errno, strerror(errno));
+    PLOG(ERROR, "open('%s', 0) failed", filename.get(),
     evhttp_send_error(request, HTTP_INTERNAL, NULL);
     return -1;
   }
@@ -104,8 +104,7 @@
 off_t GetSize(int file) {
   struct stat info;
   if (fstat(file, &info) == -1) {
-    LOG(ERROR, "stat(%d, %p) failed with %d: %s\n", file, &info,
-        errno, strerror(errno));
+    PLOG(ERROR, "stat(%d, %p) failed", file, &info);
     return -1;
   }
   return info.st_size;
diff --git a/aos/linux_code/starter/netconsole.cc b/aos/linux_code/starter/netconsole.cc
index f624673..4d32afe 100644
--- a/aos/linux_code/starter/netconsole.cc
+++ b/aos/linux_code/starter/netconsole.cc
@@ -92,9 +92,8 @@
       }
       if (read_bytes == -1) {
         if (errno != EINTR) {
-          LOG(FATAL, "read(%d, %p, %zd) failed with %d: %s\n",
-              to_copy->input, buffer + position, position - sizeof(buffer),
-              errno, strerror(errno));
+          PLOG(FATAL, "read(%d, %p, %zd) failed",
+               to_copy->input, buffer + position, position - sizeof(buffer));
         }
       } else if (read_bytes == 0 && to_copy->interface_address == NULL) {
         // read(2) says that this means EOF
@@ -111,8 +110,8 @@
       ssize_t sent_bytes = write(to_copy->output, buffer, position);
       if (sent_bytes == -1) {
         if (errno != EINTR) {
-          LOG(FATAL, "write(%d, %p, %zd) failed with %d: %s\n",
-              to_copy->output, buffer, position, errno, strerror(errno));
+          PLOG(FATAL, "write(%d, %p, %zd) failed",
+               to_copy->output, buffer, position);
         }
       } else if (sent_bytes != 0) {
         if (sent_bytes == position) {
@@ -129,6 +128,7 @@
 int NetconsoleMain(int argc, char **argv) {
   WriteCoreDumps();
   logging::Init();
+  logging::AddImplementation(new logging::StreamLogImplementation(stdout));
 
   int input, output;
   if (argc > 1) {
@@ -136,12 +136,9 @@
     if (output == -1) {
       if (errno == EACCES || errno == ELOOP || errno == ENOSPC ||
           errno == ENOTDIR || errno == EROFS || errno == ETXTBSY) {
-        fprintf(stderr, "Opening output file '%s' failed because of %s.\n",
-                argv[1], strerror(errno));
-        exit(EXIT_FAILURE);
+        PLOG(FATAL, "opening output file '%s' failed", argv[1]);
       }
-      LOG(FATAL, "open('%s', stuff, 0644) failed with %d: %s\n", argv[1],
-          errno, strerror(errno));
+      PLOG(FATAL, "open('%s', stuff, 0644) failed", argv[1]);
     }
     fprintf(stderr, "Writing output to '%s'.\n", argv[1]);
     input = -1;
@@ -157,20 +154,16 @@
 
   int from_crio = socket(AF_INET, SOCK_DGRAM, 0);
   if (from_crio == -1) {
-    LOG(FATAL, "socket(AF_INET, SOCK_DGRAM, 0) failed with %d: %s\n",
-        errno, strerror(errno));
+    PLOG(FATAL, "socket(AF_INET, SOCK_DGRAM, 0) failed");
   }
   if (setsockopt(from_crio, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) == -1) {
-    LOG(FATAL, "SOL_SOCKET::SO_REUSEADDR=%d(%d) failed with %d: %s\n",
-        on, from_crio, errno, strerror(errno));
+    PLOG(FATAL, "SOL_SOCKET::SO_REUSEADDR=%d(%d) failed", on, from_crio);
   }
   if (setsockopt(from_crio, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on)) == -1) {
-    LOG(FATAL, "SOL_SOCKET::SO_BROADCAST=%d(%d) failed with %d: %s\n",
-        on, from_crio, errno, strerror(errno));
+    PLOG(FATAL, "SOL_SOCKET::SO_BROADCAST=%d(%d) failed", on, from_crio);
   }
   if (setsockopt(from_crio, IPPROTO_IP, IP_PKTINFO, &on, sizeof(on)) == -1) {
-    LOG(FATAL, "IPROTO_IP::IP_PKTINFO=%d(%d) failed with %d: %s\n",
-        on, from_crio, errno, strerror(errno));
+    PLOG(FATAL, "IPROTO_IP::IP_PKTINFO=%d(%d) failed", on, from_crio);
   }
   union {
     struct sockaddr_in in;
@@ -188,8 +181,8 @@
                               ::aos::NetworkAddress::kCRIO);
 
   if (bind(from_crio, &address.addr, sizeof(address)) == -1) {
-    LOG(FATAL, "bind(%d, %p, %zu) failed with %d: %s\n",
-        from_crio, &address.addr, sizeof(address), errno, strerror(errno));
+    PLOG(FATAL, "bind(%d, %p, %zu) failed",
+         from_crio, &address.addr, sizeof(address));
   }
 
   pthread_t input_thread, output_thread;
@@ -202,36 +195,33 @@
   if (input != -1) {
     int to_crio = socket(AF_INET, SOCK_DGRAM, 0);
     if (to_crio == -1) {
-      LOG(FATAL, "socket(AF_INET, SOCK_DGRAM, 0) failed with %d: %s\n",
-          errno, strerror(errno));
+      PLOG(FATAL, "socket(AF_INET, SOCK_DGRAM, 0) failed");
     }
     if (setsockopt(to_crio, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) == -1) {
-      LOG(FATAL, "SOL_SOCKET::SO_REUSEADDR=%d(%d) failed with %d: %s\n",
-          on, to_crio, errno, strerror(errno));
+      PLOG(FATAL, "SOL_SOCKET::SO_REUSEADDR=%d(%d) failed", on, to_crio);
     }
     address.in.sin_port = hton<uint16_t>(6668);
     if (connect(to_crio, &address.addr, sizeof(address)) == -1) {
-      LOG(FATAL, "connect(%d, %p, %zu) failed with %d: %s\n",
-          to_crio, &address.addr, sizeof(address), errno, strerror(errno));
+      PLOG(FATAL, "connect(%d, %p, %zu) failed",
+           to_crio, &address.addr, sizeof(address));
     }
     FDsToCopy input_fds{input, to_crio, nullptr, nullptr};
     if (pthread_create(&input_thread, NULL, FDCopyThread, &input_fds) == -1) {
-      LOG(FATAL, "pthread_create(%p, NULL, %p, %p) failed with %d: %s\n",
-          &input_thread, FDCopyThread, &input_fds, errno, strerror(errno));
+      PLOG(FATAL, "pthread_create(%p, NULL, %p, %p) failed",
+           &input_thread, FDCopyThread, &input_fds);
     }
   }
 
   address.in.sin_addr = ::aos::configuration::GetOwnIPAddress();
   FDsToCopy output_fds{from_crio, output, &address.in, &crio_address.in};
   if (pthread_create(&output_thread, NULL, FDCopyThread, &output_fds) == -1) {
-    LOG(FATAL, "pthread_create(%p, NULL, %p, %p) failed with %d: %s\n",
-        &output_thread, FDCopyThread, &output_fds, errno, strerror(errno));
+    PLOG(FATAL, "pthread_create(%p, NULL, %p, %p) failed",
+         &output_thread, FDCopyThread, &output_fds);
   }
 
   // input_thread will finish when stdin gets an EOF
   if (pthread_join((input == -1) ? output_thread : input_thread, NULL) == -1) {
-    LOG(FATAL, "pthread_join(a_thread, NULL) failed with %d: %s\n",
-        errno, strerror(errno));
+    PLOG(FATAL, "pthread_join(a_thread, NULL) failed");
   }
   exit(EXIT_SUCCESS);
 }
diff --git a/aos/linux_code/starter/starter.cc b/aos/linux_code/starter/starter.cc
index 114148f..800acd9 100644
--- a/aos/linux_code/starter/starter.cc
+++ b/aos/linux_code/starter/starter.cc
@@ -112,8 +112,7 @@
     assert(watch_to_remove_ == -1);
 
     if (inotify_rm_watch(notify_fd, watch_) == -1) {
-      LOG(WARNING, "inotify_rm_watch(%d, %d) failed with %d: %s\n",
-          notify_fd, watch_, errno, strerror(errno));
+      PLOG(WARNING, "inotify_rm_watch(%d, %d) failed", notify_fd, watch_);
     }
     watch_to_remove_ = watch_;
     watch_ = -1;
@@ -159,10 +158,9 @@
                                                      IN_DELETE_SELF |
                                                      IN_MOVE_SELF));
     if (watch_ == -1) {
-      LOG(FATAL, "inotify_add_watch(%d, %s,"
-          " %s ? IN_CREATE : (IN_ATTRIB | IN_MODIFY)) failed with %d: %s\n",
-          notify_fd, filename_.c_str(), create_ ? "true" : "false",
-          errno, strerror(errno));
+      PLOG(FATAL, "inotify_add_watch(%d, %s,"
+                  " %s ? IN_CREATE : (IN_ATTRIB | IN_MODIFY)) failed",
+           notify_fd, filename_.c_str(), create_ ? "true" : "false");
     }
     watchers[watch_] = this;
     LOG(DEBUG, "watch for %s is %d\n", filename_.c_str(), watch_);
@@ -174,8 +172,7 @@
     unsigned int to_read;
     // Use FIONREAD to figure out how many bytes there are to read.
     if (ioctl(notify_fd, FIONREAD, &to_read) < 0) {
-      LOG(FATAL, "FIONREAD(%d, %p) failed with %d: %s\n",
-          notify_fd, &to_read, errno, strerror(errno));
+      PLOG(FATAL, "FIONREAD(%d, %p) failed", notify_fd, &to_read);
     }
     inotify_event *notifyevt = static_cast<inotify_event *>(malloc(to_read));
     const char *end = reinterpret_cast<char *>(notifyevt) + to_read;
@@ -183,8 +180,7 @@
 
     ssize_t ret = read(notify_fd, notifyevt, to_read);
     if (ret < 0) {
-      LOG(FATAL, "read(%d, %p, %u) failed with %d: %s\n",
-          notify_fd, notifyevt, to_read, errno, strerror(errno));
+      PLOG(FATAL, "read(%d, %p, %u) failed", notify_fd, notifyevt, to_read);
     }
     if (static_cast<size_t>(ret) != to_read) {
       LOG(ERROR, "read(%d, %p, %u) returned %zd instead of %u\n",
@@ -277,8 +273,7 @@
   errno = 0;
   FILE *pipe = popen(command.c_str(), "r");
   if (pipe == NULL) {
-    LOG(FATAL, "popen(\"%s\", \"r\") failed with %d: %s\n",
-        command.c_str(), errno, strerror(errno));
+    PLOG(FATAL, "popen(\"%s\", \"r\") failed", command.c_str());
   }
 
   // result_size is how many bytes result is currently allocated to.
@@ -290,8 +285,7 @@
       result_size *= 2;
       void *new_result = realloc(result.get(), result_size);
       if (new_result == NULL) {
-        LOG(FATAL, "realloc(%p, %zd) failed because of %d: %s\n",
-            result.get(), result_size, errno, strerror(errno));
+        PLOG(FATAL, "realloc(%p, %zd) failed", result.get(), result_size);
       } else {
         result.release();
         result = unique_c_ptr<char>(static_cast<char *>(new_result));
@@ -303,8 +297,8 @@
     // because of an error.
     if (ret < result_size - read) {
       if (ferror(pipe)) {
-        LOG(FATAL, "couldn't finish reading output of \"%s\"\n",
-            command.c_str());
+        PLOG(FATAL, "couldn't finish reading output of \"%s\"\n",
+             command.c_str());
       }
     }
     read += ret;
@@ -322,8 +316,7 @@
 
   int child_status = pclose(pipe);
   if (child_status == -1) {
-    LOG(FATAL, "pclose(%p) failed with %d: %s\n", pipe,
-        errno, strerror(errno));
+    PLOG(FATAL, "pclose(%p) failed", pipe);
   }
 
   if (child_status != 0) {
@@ -457,8 +450,8 @@
     if (stat_at_start_valid_) {
       struct stat current_stat;
       if (stat(original_binary_.c_str(), &current_stat) == -1) {
-        LOG(FATAL, "stat(%s, %p) failed with %d: %s\n",
-            original_binary_.c_str(), &current_stat, errno, strerror(errno));
+        PLOG(FATAL, "stat(%s, %p) failed",
+             original_binary_.c_str(), &current_stat);
       }
       if (current_stat.st_mtime == stat_at_start_.st_mtime) {
         LOG(DEBUG, "ignoring trigger for %s because mtime didn't change\n",
@@ -474,8 +467,7 @@
     if (pid_ != -1) {
       LOG(DEBUG, "sending SIGTERM to child %d to restart it\n", pid_);
       if (kill(pid_, SIGTERM) == -1) {
-        LOG(WARNING, "kill(%d, SIGTERM) failed with %d: %s\n",
-            pid_, errno, strerror(errno));
+        PLOG(WARNING, "kill(%d, SIGTERM) failed", pid_);
       }
       CheckDiedStatus *status = new CheckDiedStatus();
       status->self = this;
@@ -497,8 +489,7 @@
     if (pid_ == old_pid) {
       LOG(WARNING, "child %d refused to die\n", old_pid);
       if (kill(old_pid, SIGKILL) == -1) {
-        LOG(WARNING, "kill(%d, SIGKILL) failed with %d: %s\n",
-            old_pid, errno, strerror(errno));
+        PLOG(WARNING, "kill(%d, SIGKILL) failed", old_pid);
       }
     }
   }
@@ -513,8 +504,7 @@
       LOG(WARNING, "calling Start() but already have child %d running\n",
           pid_);
       if (kill(pid_, SIGKILL) == -1) {
-        LOG(WARNING, "kill(%d, SIGKILL) failed with %d: %s\n",
-            pid_, errno, strerror(errno));
+        PLOG(WARNING, "kill(%d, SIGKILL) failed", pid_);
         return;
       }
       pid_ = -1;
@@ -523,17 +513,16 @@
     // Remove the name that we run from (ie from a previous execution) and then
     // hard link the real filename to it.
     if (unlink(binary_.c_str()) != 0 && errno != ENOENT) {
-      LOG(FATAL, "removing %s failed because of %d: %s\n",
-          binary_.c_str(), errno, strerror(errno));
+      PLOG(FATAL, "removing %s failed", binary_.c_str());
     }
     if (link(original_binary_.c_str(), binary_.c_str()) != 0) {
-      LOG(FATAL, "link('%s', '%s') failed because of %d: %s\n",
-          original_binary_.c_str(), binary_.c_str(), errno, strerror(errno));
+      PLOG(FATAL, "link('%s', '%s') failed",
+           original_binary_.c_str(), binary_.c_str());
     }
 
     if (stat(original_binary_.c_str(), &stat_at_start_) == -1) {
-      LOG(FATAL, "stat(%s, %p) failed with %d: %s\n",
-          original_binary_.c_str(), &stat_at_start_, errno, strerror(errno));
+      PLOG(FATAL, "stat(%s, %p) failed",
+           original_binary_.c_str(), &stat_at_start_);
     }
     stat_at_start_valid_ = true;
 
@@ -547,13 +536,11 @@
       // The const_cast is safe because no code that might care if it gets
       // modified can run afterwards.
       execv(binary_.c_str(), const_cast<char **>(argv));
-      LOG(FATAL, "execv(%s, %p) failed with %d: %s\n",
-          binary_.c_str(), argv, errno, strerror(errno));
+      PLOG(FATAL, "execv(%s, %p) failed", binary_.c_str(), argv);
       _exit(EXIT_FAILURE);
     }
     if (pid_ == -1) {
-      LOG(FATAL, "forking to run \"%s\" failed with %d: %s\n",
-          binary_.c_str(), errno, strerror(errno));
+      PLOG(FATAL, "forking to run \"%s\" failed", binary_.c_str());
     }
     LOG(DEBUG, "started \"%s\" successfully\n", binary_.c_str());
   }
@@ -657,7 +644,7 @@
     siginfo_t infop;
     infop.si_pid = 0;
     if (waitid(P_ALL, 0, &infop, WEXITED | WSTOPPED | WNOHANG) != 0) {
-      LOG(WARNING, "waitid failed with %d: %s", errno, strerror(errno));
+      PLOG(WARNING, "waitid failed");
       continue;
     }
     // If there are no more child process deaths to process.
@@ -720,7 +707,7 @@
   // bring up shm is ok
 
   if (setpgid(0 /*self*/, 0 /*make PGID the same as PID*/) != 0) {
-    LOG(FATAL, "setpgid(0, 0) failed with %d: %s\n", errno, strerror(errno));
+    PLOG(FATAL, "setpgid(0, 0) failed");
   }
 
   // Make sure that we kill all children when we exit.
@@ -745,7 +732,7 @@
   core_touch_file += std::to_string(static_cast<intmax_t>(getpid()));
   core_touch_file += ".core_touch_file";
   if (system(("touch '" + core_touch_file + "'").c_str()) != 0) {
-    LOG(FATAL, "running `touch '%s'` failed\n", core_touch_file.c_str());
+    PLOG(FATAL, "running `touch '%s'` failed\n", core_touch_file.c_str());
   }
   FileWatch core_touch_file_watch(core_touch_file, Run, NULL);
   core = unique_ptr<Child>(
@@ -753,12 +740,11 @@
 
   FILE *pid_file = fopen("/tmp/starter.pid", "w");
   if (pid_file == NULL) {
-    LOG(FATAL, "fopen(\"/tmp/starter.pid\", \"w\") failed with %d: %s\n",
-        errno, strerror(errno));
+    PLOG(FATAL, "fopen(\"/tmp/starter.pid\", \"w\") failed");
   } else {
     if (fprintf(pid_file, "%d", core->pid()) == -1) {
-      LOG(WARNING, "fprintf(%p, \"%%d\", %d) failed with %d: %s\n",
-          pid_file, core->pid(), errno, strerror(errno));
+      PLOG(WARNING, "fprintf(%p, \"%%d\", %d) failed",
+           pid_file, core->pid());
     }
     fclose(pid_file);
   }