Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 19 Oct 2007 23:14:34 +0200
From:      Erik Trulsson <ertr1013@student.uu.se>
To:        "Aryeh M. Friedman" <aryeh.friedman@gmail.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: [stupid question] setting env variables globally
Message-ID:  <20071019211433.GA76124@owl.midgard.homeip.net>
In-Reply-To: <4718D7D4.2010604@gmail.com>
References:  <4718D7D4.2010604@gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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@student.uu.se



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20071019211433.GA76124>