Squid 1.2b24 incorrectly detects FDs in Linux 2.1.x

From: Jordan Mendelson <jordy@dont-contact.us>
Date: Tue, 25 Aug 1998 11:19:01 -0400

Hello all,

Newer copies of Linux 2.1.11x contain by default 1024 file descriptors
active on a machine, however Squid detects only 256. Doing a open() loop
until you run out will properly detect this.

Unfortunatly, this is because <linux/limits.h> defines OPEN_MAX as 256
(which defines NOFILE as OPEN_MAX), but NR_OPEN as 1024.

What is odd is that the following code snipit (which looks like it should be
used instead of NOFILE or OPEN_MAX) gives 1024:

#include <sys/time.h>
#include <sys/resource.h>
#include <unistd.h>

main() {
    struct rlimit rl;
    if (getrlimit(RLIMIT_NOFILE, &rl) < 0) {
        perror("getrlimit: RLIMIT_NOFILE");
    } else {
        rl.rlim_cur = rl.rlim_max; /* set it to the max */
        if (setrlimit(RLIMIT_NOFILE, &rl) < 0) {
            perror("setrlimit: RLIMIT_NOFILE");
        } else
            printf("%d", rl.rlim_cur);
    }
}

But in configure, it doesn't seem to use rl.rlim_max if it succeeded (in
fact, it doesn't do anything with the above code snipit as far as I can
tell)

I've attached a diff for configure.in to this message, of course... autoconf
will need to be run to rebuild the main configure before it works :)

It basically uses setrlimit, but double-checks the value against an open()
loop (as well as any other methods such as NOFILE or getdtablesize()) and
chooses which ever returns the largest number.

Jordan

