Subject: RE: Bash login breaks if too many environment variables are set
From: "Hommersom, Fred" <[email-masked]>
To: "Eric Blake" <[email-masked]>, "Reid Thompson" <[email-masked]>
Cc: <[email-masked]>
Date: Fri, 16 Sep 2005 11:08:38 +0200

Thanks for the replies so far. Unfortunately is the best option (set
variables in bash) not feasable.
The .bat file is a complex set of bat files with logic inside so that
would take a lot of effort to convert
But I have done some experiments with bash without --login option and
the advised export -p.

The number of variables itself does not seem to be the problem.
The length of the values is also important. So to get an idea what is
going on I have
incremented the number of variables up to the point where export -p
still gives the right output.
Now I add 1 character at a time to a value and tested export - p.
Only the built-in commands work now. All others end with "Resource
temporarily unavailable"

There comes a point where adding 1 more character ends up with:
    138 [main] bash 2556 handle_exceptions: Exception:
STATUS_ACCESS_VIOLATION
    887 [main] bash 2556 open_stackdumpfile: Dumping stack trace to
bash.exe.stackdump

The stackdump contains
Exception: STATUS_ACCESS_VIOLATION at eip=61014DEE
eax=00246000 ebx=10012910 ecx=00000003 edx=00245FFF esi=00000000
edi=6110A1C4
ebp=0022EEE8 esp=0022EE90 program=c:\cygwin\bin\bash.exe, pid 2556,
thread main
cs=001B ds=0023 es=0023 fs=003B gs=0000 ss=0023
Stack trace: Frame     Function  Args
0022EEE8  61014DEE  (00000000, 00000000, 0022EF18, 61087B02)
0022EF18  61068028  (00000000, 00000000, 7C90EE18, 7C919AF0)
0022EFD8  61004B16  (0022EFF0, 77D70467, 77D49A18, FFFFFFFF)
0022FF88  6100594F  (00000000, 00000000, 00000000, 00000000)
End of stack trace

Adding another character gives no errors but export -p shows now only:
declare -x HOME="/cygdrive/c/cygwin/home/fhommexx"
declare -x OLDPWD
declare -x PWD="/cygdrive/c/Data/locations/tc50_custy00"
declare -x SHLVL="1"
declare -x TERM="cygwin"
Adding still more characters reveals more variables.

The last export -p that gave correct results was piped to a file.
I tried to find if the limit was the 32k limit as suggested by Eric.
The rough size of the file is 45,098 bytes.
Stripping 'declare -x " cuts it down to 37,816 bytes
Stripping leading and trailing " cuts it down to 36,494 bytes
Modifying \\ into \ cuts it down to 33.065 bytes
The file contains 662 lines and if we also cut the linefeed (no idea how
the administration works)
There are only 32403 bytes left. And 32 k = 32.768. Pretty near but no
exact match.

Now I am stuck. Did I reach a limit of windoze, a limit in cygwin or a
supporting library or a bug?

-----Original Message-----
> Hommersom, Fred wrote:
> 
>>
>> The file bigsetup.bat contains a huge amount environment variables.
>> For a medium number (~ 600) everything works fine For a larger number

>> the output is:
>> bash: /usr/bin/id: Resource temporarily unavailable
...
> i would think that you should declare your env variables in either 
> your .bashrc or your .bash_profile rather than in a .bat file.  It may

> solve your problem.

> I haven't had a chance to look at this further, but it is on my list.
I tried looking in the Windows documentation to see if there is a limit
on environment size for CreateProcess that you might be exceeding - all
I can find is that  an individual variable can be no more than 32k, but
nothing about the overall environment size.  Does anyone else know what
limits windows imposes on the environment?  POSIX only specifies
ARG_MAX, which is the combination of command line and environment
together.
>
>You might also want to experiment with 'export -p' in a bash where you
are experiencing failures, to see if bash's list of environment
variables is shorter than what you thought should have been inherited
into bash.  Being a builtin, it won't have then invocation problems like
you are having with id, find, or sort.  I also agree with Reid's
suggestion - try sticking things into the environment AFTER bash is
started, not beforehand.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/