FreeBSD/sys/kern/kern_rctl.c
/*
 * Assign RCTL rules to the newly created process.
 */
Assign RCTL rules to the newly created process.
Assign RCTL rules to the newly created process .
int
rctl_proc_fork(struct proc *parent, struct proc *child)
{
	struct rctl_rule *rule;
	struct rctl_rule_link *link;
	int error;
	ASSERT_RACCT_ENABLED();
	RACCT_LOCK_ASSERT();
	KASSERT(parent->p_racct != NULL, ("process without racct; p = %p", parent));
	LIST_INIT(&child->p_racct->r_rule_links);
	LIST_FOREACH(link, &parent->p_racct->r_rule_links, rrl_next) {
		if (link->rrl_rule->rr_subject_type ==
		    RCTL_SUBJECT_TYPE_PROCESS) {
			rule = rctl_rule_duplicate(link->rrl_rule, M_NOWAIT);
			if (rule == NULL)
				goto fail;
			KASSERT(rule->rr_subject.rs_proc == parent,
			    ("rule->rr_subject.rs_proc != parent"));
			rule->rr_subject.rs_proc = child;
			error = rctl_racct_add_rule_locked(child->p_racct,
			    rule);
			rctl_rule_release(rule);
			if (error != 0)
				goto fail;
		} else {
			error = rctl_racct_add_rule_locked(child->p_racct,
			    link->rrl_rule);
			if (error != 0)
				goto fail;
		}
	}
	return (0);
fail:
	while (!LIST_EMPTY(&child->p_racct->r_rule_links)) {
		link = LIST_FIRST(&child->p_racct->r_rule_links);
		LIST_REMOVE(link, rrl_next);
		rctl_rule_release(link->rrl_rule);
		uma_zfree(rctl_rule_link_zone, link);
	}
	return (EAGAIN);
}
int rctl_proc_fork ( struct proc * parent , struct proc * child ) { struct rctl_rule * rule ; struct rctl_rule_link * link ; int error ; ASSERT_RACCT_ENABLED ( ) ; RACCT_LOCK_ASSERT ( ) ; KASSERT ( parent -> p_racct != NULL , ( " " , parent ) ) ; LIST_INIT ( & child -> p_racct -> r_rule_links ) ; LIST_FOREACH ( link , & parent -> p_racct -> r_rule_links , rrl_next ) { if ( link -> rrl_rule -> rr_subject_type == RCTL_SUBJECT_TYPE_PROCESS ) { rule = rctl_rule_duplicate ( link -> rrl_rule , M_NOWAIT ) ; if ( rule == NULL ) goto fail ; KASSERT ( rule -> rr_subject . rs_proc == parent , ( " " ) ) ; rule -> rr_subject . rs_proc = child ; error = rctl_racct_add_rule_locked ( child -> p_racct , rule ) ; rctl_rule_release ( rule ) ; if ( error != 0 ) goto fail ; } else { error = rctl_racct_add_rule_locked ( child -> p_racct , link -> rrl_rule ) ; if ( error != 0 ) goto fail ; } } return ( 0 ) ; fail : while ( ! LIST_EMPTY ( & child -> p_racct -> r_rule_links ) ) { link = LIST_FIRST ( & child -> p_racct -> r_rule_links ) ; LIST_REMOVE ( link , rrl_next ) ; rctl_rule_release ( link -> rrl_rule ) ; uma_zfree ( rctl_rule_link_zone , link ) ; } return ( EAGAIN ) ; }
Assign RCTL rules to the newly created process.
Assign RCTL rules to the newly created process .
/*
	 * Go through limits applicable to the parent and assign them
	 * to the child.  Rules with 'process' subject have to be duplicated
	 * in order to make their rr_subject point to the new process.
	 */