When killing a process due to RLIMIT_CPU, also log a message

with LOG_NOTICE, and print a message to the user with uprintf.

From PR 45421 by Greg Woods, but I changed the log priority (the user
might think it's an error, but the kernel is just doing its job) and the
wording of the message, and I edited a nearby comment.
This commit is contained in:
apb 2011-10-05 13:22:13 +00:00
parent 790e94dff8
commit 93dc43bb50
1 changed files with 12 additions and 5 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_synch.c,v 1.292 2011/10/05 13:05:49 apb Exp $ */
/* $NetBSD: kern_synch.c,v 1.293 2011/10/05 13:22:13 apb Exp $ */
/*-
* Copyright (c) 1999, 2000, 2004, 2006, 2007, 2008, 2009
@ -69,7 +69,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_synch.c,v 1.292 2011/10/05 13:05:49 apb Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_synch.c,v 1.293 2011/10/05 13:22:13 apb Exp $");
#include "opt_kstack.h"
#include "opt_perfctrs.h"
@ -1245,14 +1245,21 @@ sched_pstats(void)
/*
* Check if the process exceeds its CPU resource allocation.
* If over max, kill it.
* If over the hard limit, kill it with SIGKILL.
* If over the soft limit, send SIGXCPU and raise
* the soft limit a little.
*/
rlim = &p->p_rlimit[RLIMIT_CPU];
sig = 0;
if (__predict_false(runtm >= rlim->rlim_cur)) {
if (runtm >= rlim->rlim_max)
if (runtm >= rlim->rlim_max) {
sig = SIGKILL;
else {
log(LOG_NOTICE, "pid %d is killed: %s\n",
p->p_pid, "exceeded RLIMIT_CPU");
uprintf("pid %d, command %s, is killed: %s\n",
p->p_pid, p->p_comm,
"exceeded RLIMIT_CPU");
} else {
sig = SIGXCPU;
if (rlim->rlim_cur < rlim->rlim_max)
rlim->rlim_cur += 5;