Save on loginclass list locking by checking if caller already uses the struct

This commit is contained in:
mjg 2017-11-01 06:12:14 +00:00
parent 2b860577fc
commit 5c3ffebd3f
2 changed files with 12 additions and 1 deletions

View File

@ -421,6 +421,9 @@ proc0_init(void *dummy __unused)
struct thread *td;
struct ucred *newcred;
struct uidinfo tmpuinfo;
struct loginclass tmplc = {
.lc_name = "",
};
vm_paddr_t pageablemem;
int i;
@ -509,10 +512,11 @@ proc0_init(void *dummy __unused)
newcred->cr_uidinfo = newcred->cr_ruidinfo = &tmpuinfo;
newcred->cr_uidinfo = uifind(0);
newcred->cr_ruidinfo = uifind(0);
newcred->cr_loginclass = &tmplc;
newcred->cr_loginclass = loginclass_find("default");
/* End hack. creds get properly set later with thread_cow_get_proc */
curthread->td_ucred = NULL;
newcred->cr_prison = &prison0;
newcred->cr_loginclass = loginclass_find("default");
proc_set_cred_init(p, newcred);
#ifdef AUDIT
audit_cred_kproc0(newcred);

View File

@ -131,10 +131,17 @@ struct loginclass *
loginclass_find(const char *name)
{
struct loginclass *lc, *new_lc;
struct ucred *cred;
if (name[0] == '\0' || strlen(name) >= MAXLOGNAME)
return (NULL);
lc = cred->cr_loginclass;
if (strcmp(name, lc->lc_name) == 0) {
loginclass_hold(lc);
return (lc);
}
rw_rlock(&loginclasses_lock);
lc = loginclass_lookup(name);
rw_runlock(&loginclasses_lock);