From 7abb52bcafa2f7b422dfe22c5ea275c2fa9e6201 Mon Sep 17 00:00:00 2001 From: Stephen Smalley Date: Wed, 26 Mar 2014 09:30:37 -0400 Subject: [PATCH] Send libselinux logging to logcat. Otherwise we can't readily see log messages from libselinux calls made by installd. Change-Id: I319b30c181470468fe19dd5fbe9251ef03f1163b Signed-off-by: Stephen Smalley --- cmds/installd/installd.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/cmds/installd/installd.c b/cmds/installd/installd.c index 40fc13f0e..a080ee618 100644 --- a/cmds/installd/installd.c +++ b/cmds/installd/installd.c @@ -541,6 +541,27 @@ static void drop_privileges() { } } +static int log_callback(int type, const char *fmt, ...) { + va_list ap; + int priority; + + switch (type) { + case SELINUX_WARNING: + priority = ANDROID_LOG_WARN; + break; + case SELINUX_INFO: + priority = ANDROID_LOG_INFO; + break; + default: + priority = ANDROID_LOG_ERROR; + break; + } + va_start(ap, fmt); + LOG_PRI_VA(priority, "SELinux", fmt, ap); + va_end(ap); + return 0; +} + int main(const int argc, const char *argv[]) { char buf[BUFFER_MAX]; struct sockaddr addr; @@ -550,6 +571,10 @@ int main(const int argc, const char *argv[]) { ALOGI("installd firing up\n"); + union selinux_callback cb; + cb.func_log = log_callback; + selinux_set_callback(SELINUX_CB_LOG, cb); + if (initialize_globals() < 0) { ALOGE("Could not initialize globals; exiting.\n"); exit(1);