Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: 3.1.5-pws-18: Re: zsh bug



"Arnon Kanfi" wrote:
> I have discovered a bug in zsh 3.1.4 when used on SunOs. when doing an "su"
> zsh will not read any of the global RC files. After tracking the problem I
> have found out that su on SunOs 4.1.4 sets argv[0] to "-su" which causes zsh
> to do "sh" emulation and not read the RC files. Enclosed is a small patch
> that fixes the problem on SunOs (I use the "SHELL" env variable which is set
> correctly to /usr/bin/zsh)

There was a discussion on this back in zsh-workers/3221 and follow-ups,
although it concentrated more on whether su itself was broken.  The real
problem here is that zsh can't actually know what it should be emulating;
su might have exec'd an `sh' which happened to be zsh in disguise.
Nonetheless, I would agree that the best bet is to do native emulation in
this case.

If it had been up to me, I would have restricted the cases when zsh did
emulation to a fixed set of names rather than the first letter.  But now
the current behaviour is well established, although as far as I can see
undocumented, the simplest fix is to check if the name begins `su' and if
so ignore it for emulation purposes.  This leaves zsh_name as su, but I
think that's the right thing to do if that's how the shell was called.

The following patch also documents the algorithm for choosing emulation for
the first time (unless I've failed to locate something in Doc/Zsh).

Or has somebody got a better suggestion?

--- Doc/Zsh/compat.yo.su	Thu Dec 17 17:10:13 1998
+++ Doc/Zsh/compat.yo	Mon May 17 11:13:36 1999
@@ -7,7 +7,18 @@
 cindex(sh, compatibility)
 cindex(ksh, compatibility)
 Zsh tries to emulate bf(sh) or bf(ksh) when it is invoked as
-tt(sh) or tt(ksh) respectively.  In this mode the following
+tt(sh) or tt(ksh) respectively.  More precisely, it looks at the first
+letter of the name passed to it, which may not necessarily be the
+name of the executable file, ignoring any initial `tt(-)' as well as
+`tt(r)' (for restricted); an `tt(s)' or `tt(b)' will force
+bf(sh) compatibility, while `tt(k)' will force bf(ksh) compatibility.  An
+exception is if the first two letters excluding any `tt(-)' are tt(su), in
+which case no emulation will be performed; this is to workaround a problem
+under some operating systems where the tt(su) command does not change the
+name when executing a user shell.  Note that, from within zsh itself, this
+mechanism can be invoked by `tt(ARGV0=sh zsh ...)'.
+
+In this emulation mode, the following
 parameters are not special and not initialized by the shell:
 tt(ARGC),
 tt(argv),
--- Src/options.c.su	Thu May 13 17:45:43 1999
+++ Src/options.c	Mon May 17 10:53:26 1999
@@ -446,7 +446,7 @@
 	emulation = EMULATE_CSH;
     else if (ch == 'k')
 	emulation = EMULATE_KSH;
-    else if (ch == 's' || ch == 'b')
+    else if ((ch == 's' && zsh_name[1] != 'u') || ch == 'b')
 	emulation = EMULATE_SH;
     else
 	emulation = EMULATE_ZSH;

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxx>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy



Messages sorted by: Reverse Date, Date, Thread, Author