Why tinit or login -p do overwrite PATH variable?

Simple test reveals this problem. I added 2 lines to
/etc/config/sysinit.:

export PATH=$PATH:/mydir
echo $PATH
<…some other stuff…>
tinit -T /dev/con* -t /dev/con1 &
<…some other stuff…>

I can see at this point the PATH is “/bin:/etc:/usr/bin:/mydir”. All other
programs launched from the sysinit have the same PATH in their environments.
After login prompt is shown and I login (no matter what user), the PATH is
“/bin:/etc:/usr/bin:/usr/local/bin” (/etc/profile has “export
PATH=$PATH:/usr/local/bin” line). All other variables assigned in the
sysinit are preserved.

Why does this happen?

Sincerely,

Serge

Serge Yuschenko <serge.yuschenko@rogers.com> wrote:

Simple test reveals this problem. I added 2 lines to
/etc/config/sysinit.:

export PATH=$PATH:/mydir
echo $PATH
…some other stuff…
tinit -T /dev/con* -t /dev/con1 &
…some other stuff…

I can see at this point the PATH is “/bin:/etc:/usr/bin:/mydir”. All other
programs launched from the sysinit have the same PATH in their environments.
After login prompt is shown and I login (no matter what user), the PATH is
“/bin:/etc:/usr/bin:/usr/local/bin” (/etc/profile has “export
PATH=$PATH:/usr/local/bin” line). All other variables assigned in the
sysinit are preserved.

Why does this happen?

login is expected to clear all environment variables that are not listed
in the file /etc/default/login — the other environment variables
set in the sysinit are probably listed in /etc/default/login.

For setting environment variables that you want everyone to get after
they login, try modifying the file /etc/profile – that file is examined
by the shell anytime it is a login shell.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

“Serge Yuschenko” <serge.yuschenko@rogers.com> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ
ÓÌÅÄÕÀÝÅÅ: news:al6ekd$1n3$1@inn.qnx.com

export PATH=$PATH:/mydir
echo $PATH
…some other stuff…
tinit -T /dev/con* -t /dev/con1 &
…some other stuff…

I can see at this point the PATH is “/bin:/etc:/usr/bin:/mydir”. All other
programs launched from the sysinit have the same PATH in their
environments.
After login prompt is shown and I login (no matter what user), the PATH is
“/bin:/etc:/usr/bin:/usr/local/bin” (/etc/profile has “export
PATH=$PATH:/usr/local/bin” line). All other variables assigned in the
sysinit are preserved.

Weird. The -p option should make ‘login’ preserve the environment. Here’ s
my example, it works OK. Did I miss anything?

