[stupid question] setting env variables globally

Erik Trulsson ertr1013 at student.uu.se
Fri Oct 19 14:15:02 PDT 2007

On Fri, Oct 19, 2007 at 04:14:12PM +0000, Aryeh M. Friedman wrote:
> Is there any way to set the default value of a enviromental variable
> globally.   Specifically I want JAVA_VERSION to default to "1.6" unless
> the user sets it other wise.   By global I mean no matter how something
> is invoked (command line, script, GUI, IPC trigger, etc.) if it checks
> the value of the var it gets the same value (and I want to do this
> system wide)

You can take a look at login.conf(5) which probably can provide what you
want.  Depending on exactly how and when (and from where) a process is
started this might not work, but is probably the best that can be done
without hacking the kernel source code.

A process normally inherits the environment from its parent process.
When a process calls some of the exec(3) functions to start a new program it
can also provide a completely new environment which can be completely
independent of the parent's.

The settings in login.conf(5) only (AFAICT) affects processes whose ancestry
can be traced back to a login(1) instance, and where the environment hasn't
been changed along the way.  This should cover most of the processes you are
interested in but perhaps not quite all of them.

If you really want *all* processes to have a certain environment variable
set to a given value you will have to modify the execve(2) system call.
I don't recommend doing this unless you know *exactly* what you are doing
and the possible consequences thereof.  

<Insert your favourite quote here.>
Erik Trulsson
ertr1013 at student.uu.se

More information about the freebsd-questions mailing list