aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/callproc.c206
-rw-r--r--src/emacs.c2
2 files changed, 57 insertions, 151 deletions
diff --git a/src/callproc.c b/src/callproc.c
index fb187d757d5..b2352e9bd55 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -113,7 +113,6 @@ Lisp_Object Vtemp_file_name_pattern;
113 113
114Lisp_Object Vshell_file_name; 114Lisp_Object Vshell_file_name;
115 115
116Lisp_Object Vglobal_environment;
117Lisp_Object Vprocess_environment; 116Lisp_Object Vprocess_environment;
118 117
119#ifdef DOS_NT 118#ifdef DOS_NT
@@ -134,9 +133,6 @@ int synch_process_termsig;
134 this is exit code of synchronous subprocess. */ 133 this is exit code of synchronous subprocess. */
135int synch_process_retcode; 134int synch_process_retcode;
136 135
137/* List of environment variables to look up in emacsclient. */
138Lisp_Object Vlocal_environment_variables;
139
140 136
141/* Clean up when exiting Fcall_process. 137/* Clean up when exiting Fcall_process.
142 On MSDOS, delete the temporary file on any kind of termination. 138 On MSDOS, delete the temporary file on any kind of termination.
@@ -1321,8 +1317,8 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir)
1321 register char **new_env; 1317 register char **new_env;
1322 char **p, **q; 1318 char **p, **q;
1323 register int new_length; 1319 register int new_length;
1324 Lisp_Object environment = Vglobal_environment; 1320 Lisp_Object local = get_frame_param (XFRAME (Fframe_with_environment (selected_frame)),
1325 Lisp_Object local; 1321 Qenvironment);
1326 1322
1327 new_length = 0; 1323 new_length = 0;
1328 1324
@@ -1331,20 +1327,7 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir)
1331 tem = XCDR (tem)) 1327 tem = XCDR (tem))
1332 new_length++; 1328 new_length++;
1333 1329
1334 if (!NILP (Vlocal_environment_variables)) 1330 for (tem = local;
1335 {
1336 local = get_frame_param (XFRAME (Fframe_with_environment (selected_frame)),
1337 Qenvironment);
1338 if (EQ (Vlocal_environment_variables, Qt)
1339 && !NILP (local))
1340 environment = local;
1341 else if (CONSP (local))
1342 {
1343 new_length += Fsafe_length (Vlocal_environment_variables);
1344 }
1345 }
1346
1347 for (tem = environment;
1348 CONSP (tem) && STRINGP (XCAR (tem)); 1331 CONSP (tem) && STRINGP (XCAR (tem));
1349 tem = XCDR (tem)) 1332 tem = XCDR (tem))
1350 new_length++; 1333 new_length++;
@@ -1354,7 +1337,7 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir)
1354 1337
1355 /* If we have a PWD envvar, pass one down, 1338 /* If we have a PWD envvar, pass one down,
1356 but with corrected value. */ 1339 but with corrected value. */
1357 if (getenv ("PWD")) 1340 if (egetenv ("PWD"))
1358 *new_env++ = pwd_var; 1341 *new_env++ = pwd_var;
1359 1342
1360 /* Overrides. */ 1343 /* Overrides. */
@@ -1363,17 +1346,10 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir)
1363 tem = XCDR (tem)) 1346 tem = XCDR (tem))
1364 new_env = add_env (env, new_env, SDATA (XCAR (tem))); 1347 new_env = add_env (env, new_env, SDATA (XCAR (tem)));
1365 1348
1366 /* Local part of environment, if Vlocal_environment_variables is a list. */ 1349 /* Local part of environment. */
1367 for (tem = Vlocal_environment_variables; 1350 for (tem = local;
1368 CONSP (tem) && STRINGP (XCAR (tem)); 1351 CONSP (tem) && STRINGP (XCAR (tem));
1369 tem = XCDR (tem)) 1352 tem = XCDR (tem))
1370 new_env = add_env (env, new_env, egetenv (SDATA (XCAR (tem))));
1371
1372 /* The rest of the environment (either Vglobal_environment or the
1373 'environment frame parameter). */
1374 for (tem = environment;
1375 CONSP (tem) && STRINGP (XCAR (tem));
1376 tem = XCDR (tem))
1377 new_env = add_env (env, new_env, SDATA (XCAR (tem))); 1353 new_env = add_env (env, new_env, SDATA (XCAR (tem)));
1378 1354
1379 *new_env = 0; 1355 *new_env = 0;
@@ -1510,79 +1486,47 @@ getenv_internal (var, varlen, value, valuelen, frame)
1510 Lisp_Object frame; 1486 Lisp_Object frame;
1511{ 1487{
1512 Lisp_Object scan; 1488 Lisp_Object scan;
1513 Lisp_Object environment = Vglobal_environment;
1514 1489
1515 /* Try to find VAR in Vprocess_environment first. */ 1490 if (NILP (frame))
1516 for (scan = Vprocess_environment; CONSP (scan); scan = XCDR (scan))
1517 { 1491 {
1518 Lisp_Object entry = XCAR (scan); 1492 /* Try to find VAR in Vprocess_environment first. */
1519 if (STRINGP (entry) 1493 for (scan = Vprocess_environment; CONSP (scan); scan = XCDR (scan))
1520 && SBYTES (entry) >= varlen 1494 {
1495 Lisp_Object entry = XCAR (scan);
1496 if (STRINGP (entry)
1497 && SBYTES (entry) >= varlen
1521#ifdef WINDOWSNT 1498#ifdef WINDOWSNT
1522 /* NT environment variables are case insensitive. */ 1499 /* NT environment variables are case insensitive. */
1523 && ! strnicmp (SDATA (entry), var, varlen) 1500 && ! strnicmp (SDATA (entry), var, varlen)
1524#else /* not WINDOWSNT */ 1501#else /* not WINDOWSNT */
1525 && ! bcmp (SDATA (entry), var, varlen) 1502 && ! bcmp (SDATA (entry), var, varlen)
1526#endif /* not WINDOWSNT */ 1503#endif /* not WINDOWSNT */
1527 ) 1504 )
1528 {
1529 if (SBYTES (entry) > varlen && SREF (entry, varlen) == '=')
1530 {
1531 *value = (char *) SDATA (entry) + (varlen + 1);
1532 *valuelen = SBYTES (entry) - (varlen + 1);
1533 return 1;
1534 }
1535 else if (SBYTES (entry) == varlen)
1536 { 1505 {
1537 /* Lone variable names in Vprocess_environment mean that 1506 if (SBYTES (entry) > varlen && SREF (entry, varlen) == '=')
1538 variable should be removed from the environment. */ 1507 {
1539 return 0; 1508 *value = (char *) SDATA (entry) + (varlen + 1);
1509 *valuelen = SBYTES (entry) - (varlen + 1);
1510 return 1;
1511 }
1512 else if (SBYTES (entry) == varlen)
1513 {
1514 /* Lone variable names in Vprocess_environment mean that
1515 variable should be removed from the environment. */
1516 return 0;
1517 }
1540 } 1518 }
1541 } 1519 }
1520 frame = selected_frame;
1542 } 1521 }
1543 1522
1544 /* Find the environment in which to search the variable. */ 1523 /* Find the environment in which to search the variable. */
1545 if (!NILP (frame)) 1524 CHECK_FRAME (frame);
1546 { 1525 frame = Fframe_with_environment (frame);
1547 Lisp_Object local;
1548
1549 CHECK_FRAME (frame);
1550 frame = Fframe_with_environment (frame);
1551 local = get_frame_param (XFRAME (frame), Qenvironment);
1552 /* Use Vglobal_environment if there is no local environment. */
1553 if (!NILP (local))
1554 environment = local;
1555 }
1556 else if (!NILP (Vlocal_environment_variables))
1557 {
1558 Lisp_Object local = get_frame_param (XFRAME (Fframe_with_environment (selected_frame)),
1559 Qenvironment);
1560 if (EQ (Vlocal_environment_variables, Qt)
1561 && !NILP (local))
1562 environment = local;
1563 else if (CONSP (local))
1564 {
1565 for (scan = Vlocal_environment_variables; CONSP (scan); scan = XCDR (scan))
1566 {
1567 Lisp_Object entry = XCAR (scan);
1568 if (STRINGP (entry)
1569 && SBYTES (entry) == varlen
1570#ifdef WINDOWSNT
1571 /* NT environment variables are case insensitive. */
1572 && ! strnicmp (SDATA (entry), var, varlen)
1573#else /* not WINDOWSNT */
1574 && ! bcmp (SDATA (entry), var, varlen)
1575#endif /* not WINDOWSNT */
1576 )
1577 {
1578 environment = local;
1579 break;
1580 }
1581 }
1582 }
1583 }
1584 1526
1585 for (scan = environment; CONSP (scan); scan = XCDR (scan)) 1527 for (scan = get_frame_param (XFRAME (frame), Qenvironment);
1528 CONSP (scan);
1529 scan = XCDR (scan))
1586 { 1530 {
1587 Lisp_Object entry; 1531 Lisp_Object entry;
1588 1532
@@ -1612,14 +1556,13 @@ DEFUN ("getenv-internal", Fgetenv_internal, Sgetenv_internal, 1, 2, 0,
1612VARIABLE should be a string. Value is nil if VARIABLE is undefined in 1556VARIABLE should be a string. Value is nil if VARIABLE is undefined in
1613the environment. Otherwise, value is a string. 1557the environment. Otherwise, value is a string.
1614 1558
1615If optional parameter FRAME is non-nil, then it should be a frame. If 1559This function searches `process-environment' for VARIABLE. If it is
1616that frame has its own set of environment variables, this function 1560not found there, then it continues the search in the environment list
1617will look up VARIABLE in there. 1561of the selected frame.
1618 1562
1619Otherwise, this function searches `process-environment' for VARIABLE. 1563If optional parameter FRAME is non-nil, then this function will ignore
1620If it is not found there, then it continues the search in either 1564`process-environment' and will simply look up the variable in that
1621`global-environment' or the environment list of the selected frame, 1565frame's environment. */)
1622depending on the value of `local-environment-variables'. */)
1623 (variable, frame) 1566 (variable, frame)
1624 Lisp_Object variable, frame; 1567 Lisp_Object variable, frame;
1625{ 1568{
@@ -1766,8 +1709,8 @@ init_callproc ()
1766 { 1709 {
1767 char *dir = getenv ("TMPDIR"); 1710 char *dir = getenv ("TMPDIR");
1768 Vtemp_file_name_pattern 1711 Vtemp_file_name_pattern
1769 = Fexpand_file_name (build_string ("emacsXXXXXX"), 1712 = Fexpand_file_name (build_string ("emacsXXXXXX"),
1770 build_string (dir)); 1713 build_string (dir));
1771 } 1714 }
1772 else 1715 else
1773 Vtemp_file_name_pattern = build_string ("/tmp/emacsXXXXXX"); 1716 Vtemp_file_name_pattern = build_string ("/tmp/emacsXXXXXX");
@@ -1783,17 +1726,18 @@ init_callproc ()
1783} 1726}
1784 1727
1785void 1728void
1786set_global_environment () 1729set_initial_environment ()
1787{ 1730{
1788 register char **envp; 1731 register char **envp;
1789 1732 Lisp_Object env = Qnil;
1790 Vglobal_environment = Qnil;
1791#ifndef CANNOT_DUMP 1733#ifndef CANNOT_DUMP
1792 if (initialized) 1734 if (initialized)
1793#endif 1735#endif
1794 for (envp = environ; *envp; envp++) 1736 {
1795 Vglobal_environment = Fcons (build_string (*envp), 1737 for (envp = environ; *envp; envp++)
1796 Vglobal_environment); 1738 env = Fcons (build_string (*envp), env);
1739 store_frame_param (SELECTED_FRAME(), Qenvironment, env);
1740 }
1797} 1741}
1798 1742
1799void 1743void
@@ -1851,37 +1795,16 @@ If this variable is nil, then Emacs is unable to use a shared directory. */);
1851This is used by `call-process-region'. */); 1795This is used by `call-process-region'. */);
1852 /* This variable is initialized in init_callproc. */ 1796 /* This variable is initialized in init_callproc. */
1853 1797
1854 DEFVAR_LISP ("global-environment", &Vglobal_environment,
1855 doc: /* Global list of environment variables for subprocesses to inherit.
1856Each element should be a string of the form ENVVARNAME=VALUE.
1857
1858The environment which Emacs inherits is placed in this variable when
1859Emacs starts.
1860
1861Some frames may have their own local list of environment variables in
1862their 'environment parameter, which may override this global list; see
1863`local-environment-variables' and `frame-with-environment'. See
1864`process-environment' for a way to modify an environment variable on
1865all frames.
1866
1867If multiple entries define the same variable, the first one always
1868takes precedence.
1869
1870Non-ASCII characters are encoded according to the initial value of
1871`locale-coding-system', i.e. the elements must normally be decoded for use.
1872See `setenv' and `getenv'. */);
1873
1874 DEFVAR_LISP ("process-environment", &Vprocess_environment, 1798 DEFVAR_LISP ("process-environment", &Vprocess_environment,
1875 doc: /* List of overridden environment variables for subprocesses to inherit. 1799 doc: /* List of overridden environment variables for subprocesses to inherit.
1876Each element should be a string of the form ENVVARNAME=VALUE. 1800Each element should be a string of the form ENVVARNAME=VALUE.
1877 1801
1878Entries in this list take precedence to those in `global-environment' 1802Entries in this list take precedence to those in the frame-local
1879or the frame-local environments. (See `local-environment-variables' 1803environments. Therefore, let-binding `process-environment' is an easy
1880and `frame-with-environment'.) Therefore, let-binding 1804way to temporarily change the value of an environment variable,
1881`process-environment' is an easy way to temporarily change the value 1805irrespective of where it comes from. To use `process-environment' to
1882of an environment variable, irrespective of where it comes from. To 1806remove an environment variable, include only its name in the list,
1883use `process-environment' to remove an environment variable, include 1807without "=VALUE".
1884only its name in the list, without "=VALUE".
1885 1808
1886This variable is set to nil when Emacs starts. 1809This variable is set to nil when Emacs starts.
1887 1810
@@ -1900,23 +1823,6 @@ See `setenv' and `getenv'. */);
1900 defsubr (&Sgetenv_internal); 1823 defsubr (&Sgetenv_internal);
1901#endif 1824#endif
1902 defsubr (&Scall_process_region); 1825 defsubr (&Scall_process_region);
1903
1904 DEFVAR_LISP ("local-environment-variables", &Vlocal_environment_variables,
1905 doc: /* Enable or disable frame-local environment variables.
1906If set to t, `getenv', `setenv' and subprocess creation functions use
1907the local environment of the selected frame, ignoring
1908`global-environment'.
1909
1910If set to nil, Emacs uses `global-environment' and ignores the
1911frame-local environment.
1912
1913Otherwise, `local-environment-variables' should be a list of variable
1914names (represented by Lisp strings) to look up in the frame's
1915environment. The rest will come from `global-environment'.
1916
1917The frame-local environment is stored in the 'environment frame
1918parameter. See `frame-with-environment'. */);
1919 Vlocal_environment_variables = Qt;
1920} 1826}
1921 1827
1922/* arch-tag: 769b8045-1df7-4d2b-8968-e3fb49017f95 1828/* arch-tag: 769b8045-1df7-4d2b-8968-e3fb49017f95
diff --git a/src/emacs.c b/src/emacs.c
index e9fb4e3cb85..ac6bf57c2cd 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -1518,7 +1518,7 @@ main (argc, argv
1518 /* egetenv is a pretty low-level facility, which may get called in 1518 /* egetenv is a pretty low-level facility, which may get called in
1519 many circumstances; it seems flimsy to put off initializing it 1519 many circumstances; it seems flimsy to put off initializing it
1520 until calling init_callproc. */ 1520 until calling init_callproc. */
1521 set_global_environment (); 1521 set_initial_environment ();
1522 /* AIX crashes are reported in system versions 3.2.3 and 3.2.4 1522 /* AIX crashes are reported in system versions 3.2.3 and 3.2.4
1523 if this is not done. Do it after set_global_environment so that we 1523 if this is not done. Do it after set_global_environment so that we
1524 don't pollute Vglobal_environment. */ 1524 don't pollute Vglobal_environment. */