From 93dc43bb50150ac8a1d5973a1c71aec7cb078f11 Mon Sep 17 00:00:00 2001 From: apb Date: Wed, 5 Oct 2011 13:22:13 +0000 Subject: [PATCH] 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. --- sys/kern/kern_synch.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c index ad816069378f..fe1063cd7a0c 100644 --- a/sys/kern/kern_synch.c +++ b/sys/kern/kern_synch.c @@ -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 -__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;