Snap for 11914274 from 81df8941c5ac97fa49f6e03ad38b7fb5b28924cb to 24Q3-release

Change-Id: I4e46881aa437ccfbb5e55881ba0e9f0e4985f43e
diff --git a/include/android-base/logging.h b/include/android-base/logging.h
index 59a1e89..7ed0478 100644
--- a/include/android-base/logging.h
+++ b/include/android-base/logging.h
@@ -111,6 +111,10 @@
 // Loggers for use with InitLogging/SetLogger.
 
 // Log to the kernel log (dmesg).
+// Note that you'll likely need to inherit a /dev/kmsg fd from init.
+// Add `file /dev/kmsg w` to your .rc file.
+// You'll also need to `allow <your_domain> kmsg_device:chr_file w_file_perms;`
+// in `system/sepolocy/private/<your_domain>.te`.
 void KernelLogger(LogId log_buffer_id, LogSeverity severity, const char* tag, const char* file, unsigned int line, const char* message);
 // Log to stderr in the full logcat format (with pid/tid/time/tag details).
 void StderrLogger(LogId log_buffer_id, LogSeverity severity, const char* tag, const char* file, unsigned int line, const char* message);
diff --git a/logging.cpp b/logging.cpp
index facebc3..51f0ef9 100644
--- a/logging.cpp
+++ b/logging.cpp
@@ -100,7 +100,11 @@
 #if defined(__linux__)
 static int OpenKmsg() {
 #if defined(__ANDROID__)
-  // pick up 'file /dev/kmsg w' environment from daemon's init rc file
+  // Pick up `file /dev/kmsg w` environment from a daemon's init .rc file.
+  // If you're wondering why you're not seeing kernel logs from your daemon,
+  // it's probably because you're missing that line in your .rc file!
+  // You'll also need to `allow <your_domain> kmsg_device:chr_file w_file_perms;`
+  // in `system/sepolocy/private/<your_domain>.te`.
   const auto val = getenv("ANDROID_FILE__dev_kmsg");
   if (val != nullptr) {
     int fd;
@@ -110,6 +114,8 @@
     }
   }
 #endif
+  // Note that this is _not_ the normal case: this is primarily for init itself.
+  // Most other code will need to inherit an fd from init, as described above.
   return TEMP_FAILURE_RETRY(open("/dev/kmsg", O_WRONLY | O_CLOEXEC));
 }
 #endif