[//11:root] /home/root # export foo=“bar”
[//11:root] /home/root # login -p
Welcome to QNX 4.25
Copyright (c) QNX Software Systems Ltd. 1982,1998
login: root
password:
Last login: Fri Sep 06 12:33:32 2002 on //11/dev/ttyp1
Fri Sep 06 12:34:28 2002
[//11:root] /home/root # export foo="$foo:quux"
[//11:root] /home/root # export | grep foo
foo=bar:quux
[//11:root] /home/root #

“What version are you using?” #;-)=)

P.S. Glad to see you man. :slight_smile:

Regards,

  • Nick

login - runs and does its thing then starts a shell for the user, typically
/bin/sh
/bin/sh - sets default values for PATH ( :/bin:/usr/bin) so this overwrites
any previous PATH definition.
/etc/profile - is run in the current shell. This may alter the PATH env
variable.

“Nikolai Gorbunov” <n.gorbunov@swd.ru> wrote in message
news:al9qsp$g9q$1@inn.qnx.com

“Serge Yuschenko” <> serge.yuschenko@rogers.com> > ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ
ÓÌÅÄÕÀÝÅÅ: news:al6ekd$1n3$> 1@inn.qnx.com> …

export PATH=$PATH:/mydir
echo $PATH
…some other stuff…
tinit -T /dev/con* -t /dev/con1 &
…some other stuff…

I can see at this point the PATH is “/bin:/etc:/usr/bin:/mydir”. All
other
programs launched from the sysinit have the same PATH in their
environments.
After login prompt is shown and I login (no matter what user), the PATH
is
“/bin:/etc:/usr/bin:/usr/local/bin” (/etc/profile has “export
PATH=$PATH:/usr/local/bin” line). All other variables assigned in the
sysinit are preserved.

Weird. The -p option should make ‘login’ preserve the environment. Here’ s
my example, it works OK. Did I miss anything?

[//11:root] /home/root # export foo=“bar”
[//11:root] /home/root # login -p
Welcome to QNX 4.25
Copyright (c) QNX Software Systems Ltd. 1982,1998
login: root
password:
Last login: Fri Sep 06 12:33:32 2002 on file://11/dev/ttyp1
Fri Sep 06 12:34:28 2002
[//11:root] /home/root # export foo="$foo:quux"
[//11:root] /home/root # export | grep foo
foo=bar:quux
[//11:root] /home/root #

“What version are you using?” #;-)=)

P.S. Glad to see you man. > :slight_smile:

Regards,

  • Nick

Hi David,

“David Gibbs” <dagibbs@qnx.com> wrote in message
news:al7oqi$1o8$1@nntp.qnx.com

login is expected to clear all environment variables that are not listed
in the file /etc/default/login — the other environment variables
set in the sysinit are probably listed in /etc/default/login.

The documentation gives it a little bit different way. With the ‘-p’ login
should preserve current environment variables. I get it as ALL variables
with no exceptions. Now all of them but PATH are preseved. The PATH is reset
to the same value as sinit initializes it. Without ‘-p’ it clears ALL
variables and sets HOME, LOGNAME, SHELL and those mentioned in the
/etc/default/login.

For setting environment variables that you want everyone to get after
they login, try modifying the file /etc/profile – that file is examined
by the shell anytime it is a login shell.

I agree. The /etc/profile is conventional way. The point is that some
applications need to be started before any user has logged. We want all
programs to have the same PATH set no matter whether the program was
launched from /etc/config/sysinit or from command prompt by a user.
Actually, it may not be exactly the same, but it has to contain some
necessary pathes. Now we set the needed PATH in sysinit and repeat the same
in profile. It has been like this for years. Now we just wanted to do some
optimization and eliminate the duplication.


-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

Regards,

Serge

Hi Nick,

“Nikolai Gorbunov” <n.gorbunov@swd.ru> wrote in message
news:al9qsp$g9q$1@inn.qnx.com

Weird. The -p option should make ‘login’ preserve the environment. Here’ s
my example, it works OK. Did I miss anything?

The only difference of your example from mine is that you start login from
command prompt instead using tinit.

[//11:root] /home/root # export foo=“bar”
[//11:root] /home/root # login -p
Welcome to QNX 4.25
Copyright (c) QNX Software Systems Ltd. 1982,1998
login: root
password:
Last login: Fri Sep 06 12:33:32 2002 on //11/dev/ttyp1
Fri Sep 06 12:34:28 2002
[//11:root] /home/root # export foo="$foo:quux"
[//11:root] /home/root # export | grep foo
foo=bar:quux
[//11:root] /home/root #

“What version are you using?” #;-)=)

I tried it in 4.25 and 4.25 C or D whatewer the latest patch is. By the way,
same picture in RTP.

P.S. Glad to see you man. > :slight_smile:

Glad to see you too. I’ve been here for a while (mostly in qdn.public.rtp).
But just recently I realized that nobody here (in inn.qnx.com) seen my
messages since I posted them via google (119 port is closed in my company).
Now I use conventional tools from home.

Regards,

  • Nick

See you later,

Serge

Hi Richard,

“Brown, Richard” brownr_aecl_ca@127.0.0.1 wrote in message
news:ala03m$jmh$1@inn.qnx.com

login - runs and does its thing then starts a shell for the user,
typically
/bin/sh
/bin/sh - sets default values for PATH ( :/bin:/usr/bin) so this
overwrites
any previous PATH definition.

on -t /dev/con1 /bin/sh
or
tinit -T /dev/con* -c /bin/sh -t /dev/con1
keep PATH intact.

/etc/profile - is run in the current shell. This may alter the PATH env
variable.

That is what I’m trying to achieve: not to set PATH in profile, but use the
one from sysinit.

Regards,

Serge

Serge Yuschenko <serge.yuschenko@rogers.com> wrote:

Hi Richard,

“Brown, Richard” brownr_aecl_ca@127.0.0.1 wrote in message
news:ala03m$jmh$> 1@inn.qnx.com> …
login - runs and does its thing then starts a shell for the user,
typically
/bin/sh
/bin/sh - sets default values for PATH ( :/bin:/usr/bin) so this
overwrites
any previous PATH definition.

on -t /dev/con1 /bin/sh
or
tinit -T /dev/con* -c /bin/sh -t /dev/con1
keep PATH intact.

Note that the shell will do different things depending on whether it
is a login shell or not. It determines this by looking at argv[0][0] and
if that characters is a ‘-’ it will think it is a login shell, and
behave differently.

I would not be surprised if it clears/re-inits the PATH if it is a
login shell, but not otherwise. In fact, I expect this would be
the case.

/etc/profile - is run in the current shell. This may alter the PATH env
variable.


That is what I’m trying to achieve: not to set PATH in profile, but use the
one from sysinit.

/etc/profile is probably the best general place to set things
like this. It is run by all login shells at startup – therefor
anything set there will be inheritted by everyone logging in.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.