Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern When killing a process due to RLIMIT_CPU, also log ...



details:   https://anonhg.NetBSD.org/src/rev/93b3cd2baada
branches:  trunk
changeset: 770141:93b3cd2baada
user:      apb <apb%NetBSD.org@localhost>
date:      Wed Oct 05 13:22:13 2011 +0000

description:
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.

diffstat:

 sys/kern/kern_synch.c |  17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)

diffs (43 lines):

diff -r 508a77b04600 -r 93b3cd2baada sys/kern/kern_synch.c
--- a/sys/kern/kern_synch.c     Wed Oct 05 13:15:30 2011 +0000
+++ b/sys/kern/kern_synch.c     Wed Oct 05 13:22:13 2011 +0000
@@ -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 @@
 
                /*
                 * 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;



Home | Main Index | Thread Index | Old Index