@@ -180,7 +180,7 @@ strbrk(char *&buf)
180180/* Parse a string of the form "something=stuff somethingelse=more-stuff",
181181 silently ignoring unknown "somethings". */
182182static void
183- parse_options (const char *inbuf)
183+ parse_options (const char *inbuf, bool is_msys2 )
184184{
185185 int istrue;
186186 parse_thing *k;
@@ -201,7 +201,10 @@ parse_options (const char *inbuf)
201201 if (export_settings)
202202 {
203203 debug_printf (" %s" , newbuf + 1 );
204- setenv (" CYGWIN" , newbuf + 1 , 1 );
204+ if (is_msys2)
205+ setenv (" MSYS" , newbuf + 1 , 1 );
206+ else
207+ setenv (" CYGWIN" , newbuf + 1 , 1 );
205208 }
206209 return ;
207210 }
@@ -674,8 +677,10 @@ _addenv (const char *name, const char *value, int overwrite)
674677 win_env *spenv;
675678 if ((spenv = getwinenv (envhere)))
676679 spenv->add_cache (value);
680+ if (strcmp (name, " MSYS" ) == 0 )
681+ parse_options (value, true );
677682 if (strcmp (name, " CYGWIN" ) == 0 )
678- parse_options (value);
683+ parse_options (value, false );
679684
680685 return 0 ;
681686}
@@ -873,9 +878,12 @@ environ_init (char **envp, int envc)
873878 dumper_init ();
874879 if (envp_passed_in)
875880 {
881+ p = getenv (" MSYS" );
882+ if (p)
883+ parse_options (p, true );
876884 p = getenv (" CYGWIN" );
877885 if (p)
878- parse_options (p);
886+ parse_options (p, false );
879887 }
880888 }
881889 __except (NO_ERROR)
@@ -929,8 +937,10 @@ win32env_to_cygenv (PWCHAR rawenv, bool posify)
929937 }
930938 sawTERM = 1 ;
931939 }
940+ else if (*newp == ' M' && strncmp (newp, " MSYS=" , 5 ) == 0 )
941+ parse_options (newp + 5 , true );
932942 else if (*newp == ' C' && strncmp (newp, " CYGWIN=" , 7 ) == 0 )
933- parse_options (newp + 7 );
943+ parse_options (newp + 7 , false );
934944 if (*eq && posify)
935945 posify_maybe (envp + i, *++eq ? eq : --eq, tmpbuf);
936946 debug_printf (" %p: %s" , envp[i], envp[i]);
@@ -1193,8 +1203,12 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
11931203#ifdef __MSYS__
11941204 if (ascii_strncasematch (*srcp, " MSYS=" , 5 ))
11951205 {
1196- parse_options (*srcp + 5 );
1197- }
1206+ parse_options (*srcp + 5 , true );
1207+ }
1208+ else if (ascii_strncasematch (*srcp, " CYGWIN=" , 7 ))
1209+ {
1210+ parse_options (*srcp + 7 , false );
1211+ }
11981212 else if (!keep_posix)
11991213 {
12001214 /* Don't pass timezone environment to non-msys applications */
0 commit comments