FreeBSD/sys/kern/kern_prot.c
/*
 * Change process credentials.
 * Callers are responsible for providing the reference for passed credentials
 * and for freeing old ones.
 *
 * Process has to be locked except when it does not have credentials (as it
 * should not be visible just yet) or when newcred is NULL (as this can be
 * only used when the process is about to be freed, at which point it should
 * not be visible anymore).
 */
Change process credentials.
Callers are responsible for providing the reference for passed credentials
and for freeing old ones.

Process has to be locked except when it does not have credentials (as it
should not be visible just yet) or when newcred is NULL (as this can be
only used when the process is about to be freed, at which point it should
not be visible anymore).
Change process credentials . Callers are responsible for providing the reference for passed credentials and for freeing old ones . Process has to be locked except when it does not have credentials ( as it should not be visible just yet ) or when newcred is NULL ( as this can be only used when the process is about to be freed at which point it should not be visible anymore ) .
struct ucred *
proc_set_cred(struct proc *p, struct ucred *newcred)
{
	struct ucred *oldcred;
	MPASS(p->p_ucred != NULL);
	if (newcred == NULL)
		MPASS(p->p_state == PRS_ZOMBIE);
	else
		PROC_LOCK_ASSERT(p, MA_OWNED);
	oldcred = p->p_ucred;
	p->p_ucred = newcred;
	if (newcred != NULL)
		PROC_UPDATE_COW(p);
	return (oldcred);
}
struct ucred * proc_set_cred ( struct proc * p , struct ucred * newcred ) { struct ucred * oldcred ; MPASS ( p -> p_ucred != NULL ) ; if ( newcred == NULL ) MPASS ( p -> p_state == PRS_ZOMBIE ) ; else PROC_LOCK_ASSERT ( p , MA_OWNED ) ; oldcred = p -> p_ucred ; p -> p_ucred = newcred ; if ( newcred != NULL ) PROC_UPDATE_COW ( p ) ; return ( oldcred ) ; }
Change process credentials.
Change process credentials .