OSDN Git Service

* cygheap.h (class cygheap_user): Add psystemroot member and
authorcorinna <corinna>
Thu, 7 Oct 2004 21:28:56 +0000 (21:28 +0000)
committercorinna <corinna>
Thu, 7 Oct 2004 21:28:56 +0000 (21:28 +0000)
env_systemroot method.
* environ.cc (struct spenv): Add add_always member.
(spenvs): Accomodate new add_always member.  Add
cygheap_user::env_systemroot method to SYSTEMROOT entry.
(build_env): Check add_always member when adding missing environment
variables from spenvs.
* uinfo.cc (cygheap_user::env_systemroot): New method.

winsup/cygwin/ChangeLog
winsup/cygwin/cygheap.h
winsup/cygwin/environ.cc
winsup/cygwin/uinfo.cc

index 74fe843..0533bf7 100644 (file)
@@ -1,5 +1,16 @@
 2004-10-07  Corinna Vinschen  <corinna@vinschen.de>
 
+       * cygheap.h (class cygheap_user): Add psystemroot member and
+       env_systemroot method.
+       * environ.cc (struct spenv): Add add_always member.
+       (spenvs): Accomodate new add_always member.  Add
+       cygheap_user::env_systemroot method to SYSTEMROOT entry.
+       (build_env): Check add_always member when adding missing environment
+       variables from spenvs.
+       * uinfo.cc (cygheap_user::env_systemroot): New method.
+
+2004-10-07  Corinna Vinschen  <corinna@vinschen.de>
+
        * dcrt0.cc (dll_crt0_0): Drop duplicated line.
 
 2004-10-07  Christopher Faylor  <cgf@timesys.com>
index b8203bf..80abe6e 100644 (file)
@@ -106,6 +106,7 @@ class cygheap_user
   char  *pdomain;       /* Logon domain of the user */
   char  *homedrive;    /* User's home drive */
   char  *homepath;     /* User's home path */
+  char  *psystemroot;  /* Value of SYSTEMROOT */
   char  *pwinname;     /* User's name as far as Windows knows it */
   char  *puserprof;    /* User profile */
   cygsid effec_cygsid;  /* buffer for user's SID */
@@ -146,6 +147,7 @@ public:
   const char *env_userprofile (const char *, size_t);
   const char *env_domain (const char *, size_t);
   const char *env_name (const char *, size_t);
+  const char *env_systemroot (const char *, size_t);
 
   const char *logsrv ()
   {
index 6bd5f2f..90c828e 100644 (file)
@@ -819,7 +819,9 @@ struct spenv
 {
   const char *name;
   size_t namelen;
+  bool add_always;     /* If true, always add to env if missing */
   const char * (cygheap_user::*from_cygheap) (const char *, size_t);
+
   char *retrieve (bool, const char * const = NULL)
     __attribute__ ((regparm (3)));
 };
@@ -829,14 +831,14 @@ struct spenv
 /* Keep this list in upper case and sorted */
 static NO_COPY spenv spenvs[] =
 {
-  {NL ("HOMEDRIVE="), &cygheap_user::env_homedrive},
-  {NL ("HOMEPATH="), &cygheap_user::env_homepath},
-  {NL ("LOGONSERVER="), &cygheap_user::env_logsrv},
-  {NL ("SYSTEMDRIVE="), NULL},
-  {NL ("SYSTEMROOT="), NULL},
-  {NL ("USERDOMAIN="), &cygheap_user::env_domain},
-  {NL ("USERNAME="), &cygheap_user::env_name},
-  {NL ("USERPROFILE="), &cygheap_user::env_userprofile},
+  {NL ("HOMEDRIVE="), false, &cygheap_user::env_homedrive},
+  {NL ("HOMEPATH="), false, &cygheap_user::env_homepath},
+  {NL ("LOGONSERVER="), false, &cygheap_user::env_logsrv},
+  {NL ("SYSTEMDRIVE="), false, NULL},
+  {NL ("SYSTEMROOT="), true, &cygheap_user::env_systemroot},
+  {NL ("USERDOMAIN="), false, &cygheap_user::env_domain},
+  {NL ("USERNAME="), false, &cygheap_user::env_name},
+  {NL ("USERPROFILE="), false, &cygheap_user::env_userprofile},
 };
 
 char *
@@ -928,9 +930,8 @@ build_env (const char * const *envp, char *&envblock, int &envc,
 
   assert ((srcp - envp) == n);
   /* Fill in any required-but-missing environment variables. */
-  if (cygheap->user.issetuid ())
-    for (unsigned i = 0; i < SPENVS_SIZE; i++)
-      if (!saw_spenv[i])
+  for (unsigned i = 0; i < SPENVS_SIZE; i++)
+    if (!saw_spenv[i] && (spenvs[i].add_always || cygheap->user.issetuid ()))
       {
          *dstp = spenvs[i].retrieve (no_envblock);
          if (*dstp && !no_envblock && *dstp != env_dontadd)
index 757ca20..6fca2fd 100644 (file)
@@ -449,6 +449,28 @@ cygheap_user::env_name (const char *name, size_t namelen)
   return pwinname;
 }
 
+const char *
+cygheap_user::env_systemroot (const char *name, size_t namelen)
+{
+  if (!psystemroot)
+    {
+      int size = GetWindowsDirectory (NULL, 0);
+      if (size > 0)
+        {
+         psystemroot = (char *) cmalloc (HEAP_STR, ++size);
+         size = GetWindowsDirectory (psystemroot, size);
+         if (size <= 0)
+           {
+             cfree (psystemroot);
+             psystemroot = NULL;
+           }
+       }
+      if (size <= 0)
+        debug_printf ("GetWindowsDirectory(), %E");
+    }
+  return psystemroot;
+}
+
 char *
 pwdgrp::next_str (char c)
 {