Enable normal user to create a thread for the service
Default scheduling policy for a service thread is a real time SCHED_RR which requires superuser privilege to be set. To allow for creating task when invoked by normal user on Linux, apply policy depending on root or not root. Signed-off-by: Zbigniew Bodek <zbigniew.bodek@huawei.com> Change-Id: Ia0bdf9c3225e118b662f817c5d53c93092a33348
This commit is contained in:
parent
996939cacc
commit
a6456b24ed
|
@ -73,10 +73,23 @@ ThreadId THREAD_Create(Runnable run, void *argv, const ThreadAttr *attr)
|
||||||
pthread_attr_setinheritsched(&threadAttr, PTHREAD_EXPLICIT_SCHED);
|
pthread_attr_setinheritsched(&threadAttr, PTHREAD_EXPLICIT_SCHED);
|
||||||
#ifdef SAMGR_LINUX_ADAPTER
|
#ifdef SAMGR_LINUX_ADAPTER
|
||||||
struct sched_param sched = {attr->priority};
|
struct sched_param sched = {attr->priority};
|
||||||
|
int policy = SCHED_OTHER;
|
||||||
|
const int ROOT_UID = 0;
|
||||||
|
if (geteuid() == ROOT_UID) {
|
||||||
|
/*
|
||||||
|
* Real-time scheduling policy requires superuser privileges.
|
||||||
|
* Note: additionally, real-time thread can be scheduled before
|
||||||
|
* normal thread even if it yields CPU using sched_yield().
|
||||||
|
* To actually yield real-time thread one could
|
||||||
|
* sleep() rather than yield().
|
||||||
|
*/
|
||||||
|
policy = SCHED_RR;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
struct sched_param sched = {PRI_BUTT - attr->priority};
|
struct sched_param sched = {PRI_BUTT - attr->priority};
|
||||||
|
int policy = SCHED_RR;
|
||||||
#endif
|
#endif
|
||||||
pthread_attr_setschedpolicy(&threadAttr, SCHED_RR);
|
pthread_attr_setschedpolicy(&threadAttr, policy);
|
||||||
pthread_attr_setschedparam(&threadAttr, &sched);
|
pthread_attr_setschedparam(&threadAttr, &sched);
|
||||||
(void) pthread_once(&g_localKeyOnce, KeyCreate);
|
(void) pthread_once(&g_localKeyOnce, KeyCreate);
|
||||||
pthread_t threadId = 0;
|
pthread_t threadId = 0;
|
||||||
|
|
Loading…
Reference in New Issue