Get rid of lim_update_thread and cred_update_thread.
Their primary use was in thread_cow_update to free up old resources. Freeing had to be done with proc lock held and _cow_ funcs already knew how to free old structs.
This commit is contained in:
parent
752fc07d33
commit
cd672ca60f
@ -827,6 +827,7 @@ static void
|
||||
create_init(const void *udata __unused)
|
||||
{
|
||||
struct ucred *newcred, *oldcred;
|
||||
struct thread *td;
|
||||
int error;
|
||||
|
||||
error = fork1(&thread0, RFFDG | RFPROC | RFSTOPPED, 0, &initproc,
|
||||
@ -850,7 +851,9 @@ create_init(const void *udata __unused)
|
||||
audit_cred_proc1(newcred);
|
||||
#endif
|
||||
proc_set_cred(initproc, newcred);
|
||||
cred_update_thread(FIRST_THREAD_IN_PROC(initproc));
|
||||
td = FIRST_THREAD_IN_PROC(initproc);
|
||||
crfree(td->td_ucred);
|
||||
td->td_ucred = crhold(initproc->p_ucred);
|
||||
PROC_UNLOCK(initproc);
|
||||
sx_xunlock(&proctree_lock);
|
||||
crfree(oldcred);
|
||||
|
@ -1934,24 +1934,6 @@ cru2x(struct ucred *cr, struct xucred *xcr)
|
||||
ngroups * sizeof(*cr->cr_groups));
|
||||
}
|
||||
|
||||
/*
|
||||
* small routine to swap a thread's current ucred for the correct one taken
|
||||
* from the process.
|
||||
*/
|
||||
void
|
||||
cred_update_thread(struct thread *td)
|
||||
{
|
||||
struct proc *p;
|
||||
struct ucred *cred;
|
||||
|
||||
p = td->td_proc;
|
||||
cred = td->td_ucred;
|
||||
PROC_LOCK_ASSERT(p, MA_OWNED);
|
||||
td->td_ucred = crhold(p->p_ucred);
|
||||
if (cred != NULL)
|
||||
crfree(cred);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set initial process credentials.
|
||||
* Callers are responsible for providing the reference for provided credentials.
|
||||
|
@ -1436,17 +1436,3 @@ chgkqcnt(struct uidinfo *uip, int diff, rlim_t max)
|
||||
|
||||
return (chglimit(uip, &uip->ui_kqcnt, diff, max, "kqcnt"));
|
||||
}
|
||||
|
||||
void
|
||||
lim_update_thread(struct thread *td)
|
||||
{
|
||||
struct proc *p;
|
||||
struct plimit *lim;
|
||||
|
||||
p = td->td_proc;
|
||||
lim = td->td_limit;
|
||||
PROC_LOCK_ASSERT(p, MA_OWNED);
|
||||
td->td_limit = lim_hold(p->p_limit);
|
||||
if (lim != NULL)
|
||||
lim_free(lim);
|
||||
}
|
||||
|
@ -409,9 +409,9 @@ void
|
||||
thread_cow_free(struct thread *td)
|
||||
{
|
||||
|
||||
if (td->td_ucred)
|
||||
if (td->td_ucred != NULL)
|
||||
crfree(td->td_ucred);
|
||||
if (td->td_limit)
|
||||
if (td->td_limit != NULL)
|
||||
lim_free(td->td_limit);
|
||||
}
|
||||
|
||||
@ -419,15 +419,27 @@ void
|
||||
thread_cow_update(struct thread *td)
|
||||
{
|
||||
struct proc *p;
|
||||
struct ucred *oldcred;
|
||||
struct plimit *oldlimit;
|
||||
|
||||
p = td->td_proc;
|
||||
oldcred = NULL;
|
||||
oldlimit = NULL;
|
||||
PROC_LOCK(p);
|
||||
if (td->td_ucred != p->p_ucred)
|
||||
cred_update_thread(td);
|
||||
if (td->td_limit != p->p_limit)
|
||||
lim_update_thread(td);
|
||||
if (td->td_ucred != p->p_ucred) {
|
||||
oldcred = td->td_ucred;
|
||||
td->td_ucred = crhold(p->p_ucred);
|
||||
}
|
||||
if (td->td_limit != p->p_limit) {
|
||||
oldlimit = td->td_limit;
|
||||
td->td_limit = lim_hold(p->p_limit);
|
||||
}
|
||||
td->td_cowgen = p->p_cowgen;
|
||||
PROC_UNLOCK(p);
|
||||
if (oldcred != NULL)
|
||||
crfree(oldcred);
|
||||
if (oldlimit != NULL)
|
||||
lim_free(oldlimit);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -159,7 +159,5 @@ void ui_racct_foreach(void (*callback)(struct racct *racct,
|
||||
void *arg2, void *arg3), void *arg2, void *arg3);
|
||||
#endif
|
||||
|
||||
void lim_update_thread(struct thread *td);
|
||||
|
||||
#endif /* _KERNEL */
|
||||
#endif /* !_SYS_RESOURCEVAR_H_ */
|
||||
|
@ -105,7 +105,6 @@ void change_svuid(struct ucred *newcred, uid_t svuid);
|
||||
void crcopy(struct ucred *dest, struct ucred *src);
|
||||
struct ucred *crcopysafe(struct proc *p, struct ucred *cr);
|
||||
struct ucred *crdup(struct ucred *cr);
|
||||
void cred_update_thread(struct thread *td);
|
||||
void proc_set_cred_init(struct proc *p, struct ucred *cr);
|
||||
struct ucred *proc_set_cred(struct proc *p, struct ucred *cr);
|
||||
void crfree(struct ucred *cr);
|
||||
|
Loading…
x
Reference in New Issue
Block a user