Bug 2317 - ulimit in 1.17.1 doesn't set more than 1024
Summary: ulimit in 1.17.1 doesn't set more than 1024
Status: RESOLVED FIXED
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: 1.17.x
Hardware: PC Linux
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-03 10:20 UTC by Denys Fedoryshchenko
Modified: 2010-08-11 21:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Denys Fedoryshchenko 2010-08-03 10:20:02 UTC
home ~ # ssh root@10.0.1.34
GlobalOS 2.1 http://www.globalos.info/
Proxy-16 ~ # ulimit -n 262144
ash: error setting limit: Invalid argument
Proxy-16 ~ # ulimit -n 2048
ash: error setting limit: Invalid argument
Proxy-16 ~ # ulimit -n 1025
ash: error setting limit: Invalid argument
Proxy-16 ~ # ulimit -n 1024
Proxy-16 ~ #
Comment 1 Denys Fedoryshchenko 2010-08-03 10:30:29 UTC
And even more bad:

bash2 is full blown bash

Proxy-16 ~ # bash2
Proxy-16 ~ # ulimit -n 262144
Proxy-16 ~ # ulimit -n
262144
Proxy-16 ~ # exit
Proxy-16 ~ # ulimit -n
1024
Proxy-16 ~ # bash2
Proxy-16 ~ # ulimit -n
1024

So just by viewing ulimit it will be reversed back
Comment 2 Denys Fedoryshchenko 2010-08-03 13:14:06 UTC
Hold on, seems i am unable to reproduce this bug on full-blown system, i will make sure it is not GCC or kernel bug.
Comment 3 Denys Fedoryshchenko 2010-08-03 16:07:40 UTC
Tested, seems it is issue in busybox.

busybox 1.16.2 works fine, 1.17.0 fails.
I try to use gcc 3.3.6, it is still failing, i try even to change glibc from 2.10.1 to 2.11.2 - it is still not changing ulimit.

I can reproduce it also in normal linux system:

/WORK/globalosii/devel/BUSYBOX/busybox-1.17.1 # ulimit -n 10240
ash: error setting limit: Invalid argument

Interesting, if i launch busybox over valgrind it shows

/WORK/globalosii/devel/BUSYBOX/busybox-1.17.1 # ulimit -n
1014
Comment 4 Denys Fedoryshchenko 2010-08-03 16:43:19 UTC
Seems i found reason

If i add

                                        if (opts & OPT_hard)
                                                limit.rlim_max = val;
                                        if ((opts & OPT_soft) || opts == 0)
                                                limit.rlim_cur = val;
+                                        if (limit.rlim_max < limit.rlim_cur)
+                                            limit.rlim_max = limit.rlim_cur;
//bb_error_msg("setrlimit(%d, %lld, %lld)", l->cmd, (long long)limit.rlim_cur, (long long)limit.rlim_max);
                                        printf("Setrlimit call\n");
                                        if (setrlimit(l->cmd, &limit) < 0) {
                                                bb_perror_msg("error setting limit");

Problem will disappear.
This is how bash do ulimit -n 1025 by strace

getrlimit(RLIMIT_NOFILE, {rlim_cur=1024, rlim_max=1024}) = 0
setrlimit(RLIMIT_NOFILE, {rlim_cur=1025, rlim_max=1025}) = 0

This is how unpatched busybox
getrlimit(RLIMIT_NOFILE, {rlim_cur=1024, rlim_max=1024}) = 0
setrlimit(RLIMIT_NOFILE, {rlim_cur=1025, rlim_max=1024}) = -1 EINVAL (Invalid argument)
Comment 5 Denys Vlasenko 2010-08-05 01:44:23 UTC
(1) try http://busybox.net/downloads/fixes-1.17.1/busybox-1.17.1-shell.patch

(2) if patched busybox fails too, strace failing ulimit invocation and similar bash invocation:

strace -oLOG.ash -s99 /path/to/busybox ash -c 'ulimit -n NUM'
strace -oLOG.bash -s99 bash -c 'ulimit -n NUM'

and attach LOG* files to this bug.
Comment 6 Denys Vlasenko 2010-08-11 21:49:08 UTC
Closing, since hotfix at http://busybox.net/downloads/fixes-1.17.1/busybox-1.17.1-shell.patch ought to be the fix for this.