--
Jordan Mendelson     : http://jordy.wserv.com
Web Services, Inc.   : http://www.wserv.com
begin 666 diff.file
M*BHJ(&-O;F9I9W5R92YI;BY/3$0)5&AU($%U9R R," R,SHU,SHU-B Q.3DX
M"BTM+2!C;VYF:6=U<F4N:6X)5'5E($%U9R R-2 Q,3HQ-CHQ-2 Q.3DX"BHJ
M*BHJ*BHJ*BHJ*BHJ*@HJ*BH@.#@V+#@Y.2 J*BHJ"B @(VEN8VQU9&4@/'-Y
M<R]P87)A;2YH/@H@("-I;F-L=61E(#QS>7,O<F5S;W5R8V4N:#X*("!M86EN
M*"D@>PHA( EI;G0@:2QJ.PH@("-I9B!?7T-91U=)3C,R7U\*(" @(" @+RH@
M9V5T<FQI;6ET(&%N9"!S>7-C;VYF(')E='5R;G,@8F]G;W5S('9A;'5E<R!O
M;B!C>6=W:6XS,BX*(" @(" @("H@3G5M8F5R(&]F(&9D<R!I<R!V:7)T=6%L
M;'D@=6YL:6UI=&5D(&EN(&-Y9W=I;B H<WES+W!A<F%M+F@I"B @(" @(" J
M+PH@(" @("!I(#T@3D]&24Q%.PH@("-E;'-E"B$@(VEF($A!5D5?4T544DQ)
M34E4"B @(" @('-T<G5C="!R;&EM:70@<FP["B @(VEF(&1E9FEN960H4DQ)
M34E47TY/1DE,12D*(" @(" @:68@*&=E=')L:6UI="A23$E-251?3D]&24Q%
M+" F<FPI(#P@,"D@>PHM+2T@.#@V+#@Y.2 M+2TM"B @(VEN8VQU9&4@/'-Y
M<R]P87)A;2YH/@H@("-I;F-L=61E(#QS>7,O<F5S;W5R8V4N:#X*("!M86EN
M*"D@>PHA( EI;G0@:3TP+&HL:SL*(" C:68@7U]#64=724XS,E]?"B @(" @
M("\J(&=E=')L:6UI="!A;F0@<WES8V]N9B!R971U<FYS(&)O9V]U<R!V86QU
M97,@;VX@8WEG=VEN,S(N"B @(" @(" J($YU;6)E<B!O9B!F9',@:7,@=FER
M='5A;&QY('5N;&EM:71E9"!I;B!C>6=W:6X@*'-Y<R]P87)A;2YH*0H@(" @
M(" @*B\*(" @(" @:2 ]($Y/1DE,13L*(" C96QS90HA("-I9B!(059%7U-%
M5%),24U)5" F)B H9&5F:6YE9"A23$E-251?3D]&24Q%*2!\?"!D969I;F5D
M*%),24U)5%]/1DE,12DI"B @(" @('-T<G5C="!R;&EM:70@<FP["B @(VEF
M(&1E9FEN960H4DQ)34E47TY/1DE,12D*(" @(" @:68@*&=E=')L:6UI="A2
M3$E-251?3D]&24Q%+" F<FPI(#P@,"D@>PHJ*BHJ*BHJ*BHJ*BHJ*BH**BHJ
M(#DP,BPY,#@@*BHJ*@H@(" @(" @(" @<FPN<FQI;5]C=7(@/2!R;"YR;&EM
M7VUA>#L@(" @(" O*B!S970@:70@=&\@=&AE(&UA>" J+PH@(" @(" @(" @
M:68@*'-E=')L:6UI="A23$E-251?3D]&24Q%+" F<FPI(#P@,"D@>PH@(" @
M(" @(" @(" @('!E<G)O<B@B<V5T<FQI;6ET.B!23$E-251?3D]&24Q%(BD[
M"B$@(" @(" @("!]"B @(" @('T*(" C96QI9B!D969I;F5D*%),24U)5%]/
M1DE,12D*(" @(" @:68@*&=E=')L:6UI="A23$E-251?3T9)3$4L("9R;"D@
M/" P*2!["BTM+2 Y,#(L.3 Y("TM+2T*(" @(" @(" @(')L+G)L:6U?8W5R
M(#T@<FPN<FQI;5]M87@[(" @(" @+RH@<V5T(&ET('1O('1H92!M87@@*B\*
M(" @(" @(" @(&EF("AS971R;&EM:70H4DQ)34E47TY/1DE,12P@)G)L*2 \
M(# I('L*(" @(" @(" @(" @("!P97)R;W(H(G-E=')L:6UI=#H@4DQ)34E4
M7TY/1DE,12(I.PHA(" @(" @(" @?2!E;'-E"B$@(" @(" @(" @(" @:2 ]
M(')L+G)L:6U?8W5R.PH@(" @("!]"B @(V5L:68@9&5F:6YE9"A23$E-251?
M3T9)3$4I"B @(" @(&EF("AG971R;&EM:70H4DQ)34E47T]&24Q%+" F<FPI
M(#P@,"D@>PHJ*BHJ*BHJ*BHJ*BHJ*BH**BHJ(#DQ,2PY,C$@*BHJ*@H@(" @
M(" @(" @<FPN<FQI;5]C=7(@/2!R;"YR;&EM7VUA>#L@(" @(" O*B!S970@
M:70@=&\@=&AE(&UA>" J+PH@(" @(" @(" @:68@*'-E=')L:6UI="A23$E-
M251?3T9)3$4L("9R;"D@/" P*2!["B @(" @(" @(" @(" @<&5R<F]R*")S
M971R;&EM:70Z(%),24U)5%]/1DE,12(I.PHA(" @(" @(" @?0H@(" @("!]
M"B @(V5N9&EF("\J(%),24U)5%].3T9)3$4@*B\*(2 C96YD:68@+RH@2$%6
M15]315123$E-250@*B\*(2 C:68@2$%615]365-#3TY&("8F(&1E9FEN960H
M7U-#7T]014Y?34%8*0H@(" @(" @(" @:2 ]('-Y<V-O;F8H7U-#7T]014Y?
M34%8*3L*(" C96QI9B!(059%7T=%5$1404),15-)6D4@)B8@(61E9FEN960H
M7U]L:6YU>%]?*0H@(" @(" @(" @:2 ](&=E=&1T86)L97-I>F4H*3L*+2TM
M(#DQ,BPY,C(@+2TM+0H@(" @(" @(" @<FPN<FQI;5]C=7(@/2!R;"YR;&EM
M7VUA>#L@(" @(" O*B!S970@:70@=&\@=&AE(&UA>" J+PH@(" @(" @(" @
M:68@*'-E=')L:6UI="A23$E-251?3T9)3$4L("9R;"D@/" P*2!["B @(" @
M(" @(" @(" @<&5R<F]R*")S971R;&EM:70Z(%),24U)5%]/1DE,12(I.PHA
M(" @(" @(" @?2!E;'-E"B$@(" @(" @(" @(" @:2 ](')L+G)L:6U?8W5R
M.PH@(" @("!]"B @(V5N9&EF("\J(%),24U)5%].3T9)3$4@*B\*(2 C96QI
M9B!(059%7U-94T-/3D8@)B8@9&5F:6YE9"A?4T-?3U!%3E]-05@I"B @(" @
M(" @("!I(#T@<WES8V]N9BA?4T-?3U!%3E]-05@I.PH@("-E;&EF($A!5D5?
M1T541%1!0DQ%4TE:12 F)B A9&5F:6YE9"A?7VQI;G5X7U\I"B @(" @(" @
M("!I(#T@9V5T9'1A8FQE<VEZ92@I.PHJ*BHJ*BHJ*BHJ*BHJ*BH**BHJ(#DR
M-2PY,S4@*BHJ*@H@(" @(" @(" @:2 ]($Y/1DE,13L*(" C96QI9B!D969I
M;F5D*%].1DE,12D*(" @(" @(" @(&D@/2!?3D9)3$4["BT@(V5L<V4*+2 )
M=VAI;&4H*&H];W!E;B@B+V1E=B]N=6QL(BP@,"DI(#X@,"D@:3UJ.PHM(" @
M(" @(" @8VQO<V4H:2D[(&-L;W-E*&DM,2D["BT@"6DK*SL*(" C96YD:68*
M(" C96YD:68@+RH@7U]#64=724XS,E]?("HO"B @"69P<FEN=&8@*&9O<&5N
M*")C;VYF=&5S='9A;"(L(")W(BDL("(E9%QN(BP@:2D["B @"65X:70H,"D[
M"BTM+2 Y,C8L.30P("TM+2T*(" @(" @(" @(&D@/2!.3T9)3$4["B @(V5L
M:68@9&5F:6YE9"A?3D9)3$4I"B @(" @(" @("!I(#T@7TY&24Q%.PH@("-E
M;F1I9@HK( DO*B!T=7)N(&EN=&\@82!C:&5C:W!O:6YT("HO"BL@"7=H:6QE
M*"AJ/6]P96XH(B]D978O;G5L;"(L(# I*2 ^(# I(&L]:CL@"BL@(" @(" @
M("!C;&]S92AK*3L@8VQO<V4H:RTQ*3L**R @(" @(" @(&LK*SL**R **R )
M+RH@;&%R9V5S="!W:6YS("HO"BL@(" @(" @("!I(#T@:R ^(&D@/R!K(#H@
M:3L**R *(" C96YD:68@+RH@7U]#64=724XS,E]?("HO"B @"69P<FEN=&8@
M*&9O<&5N*")C;VYF=&5S='9A;"(L(")W(BDL("(E9%QN(BP@:2D["B @"65X
':70H,"D["@``
`
end
Received on Tue Aug 25 1998 - 08:22:01 MDT

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:41:43 MST