MCPcopy Create free account
hub / github.com/F-Stack/f-stack / sys_rctl_get_rules

Function sys_rctl_get_rules

freebsd/kern/kern_rctl.c:1708–1792  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1706}
1707
1708int
1709sys_rctl_get_rules(struct thread *td, struct rctl_get_rules_args *uap)
1710{
1711 struct sbuf *sb;
1712 struct rctl_rule *filter;
1713 struct rctl_rule_link *link;
1714 struct proc *p;
1715 char *inputstr, *buf;
1716 size_t bufsize;
1717 int error;
1718
1719 if (!racct_enable)
1720 return (ENOSYS);
1721
1722 error = priv_check(td, PRIV_RCTL_GET_RULES);
1723 if (error != 0)
1724 return (error);
1725
1726 error = rctl_read_inbuf(&inputstr, uap->inbufp, uap->inbuflen);
1727 if (error != 0)
1728 return (error);
1729
1730 sx_slock(&allproc_lock);
1731 error = rctl_string_to_rule(inputstr, &filter);
1732 free(inputstr, M_RCTL);
1733 if (error != 0) {
1734 sx_sunlock(&allproc_lock);
1735 return (error);
1736 }
1737
1738 bufsize = uap->outbuflen;
1739 if (bufsize > rctl_maxbufsize) {
1740 sx_sunlock(&allproc_lock);
1741 return (E2BIG);
1742 }
1743
1744 buf = malloc(bufsize, M_RCTL, M_WAITOK);
1745 sb = sbuf_new(NULL, buf, bufsize, SBUF_FIXEDLEN);
1746 KASSERT(sb != NULL, ("sbuf_new failed"));
1747
1748 FOREACH_PROC_IN_SYSTEM(p) {
1749 RACCT_LOCK();
1750 LIST_FOREACH(link, &p->p_racct->r_rule_links, rrl_next) {
1751 /*
1752 * Non-process rules will be added to the buffer later.
1753 * Adding them here would result in duplicated output.
1754 */
1755 if (link->rrl_rule->rr_subject_type !=
1756 RCTL_SUBJECT_TYPE_PROCESS)
1757 continue;
1758 if (!rctl_rule_matches(link->rrl_rule, filter))
1759 continue;
1760 rctl_rule_to_sbuf(sb, link->rrl_rule);
1761 sbuf_printf(sb, ",");
1762 }
1763 RACCT_UNLOCK();
1764 }
1765

Callers

nothing calls this directly

Calls 15

rctl_read_inbufFunction · 0.85
rctl_string_to_ruleFunction · 0.85
mallocFunction · 0.85
sbuf_newFunction · 0.85
rctl_rule_matchesFunction · 0.85
rctl_rule_to_sbufFunction · 0.85
sbuf_printfFunction · 0.85
loginclass_racct_foreachFunction · 0.85
ui_racct_foreachFunction · 0.85
prison_racct_foreachFunction · 0.85
sbuf_errorFunction · 0.85
sbuf_lenFunction · 0.85

Tested by

no test coverage detected