The main thread should just INHERIT its scheduler attributes.
Explicitly setting SCHED_OTHER/0 was causing SELinux denials:
02-08 09:58:05.430 661 661 I auditd : type=1400 audit(0.0:20): avc: denied { sys_nice } for comm="grep" capability=23 scontext=u:r:init-qcom-devstart-sh:s0 tcontext=u:r:init-qcom-devstart-sh:s0 tclass=capability permissive=0
02-08 09:58:05.430 662 662 I auditd : type=1400 audit(0.0:21): avc: denied { sys_nice } for comm="sed" capability=23 scontext=u:r:init-qcom-devstart-sh:s0 tcontext=u:r:init-qcom-devstart-sh:s0 tclass=capability permissive=0
Also use public pthread API rather than modifying the main thread's
pthread_attr_t directly.
Bug: http://b/68328561
Test: strace -f -e true
Change-Id: I65b7ab3ce285a2901a6eaacb243000c780883c3a
diff --git a/libc/bionic/__libc_init_main_thread.cpp b/libc/bionic/__libc_init_main_thread.cpp
index 5004e24..efa7dee 100644
--- a/libc/bionic/__libc_init_main_thread.cpp
+++ b/libc/bionic/__libc_init_main_thread.cpp
@@ -85,9 +85,14 @@
// thread's stack rather than on the heap.
// The main thread has no mmap allocated space for stack or pthread_internal_t.
main_thread.mmap_size = 0;
+
pthread_attr_init(&main_thread.attr);
- main_thread.attr.guard_size = 0; // The main thread has no guard page.
- main_thread.attr.stack_size = 0; // User code should never see this; we'll compute it when asked.
+ // We don't want to explicitly set the main thread's scheduler attributes (http://b/68328561).
+ pthread_attr_setinheritsched(&main_thread.attr, PTHREAD_INHERIT_SCHED);
+ // The main thread has no guard page.
+ pthread_attr_setguardsize(&main_thread.attr, 0);
+ // User code should never see this; we'll compute it when asked.
+ pthread_attr_setstacksize(&main_thread.attr, 0);
// The TLS stack guard is set from the global, so ensure that we've initialized the global
// before we initialize the TLS. Dynamic executables will initialize their copy of the global