servicemanager: include caller info in logs
In cases like b/329039146, it can be difficult to understand
where spam is coming from, because we only have the logs.
This adds caller information to servicemanager logs, so that
we can easily identify what is causing an issue, even if we
don't have logs.
Btw - passing around a calling context like this, instead of
referencing thread locals, is how I think we should do all
ACL with binder, but that's another story.
Example log output:
03-27 00:32:02.242 0 0 I servicemanager: Caller(pid=2145,uid=1001,sid=u:r:radio:s0) Found android.hardware.radio.data.IRadioData/slot1 in device VINTF manifest.
Bug: N/A
Test: N/A
Change-Id: Iea45e4d22f28f28592eb73a129117204c6c8e814
diff --git a/cmds/servicemanager/Access.cpp b/cmds/servicemanager/Access.cpp
index 711038c..8098724 100644
--- a/cmds/servicemanager/Access.cpp
+++ b/cmds/servicemanager/Access.cpp
@@ -22,6 +22,8 @@
#include <selinux/android.h>
#include <selinux/avc.h>
+#include <sstream>
+
namespace android {
#ifdef VENDORSERVICEMANAGER
@@ -80,6 +82,12 @@
}
#endif
+std::string Access::CallingContext::toDebugString() const {
+ std::stringstream ss;
+ ss << "Caller(pid=" << debugPid << ",uid=" << uid << ",sid=" << sid << ")";
+ return ss.str();
+}
+
Access::Access() {
#ifdef __ANDROID__
union selinux_callback cb;