OSDN Git Service

servicemanager: selinux: set selinux callbacks early
authorSandeep Patil <sspatil@google.com>
Tue, 27 Dec 2016 20:40:45 +0000 (12:40 -0800)
committerSandeep Patil <sspatil@google.com>
Tue, 17 Jan 2017 04:39:16 +0000 (04:39 +0000)
SELinux library error logs are never be shown in logcat if
there's a failure before the callbacks are set. We missed
all logs from service context initialization because of this.

Bug: 33746484
Test: Restart new service manager to make sure context init logs
show up in logcat.

Change-Id: I5479cf5fe10ceb1a210eda26946b6ea344792e24
Signed-off-by: Sandeep Patil <sspatil@google.com>
cmds/servicemanager/service_manager.c

index a31e3c7..43c4c8b 100644 (file)
@@ -363,6 +363,7 @@ static int audit_callback(void *data, __unused security_class_t cls, char *buf,
 int main()
 {
     struct binder_state *bs;
+    union selinux_callback cb;
 
     bs = binder_open(128*1024);
     if (!bs) {
@@ -375,6 +376,11 @@ int main()
         return -1;
     }
 
+    cb.func_audit = audit_callback;
+    selinux_set_callback(SELINUX_CB_AUDIT, cb);
+    cb.func_log = selinux_log_callback;
+    selinux_set_callback(SELINUX_CB_LOG, cb);
+
     sehandle = selinux_android_service_context_handle();
     selinux_status_open(true);
 
@@ -388,11 +394,6 @@ int main()
         abort();
     }
 
-    union selinux_callback cb;
-    cb.func_audit = audit_callback;
-    selinux_set_callback(SELINUX_CB_AUDIT, cb);
-    cb.func_log = selinux_log_callback;
-    selinux_set_callback(SELINUX_CB_LOG, cb);
 
     binder_loop(bs, svcmgr_handler);