Verify that all processes sharing a channel are the same user

Otherwise, signal delivery generally doesn't work, which results in
confusing behavior.

Change-Id: I23f81003a3729d37f4500de5c5567f41e22d121c
diff --git a/aos/events/shm_event_loop.cc b/aos/events/shm_event_loop.cc
index dad62cd..57bcb1c 100644
--- a/aos/events/shm_event_loop.cc
+++ b/aos/events/shm_event_loop.cc
@@ -58,7 +58,7 @@
 }
 std::string ShmPath(const Channel *channel) {
   CHECK(channel->has_type());
-  return ShmFolder(channel) + channel->type()->str() + ".v1";
+  return ShmFolder(channel) + channel->type()->str() + ".v2";
 }
 
 class MMapedQueue {
diff --git a/aos/events/shm_event_loop_test.cc b/aos/events/shm_event_loop_test.cc
index 87411d2..0c39704 100644
--- a/aos/events/shm_event_loop_test.cc
+++ b/aos/events/shm_event_loop_test.cc
@@ -27,12 +27,12 @@
     }
 
     // Clean up anything left there before.
-    unlink((FLAGS_shm_base + "/test/aos.TestMessage.v1").c_str());
-    unlink((FLAGS_shm_base + "/test1/aos.TestMessage.v1").c_str());
-    unlink((FLAGS_shm_base + "/test2/aos.TestMessage.v1").c_str());
-    unlink((FLAGS_shm_base + "/test2/aos.TestMessage.v1").c_str());
-    unlink((FLAGS_shm_base + "/aos/aos.timing.Report.v1").c_str());
-    unlink((FLAGS_shm_base + "/aos/aos.logging.LogMessageFbs.v1").c_str());
+    unlink((FLAGS_shm_base + "/test/aos.TestMessage.v2").c_str());
+    unlink((FLAGS_shm_base + "/test1/aos.TestMessage.v2").c_str());
+    unlink((FLAGS_shm_base + "/test2/aos.TestMessage.v2").c_str());
+    unlink((FLAGS_shm_base + "/test2/aos.TestMessage.v2").c_str());
+    unlink((FLAGS_shm_base + "/aos/aos.timing.Report.v2").c_str());
+    unlink((FLAGS_shm_base + "/aos/aos.logging.LogMessageFbs.v2").c_str());
   }
 
   ~ShmEventLoopTestFactory() { FLAGS_override_hostname = ""; }
diff --git a/aos/ipc_lib/lockless_queue.cc b/aos/ipc_lib/lockless_queue.cc
index c323b8b..7126ffd 100644
--- a/aos/ipc_lib/lockless_queue.cc
+++ b/aos/ipc_lib/lockless_queue.cc
@@ -306,6 +306,7 @@
     }
 
     memory->next_queue_index.Invalidate();
+    memory->uid = getuid();
 
     for (size_t i = 0; i < memory->num_senders(); ++i) {
       ::aos::ipc_lib::Sender *s = memory->GetSender(i);
@@ -319,6 +320,8 @@
     // Signal everything is done.  This needs to be done last, so if we die, we
     // redo initialization.
     memory->initialized = true;
+  } else {
+    CHECK_EQ(getuid(), memory->uid) << ": UIDs must match for all processes";
   }
 
   return memory;
@@ -871,6 +874,8 @@
               << memory->next_queue_index.Load(queue_size).DebugString()
               << ::std::endl;
 
+  ::std::cout << "    uid_t uid = " << memory->uid << ::std::endl;
+
   ::std::cout << "  }" << ::std::endl;
   ::std::cout << "  AtomicIndex queue[" << queue_size << "] {" << ::std::endl;
   for (size_t i = 0; i < queue_size; ++i) {
diff --git a/aos/ipc_lib/lockless_queue_memory.h b/aos/ipc_lib/lockless_queue_memory.h
index cbe76a7..a10609c 100644
--- a/aos/ipc_lib/lockless_queue_memory.h
+++ b/aos/ipc_lib/lockless_queue_memory.h
@@ -50,6 +50,11 @@
   // A message is valid iff its internal index matches the index in the queue.
   AtomicQueueIndex next_queue_index;
 
+  // All processes using a queue need to be able to send messages to each other.
+  // We're going to require they have matching UIDs, which is sufficient to do
+  // that.
+  uid_t uid;
+
   // There is then memory allocated after this structure.  That memory is used
   // to store the messages, queue, watchers, and senders.  This is equivalent to
   // writing: