* Assign RCTL rules to the newly created process. */
| 2107 | * Assign RCTL rules to the newly created process. |
| 2108 | */ |
| 2109 | int |
| 2110 | rctl_proc_fork(struct proc *parent, struct proc *child) |
| 2111 | { |
| 2112 | struct rctl_rule *rule; |
| 2113 | struct rctl_rule_link *link; |
| 2114 | int error; |
| 2115 | |
| 2116 | ASSERT_RACCT_ENABLED(); |
| 2117 | RACCT_LOCK_ASSERT(); |
| 2118 | KASSERT(parent->p_racct != NULL, ("process without racct; p = %p", parent)); |
| 2119 | |
| 2120 | LIST_INIT(&child->p_racct->r_rule_links); |
| 2121 | |
| 2122 | /* |
| 2123 | * Go through limits applicable to the parent and assign them |
| 2124 | * to the child. Rules with 'process' subject have to be duplicated |
| 2125 | * in order to make their rr_subject point to the new process. |
| 2126 | */ |
| 2127 | LIST_FOREACH(link, &parent->p_racct->r_rule_links, rrl_next) { |
| 2128 | if (link->rrl_rule->rr_subject_type == |
| 2129 | RCTL_SUBJECT_TYPE_PROCESS) { |
| 2130 | rule = rctl_rule_duplicate(link->rrl_rule, M_NOWAIT); |
| 2131 | if (rule == NULL) |
| 2132 | goto fail; |
| 2133 | KASSERT(rule->rr_subject.rs_proc == parent, |
| 2134 | ("rule->rr_subject.rs_proc != parent")); |
| 2135 | rule->rr_subject.rs_proc = child; |
| 2136 | error = rctl_racct_add_rule_locked(child->p_racct, |
| 2137 | rule); |
| 2138 | rctl_rule_release(rule); |
| 2139 | if (error != 0) |
| 2140 | goto fail; |
| 2141 | } else { |
| 2142 | error = rctl_racct_add_rule_locked(child->p_racct, |
| 2143 | link->rrl_rule); |
| 2144 | if (error != 0) |
| 2145 | goto fail; |
| 2146 | } |
| 2147 | } |
| 2148 | |
| 2149 | return (0); |
| 2150 | |
| 2151 | fail: |
| 2152 | while (!LIST_EMPTY(&child->p_racct->r_rule_links)) { |
| 2153 | link = LIST_FIRST(&child->p_racct->r_rule_links); |
| 2154 | LIST_REMOVE(link, rrl_next); |
| 2155 | rctl_rule_release(link->rrl_rule); |
| 2156 | uma_zfree(rctl_rule_link_zone, link); |
| 2157 | } |
| 2158 | |
| 2159 | return (EAGAIN); |
| 2160 | } |
| 2161 | |
| 2162 | /* |
| 2163 | * Release rules attached to the racct. |
no test coverage detected