Re: PATH variable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Sep 08, 2004 at 03:13:11PM -0400, Robert Locke wrote:
> On Wed, 2004-09-08 at 13:58, Nifty Hat Mitch wrote:
> > On Wed, Sep 08, 2004 at 08:02:27AM +0200, Joachim Backes wrote:
> > 
> > > can somebody tell me where the PATH variable is initially set? I'm
> > > sure, not in /etc/profile.
> > 
> > The strict answer to this is that it is set 
> > by init (/sbin/init).
....
> > 
> 
> I need to contest some of what you are saying....  For one, where do
> several of the directories you quote get removed from the $PATH of a
> regular user, if I am using the "init" process' $PATH?
> 
> So let me quote man bash
....> 
> In doing a strings of /bin/bash, I notice a string of
> "/usr/local/bin:/bin:/usr/bin"...
....
> I have to admit the thought of this being hard-coded into /bin/bash
> bothers me, but....
> 
> Any thoughts?

Thought.. "Use the Source Luke".

In .../variables.c of bash source there is code that looks like:

  /* Now make our own defaults in case the vars that we think are
     important are missing. */
  temp_var = set_if_not ("PATH", DEFAULT_PATH_VALUE);

So in this case the PATH string you are seeing with strings
would be set if $PATH was not set (some additional conditions apply).

The man page notes that the default PATH is system dependent
and the Fedora source has a patch applied.  This accounts
for the difference in the man page and the string you see 
in the binary.
...
 /* The default value of the PATH variable. */
 #ifndef DEFAULT_PATH_VALUE
 #define DEFAULT_PATH_VALUE \
-  "/usr/gnu/bin:/usr/local/bin:/usr/ucb:/bin:/usr/bin:."
+  "/usr/local/bin:/bin:/usr/bin"
 #endif
...

It may be important to recall the initial question.
  > > > can somebody tell me where the PATH variable is initially set?

There is some risk of splitting hairs here but it is most important to
know where PATH was set last not when or where it was initially set.
In the chain of process creation PATH in the environment can be set,
reset, unset, appended to, sliced, diced what ever.

For most of us the important topic is that the login process does a
number of things to ensure a stable and secure system.  In the login
sequence a lot of reset, unset, slice, dice does go on.   There are
commonly two types of login sequences started by init.  Each fiddles 
with PATH a bit differently.  In /etc/inittab you will find...

    six of these
	  # Run gettys in standard runlevels 
          1:2345:respawn:/sbin/mingetty tty1
    and one of these
          # Run xdm in runlevel 5
	  x:5:respawn:/etc/X11/prefdm -nodaemon
    not directly in inittab  will be "sshd", "rshd", "rlogin"
    and other network login actions.

With little regard for how and where the PATH variable may initially
be set (see my initial answer) these inittab login lines will start a chain
of events that will set $PATH and other parts of the environment for
users.

With X running things are more complex than a tty login.

See also man -a exec


-- 
	T o m  M i t c h e l l 




[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux