[Lazarus] SetEnv on Linux 64bit

michael.vancanneyt at wisa.be michael.vancanneyt at wisa.be
Wed Apr 4 11:53:55 CEST 2012



On Wed, 4 Apr 2012, Honza wrote:

> 2012/4/3 Michael Van Canneyt <michael at freepascal.org>:
>>
>>
>> On Tue, 3 Apr 2012, waldo kitty wrote:
>>
>>> On 4/3/2012 09:57, michael.vancanneyt at wisa.be wrote:
>>>>
>>>> On Tue, 3 Apr 2012, fred f wrote:
>>>>>
>>>>> I need to set up LIBOVERLAY_SCROLLBAR=0 on Ubuntu 64bit, but there LIBC
>>>>> is not
>>>>> supported and therefore I am looking for SetEnv which I can use on 64bit
>>>>> Linux.
>>>>>
>>>>> SysUtils contains only GetEnvironmentVariable, but not Set...
>>>>
>>>>
>>>> That's not how it works on Unix/Linux.
>>>>
>>>> You must always set up environment variables before a program starts.
>>>> When starting a process, the environment for that process is started and
>>>> is
>>>> then immutable for the duration of the process.
>>>
>>>
>>> ewww... so no "fancy" capabilities like we could do in the old DOS days
>>> where we could change the base environment as well as cloning it with
>>> changes for child processes??? if so, that's blows several of my porting
>>> projects up :? :(
>>
>>
>> Not possible on Posix platforms.
>
> Now I'm confused. AFAICS
> (http://pubs.opengroup.org/onlinepubs/007904975/functions/setenv.html)
> Posix setenv() allows a process to mutate its environment variables.
>
> I probably misunderstood something, can someone enlighten me please?

You can always modify them (it's just data in memory), but modifying them 
will only change your private view of the variables. 
The changes you make will not propagate to libraries or newly started processes.

Therefor it makes no sense to change them, and the FPC runtime does not allow
it. If we did allow it, people would expect DOS/Windows like behaviour, which
we simply cannot provide.

If you read the second part of the provided URL, you'll see that the POSIX
group recognises that the behaviour of setenv() is problematical.

The URL points - for restrictions - to the exec function

http://pubs.opengroup.org/onlinepubs/007904975/functions/exec.html

Where it says:

"For those forms not containing an envp pointer ( execl(), execv(), execlp(),
and execvp()), the environment for the new process image shall be taken from
the external variable environ in the calling process."

Etc etc etc.

Michael.




More information about the Lazarus mailing list