FreeBSD/sys/kern/kern_rctl.c
/*
 * Appends a rule to the sbuf.
 */
Appends a rule to the sbuf.
Appends a rule to the sbuf .
static void
rctl_rule_to_sbuf(struct sbuf *sb, const struct rctl_rule *rule)
{
	int64_t amount;
	ASSERT_RACCT_ENABLED();
	sbuf_printf(sb, "%s:", rctl_subject_type_name(rule->rr_subject_type));
	switch (rule->rr_subject_type) {
	case RCTL_SUBJECT_TYPE_PROCESS:
		if (rule->rr_subject.rs_proc == NULL)
			sbuf_printf(sb, ":");
		else
			sbuf_printf(sb, "%d:",
			    rule->rr_subject.rs_proc->p_pid);
		break;
	case RCTL_SUBJECT_TYPE_USER:
		if (rule->rr_subject.rs_uip == NULL)
			sbuf_printf(sb, ":");
		else
			sbuf_printf(sb, "%d:",
			    rule->rr_subject.rs_uip->ui_uid);
		break;
	case RCTL_SUBJECT_TYPE_LOGINCLASS:
		if (rule->rr_subject.rs_loginclass == NULL)
			sbuf_printf(sb, ":");
		else
			sbuf_printf(sb, "%s:",
			    rule->rr_subject.rs_loginclass->lc_name);
		break;
	case RCTL_SUBJECT_TYPE_JAIL:
		if (rule->rr_subject.rs_prison_racct == NULL)
			sbuf_printf(sb, ":");
		else
			sbuf_printf(sb, "%s:",
			    rule->rr_subject.rs_prison_racct->prr_name);
		break;
	default:
		panic("rctl_rule_to_sbuf: unknown subject type %d",
		    rule->rr_subject_type);
	}
	amount = rule->rr_amount;
	if (amount != RCTL_AMOUNT_UNDEFINED &&
	    RACCT_IS_IN_MILLIONS(rule->rr_resource))
		amount /= 1000000;
	sbuf_printf(sb, "%s:%s=%jd",
	    rctl_resource_name(rule->rr_resource),
	    rctl_action_name(rule->rr_action),
	    amount);
	if (rule->rr_per != rule->rr_subject_type)
		sbuf_printf(sb, "/%s", rctl_subject_type_name(rule->rr_per));
}
static void rctl_rule_to_sbuf ( struct sbuf * sb , const struct rctl_rule * rule ) { int64_t amount ; ASSERT_RACCT_ENABLED ( ) ; sbuf_printf ( sb , " " , rctl_subject_type_name ( rule -> rr_subject_type ) ) ; switch ( rule -> rr_subject_type ) { case RCTL_SUBJECT_TYPE_PROCESS : if ( rule -> rr_subject . rs_proc == NULL ) sbuf_printf ( sb , " " ) ; else sbuf_printf ( sb , " " , rule -> rr_subject . rs_proc -> p_pid ) ; break ; case RCTL_SUBJECT_TYPE_USER : if ( rule -> rr_subject . rs_uip == NULL ) sbuf_printf ( sb , " " ) ; else sbuf_printf ( sb , " " , rule -> rr_subject . rs_uip -> ui_uid ) ; break ; case RCTL_SUBJECT_TYPE_LOGINCLASS : if ( rule -> rr_subject . rs_loginclass == NULL ) sbuf_printf ( sb , " " ) ; else sbuf_printf ( sb , " " , rule -> rr_subject . rs_loginclass -> lc_name ) ; break ; case RCTL_SUBJECT_TYPE_JAIL : if ( rule -> rr_subject . rs_prison_racct == NULL ) sbuf_printf ( sb , " " ) ; else sbuf_printf ( sb , " " , rule -> rr_subject . rs_prison_racct -> prr_name ) ; break ; default : panic ( " " , rule -> rr_subject_type ) ; } amount = rule -> rr_amount ; if ( amount != RCTL_AMOUNT_UNDEFINED && RACCT_IS_IN_MILLIONS ( rule -> rr_resource ) ) amount /= 1000000 ; sbuf_printf ( sb , " " , rctl_resource_name ( rule -> rr_resource ) , rctl_action_name ( rule -> rr_action ) , amount ) ; if ( rule -> rr_per != rule -> rr_subject_type ) sbuf_printf ( sb , " " , rctl_subject_type_name ( rule -> rr_per ) ) ; }
Appends a rule to the sbuf.
Appends a rule to the sbuf .