| 610 | } |
| 611 | |
| 612 | static void |
| 613 | lim_cb(void *arg) |
| 614 | { |
| 615 | struct rlimit rlim; |
| 616 | struct thread *td; |
| 617 | struct proc *p; |
| 618 | |
| 619 | p = arg; |
| 620 | PROC_LOCK_ASSERT(p, MA_OWNED); |
| 621 | /* |
| 622 | * Check if the process exceeds its cpu resource allocation. If |
| 623 | * it reaches the max, arrange to kill the process in ast(). |
| 624 | */ |
| 625 | if (p->p_cpulimit == RLIM_INFINITY) |
| 626 | return; |
| 627 | PROC_STATLOCK(p); |
| 628 | FOREACH_THREAD_IN_PROC(p, td) { |
| 629 | ruxagg(p, td); |
| 630 | } |
| 631 | PROC_STATUNLOCK(p); |
| 632 | if (p->p_rux.rux_runtime > p->p_cpulimit * cpu_tickrate()) { |
| 633 | lim_rlimit_proc(p, RLIMIT_CPU, &rlim); |
| 634 | if (p->p_rux.rux_runtime >= rlim.rlim_max * cpu_tickrate()) { |
| 635 | killproc(p, "exceeded maximum CPU limit"); |
| 636 | } else { |
| 637 | if (p->p_cpulimit < rlim.rlim_max) |
| 638 | p->p_cpulimit += 5; |
| 639 | kern_psignal(p, SIGXCPU); |
| 640 | } |
| 641 | } |
| 642 | if ((p->p_flag & P_WEXIT) == 0) |
| 643 | callout_reset_sbt(&p->p_limco, SBT_1S, 0, |
| 644 | lim_cb, p, C_PREL(1)); |
| 645 | } |
| 646 | |
| 647 | int |
| 648 | kern_setrlimit(struct thread *td, u_int which, struct rlimit *limp) |
nothing calls this directly
no test coverage detected