aboutsummaryrefslogtreecommitdiffstats
path: root/src/callproc.c
diff options
context:
space:
mode:
authorJoakim Verona2011-02-05 11:23:09 +0100
committerJoakim Verona2011-02-05 11:23:09 +0100
commit4bd51ad5c3445b644dfb017d5b57b10a90aa325f (patch)
tree894801e7308ce4ecc34933f959e28f4b9cff9533 /src/callproc.c
parent13cfe8df462ab8da9f0028e16cc84dcaceaca3d1 (diff)
parent9bcaafce5351d270ac514e23cb69ff1a5fd35229 (diff)
downloademacs-4bd51ad5c3445b644dfb017d5b57b10a90aa325f.tar.gz
emacs-4bd51ad5c3445b644dfb017d5b57b10a90aa325f.zip
merge from upstream. currently seems to have bitroted and i get segfaults
Diffstat (limited to 'src/callproc.c')
-rw-r--r--src/callproc.c110
1 files changed, 46 insertions, 64 deletions
diff --git a/src/callproc.c b/src/callproc.c
index ee0872b5562..09d0ca5b42c 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -1,6 +1,5 @@
1/* Synchronous subprocess invocation for GNU Emacs. 1/* Synchronous subprocess invocation for GNU Emacs.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, 1999, 2000, 2001, 2 Copyright (C) 1985-1988, 1993-1995, 1999-2011
3 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc. 3 Free Software Foundation, Inc.
5 4
6This file is part of GNU Emacs. 5This file is part of GNU Emacs.
@@ -25,10 +24,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
25#include <stdio.h> 24#include <stdio.h>
26#include <setjmp.h> 25#include <setjmp.h>
27#include <sys/types.h> 26#include <sys/types.h>
28
29#ifdef HAVE_UNISTD_H
30#include <unistd.h> 27#include <unistd.h>
31#endif
32 28
33#include <sys/file.h> 29#include <sys/file.h>
34#include <fcntl.h> 30#include <fcntl.h>
@@ -75,17 +71,9 @@ extern char **environ;
75#endif 71#endif
76#endif 72#endif
77 73
78Lisp_Object Vexec_path, Vexec_directory, Vexec_suffixes;
79Lisp_Object Vdata_directory, Vdoc_directory;
80Lisp_Object Vconfigure_info_directory, Vshared_game_score_directory;
81
82/* Pattern used by call-process-region to make temp files. */ 74/* Pattern used by call-process-region to make temp files. */
83static Lisp_Object Vtemp_file_name_pattern; 75static Lisp_Object Vtemp_file_name_pattern;
84 76
85Lisp_Object Vshell_file_name;
86
87Lisp_Object Vprocess_environment, Vinitial_environment;
88
89#ifdef DOS_NT 77#ifdef DOS_NT
90Lisp_Object Qbuffer_file_type; 78Lisp_Object Qbuffer_file_type;
91#endif /* DOS_NT */ 79#endif /* DOS_NT */
@@ -361,7 +349,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
361 349
362 display_p = INTERACTIVE && nargs >= 4 && !NILP (args[3]); 350 display_p = INTERACTIVE && nargs >= 4 && !NILP (args[3]);
363 351
364 filefd = emacs_open (SDATA (infile), O_RDONLY, 0); 352 filefd = emacs_open (SSDATA (infile), O_RDONLY, 0);
365 if (filefd < 0) 353 if (filefd < 0)
366 { 354 {
367 infile = DECODE_FILE (infile); 355 infile = DECODE_FILE (infile);
@@ -477,11 +465,11 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
477 else if (STRINGP (error_file)) 465 else if (STRINGP (error_file))
478 { 466 {
479#ifdef DOS_NT 467#ifdef DOS_NT
480 fd_error = emacs_open (SDATA (error_file), 468 fd_error = emacs_open (SSDATA (error_file),
481 O_WRONLY | O_TRUNC | O_CREAT | O_TEXT, 469 O_WRONLY | O_TRUNC | O_CREAT | O_TEXT,
482 S_IREAD | S_IWRITE); 470 S_IREAD | S_IWRITE);
483#else /* not DOS_NT */ 471#else /* not DOS_NT */
484 fd_error = creat (SDATA (error_file), 0666); 472 fd_error = creat (SSDATA (error_file), 0666);
485#endif /* not DOS_NT */ 473#endif /* not DOS_NT */
486 } 474 }
487 475
@@ -1091,7 +1079,7 @@ child_setup (int in, int out, int err, register char **new_argv, int set_pgrp, L
1091 CONSP (tem) && STRINGP (XCAR (tem)); 1079 CONSP (tem) && STRINGP (XCAR (tem));
1092 tem = XCDR (tem)) 1080 tem = XCDR (tem))
1093 { 1081 {
1094 if (strncmp (SDATA (XCAR (tem)), "DISPLAY", 7) == 0 1082 if (strncmp (SSDATA (XCAR (tem)), "DISPLAY", 7) == 0
1095 && (SDATA (XCAR (tem)) [7] == '\0' 1083 && (SDATA (XCAR (tem)) [7] == '\0'
1096 || SDATA (XCAR (tem)) [7] == '=')) 1084 || SDATA (XCAR (tem)) [7] == '='))
1097 /* DISPLAY is specified in process-environment. */ 1085 /* DISPLAY is specified in process-environment. */
@@ -1123,10 +1111,10 @@ child_setup (int in, int out, int err, register char **new_argv, int set_pgrp, L
1123 1111
1124 if (STRINGP (display)) 1112 if (STRINGP (display))
1125 { 1113 {
1126 int vlen = strlen ("DISPLAY=") + strlen (SDATA (display)) + 1; 1114 int vlen = strlen ("DISPLAY=") + strlen (SSDATA (display)) + 1;
1127 char *vdata = (char *) alloca (vlen); 1115 char *vdata = (char *) alloca (vlen);
1128 strcpy (vdata, "DISPLAY="); 1116 strcpy (vdata, "DISPLAY=");
1129 strcat (vdata, SDATA (display)); 1117 strcat (vdata, SSDATA (display));
1130 new_env = add_env (env, new_env, vdata); 1118 new_env = add_env (env, new_env, vdata);
1131 } 1119 }
1132 1120
@@ -1134,7 +1122,7 @@ child_setup (int in, int out, int err, register char **new_argv, int set_pgrp, L
1134 for (tem = Vprocess_environment; 1122 for (tem = Vprocess_environment;
1135 CONSP (tem) && STRINGP (XCAR (tem)); 1123 CONSP (tem) && STRINGP (XCAR (tem));
1136 tem = XCDR (tem)) 1124 tem = XCDR (tem))
1137 new_env = add_env (env, new_env, SDATA (XCAR (tem))); 1125 new_env = add_env (env, new_env, SSDATA (XCAR (tem)));
1138 1126
1139 *new_env = 0; 1127 *new_env = 0;
1140 1128
@@ -1154,6 +1142,14 @@ child_setup (int in, int out, int err, register char **new_argv, int set_pgrp, L
1154#ifdef WINDOWSNT 1142#ifdef WINDOWSNT
1155 prepare_standard_handles (in, out, err, handles); 1143 prepare_standard_handles (in, out, err, handles);
1156 set_process_dir (SDATA (current_dir)); 1144 set_process_dir (SDATA (current_dir));
1145 /* Spawn the child. (See ntproc.c:Spawnve). */
1146 cpid = spawnve (_P_NOWAIT, new_argv[0], new_argv, env);
1147 reset_standard_handles (in, out, err, handles);
1148 if (cpid == -1)
1149 /* An error occurred while trying to spawn the process. */
1150 report_file_error ("Spawning child process", Qnil);
1151 return cpid;
1152
1157#else /* not WINDOWSNT */ 1153#else /* not WINDOWSNT */
1158 /* Make sure that in, out, and err are not actually already in 1154 /* Make sure that in, out, and err are not actually already in
1159 descriptors zero, one, or two; this could happen if Emacs is 1155 descriptors zero, one, or two; this could happen if Emacs is
@@ -1192,36 +1188,17 @@ child_setup (int in, int out, int err, register char **new_argv, int set_pgrp, L
1192 emacs_close (out); 1188 emacs_close (out);
1193 if (err != in && err != out) 1189 if (err != in && err != out)
1194 emacs_close (err); 1190 emacs_close (err);
1195#endif /* not MSDOS */
1196#endif /* not WINDOWSNT */
1197 1191
1198#if defined(USG) 1192#if defined(USG)
1199#ifndef SETPGRP_RELEASES_CTTY 1193#ifndef SETPGRP_RELEASES_CTTY
1200 setpgrp (); /* No arguments but equivalent in this case */ 1194 setpgrp (); /* No arguments but equivalent in this case */
1201#endif 1195#endif
1202#else 1196#else /* not USG */
1203 setpgrp (pid, pid); 1197 setpgrp (pid, pid);
1204#endif /* USG */ 1198#endif /* not USG */
1205 1199
1206#ifdef MSDOS
1207 pid = run_msdos_command (new_argv, pwd_var + 4, in, out, err, env);
1208 xfree (pwd_var);
1209 if (pid == -1)
1210 /* An error occurred while trying to run the subprocess. */
1211 report_file_error ("Spawning child process", Qnil);
1212 return pid;
1213#else /* not MSDOS */
1214#ifdef WINDOWSNT
1215 /* Spawn the child. (See ntproc.c:Spawnve). */
1216 cpid = spawnve (_P_NOWAIT, new_argv[0], new_argv, env);
1217 reset_standard_handles (in, out, err, handles);
1218 if (cpid == -1)
1219 /* An error occurred while trying to spawn the process. */
1220 report_file_error ("Spawning child process", Qnil);
1221 return cpid;
1222#else /* not WINDOWSNT */
1223 /* setpgrp_of_tty is incorrect here; it uses input_fd. */ 1200 /* setpgrp_of_tty is incorrect here; it uses input_fd. */
1224 EMACS_SET_TTY_PGRP (0, &pid); 1201 tcsetpgrp (0, pid);
1225 1202
1226 /* execvp does not accept an environment arg so the only way 1203 /* execvp does not accept an environment arg so the only way
1227 to pass this environment is to set environ. Our caller 1204 to pass this environment is to set environ. Our caller
@@ -1233,8 +1210,16 @@ child_setup (int in, int out, int err, register char **new_argv, int set_pgrp, L
1233 emacs_write (1, new_argv[0], strlen (new_argv[0])); 1210 emacs_write (1, new_argv[0], strlen (new_argv[0]));
1234 emacs_write (1, "\n", 1); 1211 emacs_write (1, "\n", 1);
1235 _exit (1); 1212 _exit (1);
1236#endif /* not WINDOWSNT */ 1213
1237#endif /* not MSDOS */ 1214#else /* MSDOS */
1215 pid = run_msdos_command (new_argv, pwd_var + 4, in, out, err, env);
1216 xfree (pwd_var);
1217 if (pid == -1)
1218 /* An error occurred while trying to run the subprocess. */
1219 report_file_error ("Spawning child process", Qnil);
1220 return pid;
1221#endif /* MSDOS */
1222#endif /* not WINDOWSNT */
1238} 1223}
1239 1224
1240#ifndef WINDOWSNT 1225#ifndef WINDOWSNT
@@ -1292,7 +1277,7 @@ getenv_internal_1 (const char *var, int varlen, char **value, int *valuelen,
1292 { 1277 {
1293 if (SBYTES (entry) > varlen && SREF (entry, varlen) == '=') 1278 if (SBYTES (entry) > varlen && SREF (entry, varlen) == '=')
1294 { 1279 {
1295 *value = (char *) SDATA (entry) + (varlen + 1); 1280 *value = SSDATA (entry) + (varlen + 1);
1296 *valuelen = SBYTES (entry) - (varlen + 1); 1281 *valuelen = SBYTES (entry) - (varlen + 1);
1297 return 1; 1282 return 1;
1298 } 1283 }
@@ -1324,7 +1309,7 @@ getenv_internal (const char *var, int varlen, char **value, int *valuelen,
1324 = Fframe_parameter (NILP (frame) ? selected_frame : frame, Qdisplay); 1309 = Fframe_parameter (NILP (frame) ? selected_frame : frame, Qdisplay);
1325 if (STRINGP (display)) 1310 if (STRINGP (display))
1326 { 1311 {
1327 *value = (char *) SDATA (display); 1312 *value = SSDATA (display);
1328 *valuelen = SBYTES (display); 1313 *valuelen = SBYTES (display);
1329 return 1; 1314 return 1;
1330 } 1315 }
@@ -1355,13 +1340,13 @@ If optional parameter ENV is a list, then search this list instead of
1355 CHECK_STRING (variable); 1340 CHECK_STRING (variable);
1356 if (CONSP (env)) 1341 if (CONSP (env))
1357 { 1342 {
1358 if (getenv_internal_1 (SDATA (variable), SBYTES (variable), 1343 if (getenv_internal_1 (SSDATA (variable), SBYTES (variable),
1359 &value, &valuelen, env)) 1344 &value, &valuelen, env))
1360 return value ? make_string (value, valuelen) : Qt; 1345 return value ? make_string (value, valuelen) : Qt;
1361 else 1346 else
1362 return Qnil; 1347 return Qnil;
1363 } 1348 }
1364 else if (getenv_internal (SDATA (variable), SBYTES (variable), 1349 else if (getenv_internal (SSDATA (variable), SBYTES (variable),
1365 &value, &valuelen, env)) 1350 &value, &valuelen, env))
1366 return make_string (value, valuelen); 1351 return make_string (value, valuelen);
1367 else 1352 else
@@ -1474,13 +1459,13 @@ init_callproc (void)
1474#endif 1459#endif
1475 { 1460 {
1476 tempdir = Fdirectory_file_name (Vexec_directory); 1461 tempdir = Fdirectory_file_name (Vexec_directory);
1477 if (access (SDATA (tempdir), 0) < 0) 1462 if (access (SSDATA (tempdir), 0) < 0)
1478 dir_warning ("Warning: arch-dependent data dir (%s) does not exist.\n", 1463 dir_warning ("Warning: arch-dependent data dir (%s) does not exist.\n",
1479 Vexec_directory); 1464 Vexec_directory);
1480 } 1465 }
1481 1466
1482 tempdir = Fdirectory_file_name (Vdata_directory); 1467 tempdir = Fdirectory_file_name (Vdata_directory);
1483 if (access (SDATA (tempdir), 0) < 0) 1468 if (access (SSDATA (tempdir), 0) < 0)
1484 dir_warning ("Warning: arch-independent data dir (%s) does not exist.\n", 1469 dir_warning ("Warning: arch-independent data dir (%s) does not exist.\n",
1485 Vdata_directory); 1470 Vdata_directory);
1486 1471
@@ -1519,7 +1504,7 @@ void
1519syms_of_callproc (void) 1504syms_of_callproc (void)
1520{ 1505{
1521#ifdef DOS_NT 1506#ifdef DOS_NT
1522 Qbuffer_file_type = intern ("buffer-file-type"); 1507 Qbuffer_file_type = intern_c_string ("buffer-file-type");
1523 staticpro (&Qbuffer_file_type); 1508 staticpro (&Qbuffer_file_type);
1524#endif /* DOS_NT */ 1509#endif /* DOS_NT */
1525 1510
@@ -1532,41 +1517,41 @@ syms_of_callproc (void)
1532#endif 1517#endif
1533 staticpro (&Vtemp_file_name_pattern); 1518 staticpro (&Vtemp_file_name_pattern);
1534 1519
1535 DEFVAR_LISP ("shell-file-name", &Vshell_file_name, 1520 DEFVAR_LISP ("shell-file-name", Vshell_file_name,
1536 doc: /* *File name to load inferior shells from. 1521 doc: /* *File name to load inferior shells from.
1537Initialized from the SHELL environment variable, or to a system-dependent 1522Initialized from the SHELL environment variable, or to a system-dependent
1538default if SHELL is not set. */); 1523default if SHELL is not set. */);
1539 1524
1540 DEFVAR_LISP ("exec-path", &Vexec_path, 1525 DEFVAR_LISP ("exec-path", Vexec_path,
1541 doc: /* *List of directories to search programs to run in subprocesses. 1526 doc: /* *List of directories to search programs to run in subprocesses.
1542Each element is a string (directory name) or nil (try default directory). */); 1527Each element is a string (directory name) or nil (try default directory). */);
1543 1528
1544 DEFVAR_LISP ("exec-suffixes", &Vexec_suffixes, 1529 DEFVAR_LISP ("exec-suffixes", Vexec_suffixes,
1545 doc: /* *List of suffixes to try to find executable file names. 1530 doc: /* *List of suffixes to try to find executable file names.
1546Each element is a string. */); 1531Each element is a string. */);
1547 Vexec_suffixes = Qnil; 1532 Vexec_suffixes = Qnil;
1548 1533
1549 DEFVAR_LISP ("exec-directory", &Vexec_directory, 1534 DEFVAR_LISP ("exec-directory", Vexec_directory,
1550 doc: /* Directory for executables for Emacs to invoke. 1535 doc: /* Directory for executables for Emacs to invoke.
1551More generally, this includes any architecture-dependent files 1536More generally, this includes any architecture-dependent files
1552that are built and installed from the Emacs distribution. */); 1537that are built and installed from the Emacs distribution. */);
1553 1538
1554 DEFVAR_LISP ("data-directory", &Vdata_directory, 1539 DEFVAR_LISP ("data-directory", Vdata_directory,
1555 doc: /* Directory of machine-independent files that come with GNU Emacs. 1540 doc: /* Directory of machine-independent files that come with GNU Emacs.
1556These are files intended for Emacs to use while it runs. */); 1541These are files intended for Emacs to use while it runs. */);
1557 1542
1558 DEFVAR_LISP ("doc-directory", &Vdoc_directory, 1543 DEFVAR_LISP ("doc-directory", Vdoc_directory,
1559 doc: /* Directory containing the DOC file that comes with GNU Emacs. 1544 doc: /* Directory containing the DOC file that comes with GNU Emacs.
1560This is usually the same as `data-directory'. */); 1545This is usually the same as `data-directory'. */);
1561 1546
1562 DEFVAR_LISP ("configure-info-directory", &Vconfigure_info_directory, 1547 DEFVAR_LISP ("configure-info-directory", Vconfigure_info_directory,
1563 doc: /* For internal use by the build procedure only. 1548 doc: /* For internal use by the build procedure only.
1564This is the name of the directory in which the build procedure installed 1549This is the name of the directory in which the build procedure installed
1565Emacs's info files; the default value for `Info-default-directory-list' 1550Emacs's info files; the default value for `Info-default-directory-list'
1566includes this. */); 1551includes this. */);
1567 Vconfigure_info_directory = build_string (PATH_INFO); 1552 Vconfigure_info_directory = build_string (PATH_INFO);
1568 1553
1569 DEFVAR_LISP ("shared-game-score-directory", &Vshared_game_score_directory, 1554 DEFVAR_LISP ("shared-game-score-directory", Vshared_game_score_directory,
1570 doc: /* Directory of score files for games which come with GNU Emacs. 1555 doc: /* Directory of score files for games which come with GNU Emacs.
1571If this variable is nil, then Emacs is unable to use a shared directory. */); 1556If this variable is nil, then Emacs is unable to use a shared directory. */);
1572#ifdef DOS_NT 1557#ifdef DOS_NT
@@ -1575,13 +1560,13 @@ If this variable is nil, then Emacs is unable to use a shared directory. */);
1575 Vshared_game_score_directory = build_string (PATH_GAME); 1560 Vshared_game_score_directory = build_string (PATH_GAME);
1576#endif 1561#endif
1577 1562
1578 DEFVAR_LISP ("initial-environment", &Vinitial_environment, 1563 DEFVAR_LISP ("initial-environment", Vinitial_environment,
1579 doc: /* List of environment variables inherited from the parent process. 1564 doc: /* List of environment variables inherited from the parent process.
1580Each element should be a string of the form ENVVARNAME=VALUE. 1565Each element should be a string of the form ENVVARNAME=VALUE.
1581The elements must normally be decoded (using `locale-coding-system') for use. */); 1566The elements must normally be decoded (using `locale-coding-system') for use. */);
1582 Vinitial_environment = Qnil; 1567 Vinitial_environment = Qnil;
1583 1568
1584 DEFVAR_LISP ("process-environment", &Vprocess_environment, 1569 DEFVAR_LISP ("process-environment", Vprocess_environment,
1585 doc: /* List of overridden environment variables for subprocesses to inherit. 1570 doc: /* List of overridden environment variables for subprocesses to inherit.
1586Each element should be a string of the form ENVVARNAME=VALUE. 1571Each element should be a string of the form ENVVARNAME=VALUE.
1587 1572
@@ -1608,6 +1593,3 @@ See `setenv' and `getenv'. */);
1608 defsubr (&Sgetenv_internal); 1593 defsubr (&Sgetenv_internal);
1609 defsubr (&Scall_process_region); 1594 defsubr (&Scall_process_region);
1610} 1595}
1611
1612/* arch-tag: 769b8045-1df7-4d2b-8968-e3fb49017f95
1613 (do not change this comment) */