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

Re: Is a pristine shell allowed to set HOME? (fwd)



Bart Schaefer wrote:
> I was thinking perhaps it should continue to set HOME when in "zsh
> emulation" but not when in any other shell emulations.  I should have
> said so before, but I was in a hurry when I was forwarding that ...

I was hoping to avoid too much complexity, but I suppose you're right.

Index: README
===================================================================
RCS file: /cvsroot/zsh/zsh/README,v
retrieving revision 1.25
diff -u -r1.25 README
--- README	6 Feb 2006 12:05:32 -0000	1.25
+++ README	7 Feb 2006 11:10:20 -0000
@@ -31,8 +31,9 @@
 handling of other arguments).  This appears to be the standard shell
 behaviour.
 
-The variable HOME is no longer set by the shell; it must be present
-in the environment.  It is valid for the variable to be unset.
+The variable HOME is no longer set by the shell if zsh is emulating any
+other shell at startup; it must be present in the environment or set
+subsequently by the user.  It is valid for the variable to be unset.
 
 Zsh has previously been lax about whether it allows octets with the
 top bit set to be part of a shell identifier.  With --enable-multibyte set,
Index: Src/init.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/init.c,v
retrieving revision 1.62
diff -u -r1.62 init.c
--- Src/init.c	6 Feb 2006 11:57:05 -0000	1.62
+++ Src/init.c	7 Feb 2006 11:10:21 -0000
@@ -798,19 +798,28 @@
     /* Get password entry and set info for `USERNAME' */
 #ifdef HAVE_GETPWUID
     if ((pswd = getpwuid(cached_uid))) {
+	if (emulation == EMULATE_ZSH)
+	    home = metafy(pswd->pw_dir, -1, META_DUP);
 	cached_username = ztrdup(pswd->pw_name);
-    } else
+    }
+    else
 #endif /* HAVE_GETPWUID */
-	   {
+    {
+	if (emulation == EMULATE_ZSH)
+	    home = ztrdup("/");
 	cached_username = ztrdup("");
     }
 
     /*
      * Try a cheap test to see if we can initialize `PWD' from `HOME'.
-     * HOME must come from the environment; we're not allowed to
-     * set it locally.
+     * In non-native emulations HOME must come from the environment;
+     * we're not allowed to set it locally.
      */
-    if ((ptr = getenv("HOME")) && ispwd(ptr))
+    if (emulation == EMULATE_ZSH)
+	ptr = home;
+    else
+	ptr = getenv("HOME");
+    if (ptr && ispwd(ptr))
 	pwd = ztrdup(ptr);
     else if ((ptr = zgetenv("PWD")) && (strlen(ptr) < PATH_MAX) &&
 	     (ptr = metafy(ptr, -1, META_STATIC), ispwd(ptr)))
Index: Src/params.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/params.c,v
retrieving revision 1.108
diff -u -r1.108 params.c
--- Src/params.c	6 Feb 2006 11:57:06 -0000	1.108
+++ Src/params.c	7 Feb 2006 11:10:22 -0000
@@ -690,6 +690,17 @@
     *envp = '\0';
     opts[ALLEXPORT] = oae;
 
+    if (emulation == EMULATE_ZSH)
+    {
+	/*
+	 * For native emulation we always set the variable home
+	 * (see setupvals()).
+	 */
+	pm = (Param) paramtab->getnode(paramtab, "HOME");
+	pm->flags &= ~PM_UNSET;
+	if (!(pm->flags & PM_EXPORTED))
+	    addenv(pm, home);
+    }
     pm = (Param) paramtab->getnode(paramtab, "LOGNAME");
     if (!(pm->flags & PM_EXPORTED))
 	addenv(pm, pm->u.str);
Index: Doc/Zsh/params.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/params.yo,v
retrieving revision 1.27
diff -u -r1.27 params.yo
--- Doc/Zsh/params.yo	7 Nov 2005 09:37:34 -0000	1.27
+++ Doc/Zsh/params.yo	7 Feb 2006 11:14:21 -0000
@@ -805,7 +805,10 @@
 )
 vindex(HOME)
 item(tt(HOME) <S>)(
-The default argument for the tt(cd) command.
+The default argument for the tt(cd) command.  This is not set automatically
+by the shell in tt(sh), tt(ksh) or tt(csh) emulation, but it is typically
+present in the environment anyway, and if it becomes set it has its usual
+special behaviour.
 )
 vindex(IFS)
 item(tt(IFS) <S>)(

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php



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