[Bug 340952] New: Check to see which shell is reading /etc/profile is wrong
https://bugzilla.novell.com/show_bug.cgi?id=340952 Summary: Check to see which shell is reading /etc/profile is wrong Product: openSUSE 10.3 Version: Final Platform: All OS/Version: Other Status: NEW Severity: Normal Priority: P5 - None Component: Basesystem AssignedTo: bnc-team-screening@forge.provo.novell.com ReportedBy: torsten.foertsch@gmx.net QAContact: qa@suse.de Found By: --- If a script like /usr/sbin/Check (used during rpm building) with a shebang line that reads #!/bin/sh reads /etc/profile the check at the top of /etc/profile should set is=sh but instead it sets is=bash. That leads to a subsequent read of ~/.bashrc which is wrong if bash is in sh-mode. ~/.bashrc is by definition only read by a bash. It may contain statements that are understood by bash but not by sh. After patching my /etc/profile looks like this: if test -f /proc/mounts ; then case "`/bin/ls -l /proc/$$/exe`" in */bash) is=bash ;; */ash) is=ash ;; */ksh) is=ksh ;; */pdksh) is=ksh ;; */zsh) is=zsh ;; */*) is=sh ;; esac read x </proc/$$/cmdline case "$x" in sh|*/sh) is=sh ;; esac # # `r' in $- occurs *after* system files are parsed # for a in $SHELL ; do .. The "read x..." plus the case-statement are new. I have checked this with all mentioned shells, bash, ash, ksh, pdksh and zsh. -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug.
https://bugzilla.novell.com/show_bug.cgi?id=340952#c1 --- Comment #1 from Torsten Foertsch <torsten.foertsch@gmx.net> 2007-11-12 03:24:55 MST --- case "`awk -F'\0' '{print $1}' /proc/$$/cmdline`" in sh|*/sh) is=sh ;; esac This test is better. It sets is=sh even if a ksh, zsh, etc is called as /bin/sh as in perl -e 'exec {"/bin/ash"} qw!/bin/sh -x /etc/profile!' -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug.
https://bugzilla.novell.com/show_bug.cgi?id=340952 Philipp Thomas <pth@novell.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |pth@novell.com AssignedTo|bnc-team-screening@forge.provo.novell.com |werner@novell.com -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug.
https://bugzilla.novell.com/show_bug.cgi?id=340952#c2 Dr. Werner Fink <werner@novell.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Severity|Normal |Minor Status|NEW |NEEDINFO Info Provider| |torsten.foertsch@gmx.net --- Comment #2 from Dr. Werner Fink <werner@novell.com> 2007-11-13 03:38:58 MST --- To be noted: there will be *no* external program like awk within /etc/bash.bashrc nor /etc/profile ;) Beside this, does case "$0" in sh|*/sh) is=sh ;; esac work also for you? -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug.
https://bugzilla.novell.com/show_bug.cgi?id=340952#c3 --- Comment #3 from Dr. Werner Fink <werner@novell.com> 2007-11-13 03:46:27 MST --- Beside this, some bourne shell show problems like magellan:werner # bash -c 'exec -la /bin/sh /bin/ksh' h:w$ echo $is sh h:w$ magellan:werner # bash -c 'exec -la /bin/sh /bin/zsh' \h:\w\$ echo $is sh \h:\w\$ magellan:werner # bash -c 'exec -la /bin/sh /bin/ash' alias: -- not found alias: -- not found alias: -- not found alias: -- not found \h:\w\$ echo $is sh sh as you can see, it makes sence to distinguish between several bourne shell derivates. -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug.
https://bugzilla.novell.com/show_bug.cgi?id=340952#c4 --- Comment #4 from Dr. Werner Fink <werner@novell.com> 2007-11-14 05:28:22 MST --- any news? -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug.
https://bugzilla.novell.com/show_bug.cgi?id=340952#c5 Torsten Foertsch <torsten.foertsch@gmx.net> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |torsten.foertsch@gmx.net Status|NEEDINFO |NEW Info Provider|torsten.foertsch@gmx.net | --- Comment #5 from Torsten Foertsch <torsten.foertsch@gmx.net> 2007-11-27 05:41:11 MST --- Replying to comment #2, I think I can say it wont work (without actually trying out). $0 is the name of the shell script not the shell itself if the shell is invoked via a shebang line. So if the script /usr/sbin/Check is called $0 is "/usr/sbin/Check" not "/bin/sh". I agree it would be better to solve this without external programs and even better without /proc. I'd really like to learn how that can be done. Replying to comment #3, I agree there is more to do than what my initial report recommends. I was trying to resolve my current problem. That is I was trying to make /usr/sbin/Check work in my environment. Maybe it would be better to do the extra check only if is=bash. The problem is not a login shell it is a script like /usr/sbin/Check that starts with #!/bin/sh (not #!/bin/bash) and sources /etc/profile: #!/bin/sh /etc/profile Then something like this would work: case "`/bin/ls -l /proc/$$/exe`" in */bash) # The next line is based on an erroneous behavior of the current bash. # It stops reading at the first NULL byte. read x </proc/$$/cmdline case "$x" in sh|*/sh) is=sh ;; *) is=bash ;; esac ;; */ash) is=ash ;; */ksh) is=ksh ;; */pdksh) is=ksh ;; */zsh) is=zsh ;; */*) is=sh ;; esac It works without external programs. But see the comment. It may not work for future bashs. That way a login ash works: $ bash -c 'exec -la /bin/sh /bin/ash' r2@opi:/home/r2> echo $is ash r2@opi:/home/r2> as well as a bash that is invoked as /bin/sh via a shebang line. -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug.
https://bugzilla.novell.com/show_bug.cgi?id=340952 User werner@novell.com added comment https://bugzilla.novell.com/show_bug.cgi?id=340952#c6 Dr. Werner Fink <werner@novell.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED --- Comment #6 from Dr. Werner Fink <werner@novell.com> 2007-12-04 09:06:46 MST --- Just doing this way case "`/bin/ls --color=never -l /proc/$$/exe`" in */bash) is=bash read -t 1 a r </proc/$$/cmdline case "$a" in sh|-sh|*/sh) is=sh ;; esac ;; */ash) is=ash ;; */ksh) is=ksh ;; */pdksh) is=ksh ;; */zsh) is=zsh ;; */*) is=sh ;; esac should work even for future bash versions -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug.
participants (1)
-
bugzilla_noreply@novell.com