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

Bug#419706: setrlimit(RLIMIT_CPUINFO) with zero value doesn't inherit properly across children



Package: kernel

This is in 2.6.20-3 and (Ubuntu) 2.6.20-15.

Full details may be found on the zsh-workers thread, here:
http://www.zsh.org/mla/workers/2007/msg00200.html

A bug for Ubuntu on launchpad is at
https://bugs.launchpad.net/ubuntu/+source/linux-source-2.6.20/+bug/107209

The following behavior was observed:

$ bash -c 'ulimit -t 0; ulimit -Ht; while :; do :; done'
0
Killed
$ bash -c 'ulimit -t 0; ulimit -Ht; (while :; do :; done)'
0
<loops forever>
$ bash -c 'ulimit -St 0; while :; do :; done'
CPU time limit exceeded (core dumped)
$ bash -c 'ulimit -St 0; (while :; do :; done)'
<loops forever>

David Peer suggested:

> but here is one rapid fix that solves the problem.
> 
> (you will not see the new limit of 1 sec but you'll still see it set to 0, but its 1 sec - believe me && try,
> 
> if you want to see it, fork another any shell and you'll see it....bug or feature?!)
> 
> Before the line: *old_rlim = new_rlim;
> 
> add:
> 
> if (resource == RLIMIT_CPU && new_rlim.rlim_cur == 0) {
>            /*
>             * The caller is asking for an immediate RLIMIT_CPU
>             * expiry. But we use the zero value to mean "it was
>             * never set". So let's cheat and make it one second
>             * instead
>             */
>            new_rlim.rlim_cur = 1;
>        }
> 
> You can remove the dumb if statement that does nothing cause the assignment occurs(*old_rlim = new_rlim) before
> 
> so it has no meaning! : if (rlim_cur == 0) {....}
> 
> David



Reply to: