FS#20288 - [filesystem] 2010-02-4 /etc/profile detects wrongly sh as bash
Attached to Project:
Arch Linux
Opened by solsTiCe (zebul666) - Tuesday, 27 July 2010, 10:35 GMT
Last edited by Pierre Schmitz (Pierre) - Sunday, 12 December 2010, 23:39 GMT
Opened by solsTiCe (zebul666) - Tuesday, 27 July 2010, 10:35 GMT
Last edited by Pierre Schmitz (Pierre) - Sunday, 12 December 2010, 23:39 GMT
|
Details
By investigating bug #20264, it has been found that
/etc/profile detects the shell run in a broken way.
ls _l /proc/$$/exe will always return /bin/bash when run from a shell sh or /bin/sh (which is symlink to bash) so detection of shell in /etc/profile will fail some folks on #bash on freenode thinks trying to implement profile.$shell for each specific shell is I quote "stupid". however a way to fix could be to test for $POSIXLY_CORRECT which is set when bash is run as sh or compile bash with the correct option to use /etc/bash_profile ? how do other distro deal with diffrent shells in /etc/profile ? |
This task depends upon
Closed by Pierre Schmitz (Pierre)
Sunday, 12 December 2010, 23:39 GMT
Reason for closing: Fixed
Additional comments about closing: /etc/profile.$shell is no longer used
Sunday, 12 December 2010, 23:39 GMT
Reason for closing: Fixed
Additional comments about closing: /etc/profile.$shell is no longer used
see man login
"the cake is a lie"
I guess what was meant to say is that $SHELL can not be used to determine the currently running shell, which is true.
> however a way to fix could be to test for $POSIXLY_CORRECT which is set when bash is run as sh
Good to know, but still do we confine ourselves to sh/bash only? Besides, on ubuntu I have
-cur_work~> sh
$ echo $POSIXLY_CORRECT
$ echo $SHELL
/bin/bash
So, $SHELL is correct, but $POSIXLY_CORRECT is not... Should we trust env. vars?
I can't test right now, but would $(ps -p "$$" -o comm=) work?
$ echo $(ps -p "$$" -o comm=)
bash
[~]$ /bin/sh
[~]$ echo $(ps -p "$$" -o comm=)
sh
-svibor-13:46-~~> /bin/sh
-svibor-13:46-~~> ps -p $$ -o comm=
sh
-svibor-13:47-~~> ls -l /proc/$$/exe
lrwxrwxrwx 1 lisaev users 0 Aug 8 13:47 /proc/4027/exe -> /bin/bash
-svibor-13:47-~~> exit
exit
So, yeah it looks like that in /etc/profile one should replace "case $(/bin/ls -l /proc/$$/exe) in" with "case $(/bin/ps -p $$ -o comm=) in"...
Also, it may be irrelevant, but what's wrong with /proc/$$/exe pointing to bash when sh is run, if they are the same?
So you may replace with "case $0 in"
Still it would be better to check only the first token of the commandline ($0), as for example when GDM is launched (as for the bug that lead to the opening of this one) the command is "/bin/sh /usr/sbin/gdm"
-cur_work~> /bin/csh
% echo $0
No file for $0.
% exit
% exit
-cur_work~>
The problem with ps though, is that filesystem will now depend on procps...
case $(/bin/cat /proc/$$/cmdline|/bin/cut -d" " -f1) in
Just replace it with case $SHELL in, please.