aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorMichael Kerrisk <michael.kerrisk@gmx.net>2004-08-01 20:31:12 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2004-08-01 20:31:12 -0700
commit81fd00e2e58911325c794b6f98d683ecb7db2b04 (patch)
tree10dc7924c324e3aade4e92c373161cca0cdaf020 /kernel
parentb0b6a9b776df159db5759b669a4bd6c73f91a5a4 (diff)
downloadhistory-81fd00e2e58911325c794b6f98d683ecb7db2b04.tar.gz
[PATCH] Off-by-one error for SIGXCPU / RLIMIT_CPU checking
There is a lonstanding off-by-one error that results from an incorrect comparison when checking whether a process has consumed CPU time in excess of its RLIMIT_CPU limits. This means, for example, that if we use setrlimit() to set the soft CPU limit (rlim_cur) to 5 seconds and the hard limit (rlim_max) to 10 seconds, then the process only receives a SIGXCPU signal after consuming 6 seconds of CPU time, and, if it continues consuming CPU after handling that signal, only receives SIGKILL after consuming 11 seconds of CPU time. The fix is trivial. Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/timer.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/kernel/timer.c b/kernel/timer.c
index 56b315bc53cf1b..4850abbeacdce6 100644
--- a/kernel/timer.c
+++ b/kernel/timer.c
@@ -792,12 +792,12 @@ static inline void do_process_times(struct task_struct *p,
psecs = (p->utime += user);
psecs += (p->stime += system);
- if (psecs / HZ > p->rlim[RLIMIT_CPU].rlim_cur) {
+ if (psecs / HZ >= p->rlim[RLIMIT_CPU].rlim_cur) {
/* Send SIGXCPU every second.. */
if (!(psecs % HZ))
send_sig(SIGXCPU, p, 1);
/* and SIGKILL when we go over max.. */
- if (psecs / HZ > p->rlim[RLIMIT_CPU].rlim_max)
+ if (psecs / HZ >= p->rlim[RLIMIT_CPU].rlim_max)
send_sig(SIGKILL, p, 1);
}
}