| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
#include <config.h> |
|---|
| 25 |
#include <signal.h> |
|---|
| 26 |
#include <errno.h> |
|---|
| 27 |
#include <stdio.h> |
|---|
| 28 |
|
|---|
| 29 |
#ifndef USE_CRT_DLL |
|---|
| 30 |
extern int errno; |
|---|
| 31 |
#endif |
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
#if !defined (SIGCHLD) && defined (SIGCLD) |
|---|
| 36 |
#define SIGCHLD SIGCLD |
|---|
| 37 |
#endif |
|---|
| 38 |
|
|---|
| 39 |
#include <sys/types.h> |
|---|
| 40 |
|
|---|
| 41 |
#ifdef HAVE_UNISTD_H |
|---|
| 42 |
#include <unistd.h> |
|---|
| 43 |
#endif |
|---|
| 44 |
|
|---|
| 45 |
#include <sys/file.h> |
|---|
| 46 |
#ifdef HAVE_FCNTL_H |
|---|
| 47 |
#define INCLUDED_FCNTL |
|---|
| 48 |
#include <fcntl.h> |
|---|
| 49 |
#endif |
|---|
| 50 |
|
|---|
| 51 |
#ifdef WINDOWSNT |
|---|
| 52 |
#define NOMINMAX |
|---|
| 53 |
#include <windows.h> |
|---|
| 54 |
#include <stdlib.h> |
|---|
| 55 |
#include <fcntl.h> |
|---|
| 56 |
#include "w32.h" |
|---|
| 57 |
#define _P_NOWAIT 1 |
|---|
| 58 |
#endif |
|---|
| 59 |
|
|---|
| 60 |
#ifdef MSDOS |
|---|
| 61 |
#define INCLUDED_FCNTL |
|---|
| 62 |
#include <fcntl.h> |
|---|
| 63 |
#include <sys/stat.h> |
|---|
| 64 |
#include <sys/param.h> |
|---|
| 65 |
#include <errno.h> |
|---|
| 66 |
#endif |
|---|
| 67 |
|
|---|
| 68 |
#ifndef O_RDONLY |
|---|
| 69 |
#define O_RDONLY 0 |
|---|
| 70 |
#endif |
|---|
| 71 |
|
|---|
| 72 |
#ifndef O_WRONLY |
|---|
| 73 |
#define O_WRONLY 1 |
|---|
| 74 |
#endif |
|---|
| 75 |
|
|---|
| 76 |
#include "lisp.h" |
|---|
| 77 |
#include "commands.h" |
|---|
| 78 |
#include "buffer.h" |
|---|
| 79 |
#include "charset.h" |
|---|
| 80 |
#include "ccl.h" |
|---|
| 81 |
#include "coding.h" |
|---|
| 82 |
#include "composite.h" |
|---|
| 83 |
#include <epaths.h> |
|---|
| 84 |
#include "process.h" |
|---|
| 85 |
#include "syssignal.h" |
|---|
| 86 |
#include "systty.h" |
|---|
| 87 |
#include "blockinput.h" |
|---|
| 88 |
|
|---|
| 89 |
#ifdef MSDOS |
|---|
| 90 |
#include "msdos.h" |
|---|
| 91 |
#endif |
|---|
| 92 |
|
|---|
| 93 |
#ifdef VMS |
|---|
| 94 |
extern noshare char **environ; |
|---|
| 95 |
#else |
|---|
| 96 |
#ifndef USE_CRT_DLL |
|---|
| 97 |
extern char **environ; |
|---|
| 98 |
#endif |
|---|
| 99 |
#endif |
|---|
| 100 |
|
|---|
| 101 |
#ifdef HAVE_SETPGID |
|---|
| 102 |
#if !defined (USG) || defined (BSD_PGRPS) |
|---|
| 103 |
#undef setpgrp |
|---|
| 104 |
#define setpgrp setpgid |
|---|
| 105 |
#endif |
|---|
| 106 |
#endif |
|---|
| 107 |
|
|---|
| 108 |
Lisp_Object Vexec_path, Vexec_directory, Vexec_suffixes; |
|---|
| 109 |
Lisp_Object Vdata_directory, Vdoc_directory; |
|---|
| 110 |
Lisp_Object Vconfigure_info_directory, Vshared_game_score_directory; |
|---|
| 111 |
Lisp_Object Vtemp_file_name_pattern; |
|---|
| 112 |
|
|---|
| 113 |
Lisp_Object Vshell_file_name; |
|---|
| 114 |
|
|---|
| 115 |
Lisp_Object Vprocess_environment; |
|---|
| 116 |
|
|---|
| 117 |
#ifdef MEADOW |
|---|
| 118 |
int mw32_process_expects_pty; |
|---|
| 119 |
Lisp_Object Vmw32_process_under_setup; |
|---|
| 120 |
#endif |
|---|
| 121 |
|
|---|
| 122 |
#ifdef DOS_NT |
|---|
| 123 |
Lisp_Object Qbuffer_file_type; |
|---|
| 124 |
#endif |
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
int synch_process_alive; |
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
char *synch_process_death; |
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
int synch_process_termsig; |
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
int synch_process_retcode; |
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
static int call_process_exited; |
|---|
| 146 |
|
|---|
| 147 |
#ifndef VMS |
|---|
| 148 |
|
|---|
| 149 |
static Lisp_Object |
|---|
| 150 |
call_process_kill (fdpid) |
|---|
| 151 |
Lisp_Object fdpid; |
|---|
| 152 |
{ |
|---|
| 153 |
emacs_close (XFASTINT (Fcar (fdpid))); |
|---|
| 154 |
EMACS_KILLPG (XFASTINT (Fcdr (fdpid)), SIGKILL); |
|---|
| 155 |
synch_process_alive = 0; |
|---|
| 156 |
return Qnil; |
|---|
| 157 |
} |
|---|
| 158 |
|
|---|
| 159 |
Lisp_Object |
|---|
| 160 |
call_process_cleanup (fdpid) |
|---|
| 161 |
Lisp_Object fdpid; |
|---|
| 162 |
{ |
|---|
| 163 |
#if defined (MSDOS) || defined (MAC_OS8) |
|---|
| 164 |
|
|---|
| 165 |
register Lisp_Object file; |
|---|
| 166 |
file = Fcdr (fdpid); |
|---|
| 167 |
emacs_close (XFASTINT (Fcar (fdpid))); |
|---|
| 168 |
if (strcmp (SDATA (file), NULL_DEVICE) != 0) |
|---|
| 169 |
unlink (SDATA (file)); |
|---|
| 170 |
#else |
|---|
| 171 |
register int pid = XFASTINT (Fcdr (fdpid)); |
|---|
| 172 |
|
|---|
| 173 |
if (call_process_exited) |
|---|
| 174 |
{ |
|---|
| 175 |
emacs_close (XFASTINT (Fcar (fdpid))); |
|---|
| 176 |
return Qnil; |
|---|
| 177 |
} |
|---|
| 178 |
|
|---|
| 179 |
if (EMACS_KILLPG (pid, SIGINT) == 0) |
|---|
| 180 |
{ |
|---|
| 181 |
int count = SPECPDL_INDEX (); |
|---|
| 182 |
record_unwind_protect (call_process_kill, fdpid); |
|---|
| 183 |
message1 ("Waiting for process to die...(type C-g again to kill it instantly)"); |
|---|
| 184 |
immediate_quit = 1; |
|---|
| 185 |
QUIT; |
|---|
| 186 |
wait_for_termination (pid); |
|---|
| 187 |
immediate_quit = 0; |
|---|
| 188 |
specpdl_ptr = specpdl + count; |
|---|
| 189 |
message1 ("Waiting for process to die...done"); |
|---|
| 190 |
} |
|---|
| 191 |
synch_process_alive = 0; |
|---|
| 192 |
emacs_close (XFASTINT (Fcar (fdpid))); |
|---|
| 193 |
#endif |
|---|
| 194 |
return Qnil; |
|---|
| 195 |
} |
|---|
| 196 |
|
|---|
| 197 |
DEFUN ("call-process", Fcall_process, Scall_process, 1, MANY, 0, |
|---|
| 198 |
doc: |
|---|
| 199 |
The remaining arguments are optional. |
|---|
| 200 |
The program's input comes from file INFILE (nil means `/dev/null'). |
|---|
| 201 |
Insert output in BUFFER before point; t means current buffer; |
|---|
| 202 |
nil for BUFFER means discard it; 0 means discard and don't wait. |
|---|
| 203 |
BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case, |
|---|
| 204 |
REAL-BUFFER says what to do with standard output, as above, |
|---|
| 205 |
while STDERR-FILE says what to do with standard error in the child. |
|---|
| 206 |
STDERR-FILE may be nil (discard standard error output), |
|---|
| 207 |
t (mix it with ordinary output), or a file name string. |
|---|
| 208 |
|
|---|
| 209 |
Fourth arg DISPLAY non-nil means redisplay buffer as output is inserted. |
|---|
| 210 |
Remaining arguments are strings passed as command arguments to PROGRAM. |
|---|
| 211 |
|
|---|
| 212 |
If executable PROGRAM can't be found as an executable, `call-process' |
|---|
| 213 |
signals a Lisp error. `call-process' reports errors in execution of |
|---|
| 214 |
the program only through its return and output. |
|---|
| 215 |
|
|---|
| 216 |
If BUFFER is 0, `call-process' returns immediately with value nil. |
|---|
| 217 |
Otherwise it waits for PROGRAM to terminate |
|---|
| 218 |
and returns a numeric exit status or a signal description string. |
|---|
| 219 |
If you quit, the process is killed with SIGINT, or SIGKILL if you quit again. |
|---|
| 220 |
|
|---|
| 221 |
usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */) |
|---|
| 222 |
(nargs, args) |
|---|
| 223 |
int nargs; |
|---|
| 224 |
register Lisp_Object *args; |
|---|
| 225 |
{ |
|---|
| 226 |
Lisp_Object infile, buffer, current_dir, path; |
|---|
| 227 |
int display_p; |
|---|
| 228 |
int fd[2]; |
|---|
| 229 |
int filefd; |
|---|
| 230 |
register int pid; |
|---|
| 231 |
#define CALLPROC_BUFFER_SIZE_MIN (16 * 1024) |
|---|
| 232 |
#define CALLPROC_BUFFER_SIZE_MAX (4 * CALLPROC_BUFFER_SIZE_MIN) |
|---|
| 233 |
char buf[CALLPROC_BUFFER_SIZE_MAX]; |
|---|
| 234 |
int bufsize = CALLPROC_BUFFER_SIZE_MIN; |
|---|
| 235 |
int count = SPECPDL_INDEX (); |
|---|
| 236 |
|
|---|
| 237 |
register const unsigned char **new_argv |
|---|
| 238 |
= (const unsigned char **) alloca ((max (2, nargs - 2)) * sizeof (char *)); |
|---|
| 239 |
struct buffer *old = current_buffer; |
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 |
Lisp_Object error_file; |
|---|
| 243 |
#ifdef MSDOS |
|---|
| 244 |
char *outf, *tempfile; |
|---|
| 245 |
int outfilefd; |
|---|
| 246 |
#endif |
|---|
| 247 |
#ifdef MAC_OS8 |
|---|
| 248 |
char *tempfile; |
|---|
| 249 |
int outfilefd; |
|---|
| 250 |
#endif |
|---|
| 251 |
#if 0 |
|---|
| 252 |
int mask; |
|---|
| 253 |
#endif |
|---|
| 254 |
struct coding_system process_coding; |
|---|
| 255 |
struct coding_system argument_coding; |
|---|
| 256 |
|
|---|
| 257 |
Lisp_Object coding_systems; |
|---|
| 258 |
|
|---|
| 259 |
|
|---|
| 260 |
coding_systems = Qt; |
|---|
| 261 |
|
|---|
| 262 |
CHECK_STRING (args[0]); |
|---|
| 263 |
|
|---|
| 264 |
error_file = Qt; |
|---|
| 265 |
|
|---|
| 266 |
#ifndef subprocesses |
|---|
| 267 |
|
|---|
| 268 |
if (nargs >= 3 |
|---|
| 269 |
&& (INTEGERP (CONSP (args[2]) ? XCAR (args[2]) : args[2]))) |
|---|
| 270 |
error ("Operating system cannot handle asynchronous subprocesses"); |
|---|
| 271 |
#endif |
|---|
| 272 |
|
|---|
| 273 |
|
|---|
| 274 |
{ |
|---|
| 275 |
Lisp_Object val, *args2; |
|---|
| 276 |
int i; |
|---|
| 277 |
|
|---|
| 278 |
|
|---|
| 279 |
if (nargs >= 5) |
|---|
| 280 |
{ |
|---|
| 281 |
int must_encode = 0; |
|---|
| 282 |
|
|---|
| 283 |
for (i = 4; i < nargs; i++) |
|---|
| 284 |
CHECK_STRING (args[i]); |
|---|
| 285 |
|
|---|
| 286 |
for (i = 4; i < nargs; i++) |
|---|
| 287 |
if (STRING_MULTIBYTE (args[i])) |
|---|
| 288 |
must_encode = 1; |
|---|
| 289 |
|
|---|
| 290 |
if (!NILP (Vcoding_system_for_write)) |
|---|
| 291 |
val = Vcoding_system_for_write; |
|---|
| 292 |
else if (! must_encode) |
|---|
| 293 |
val = Qnil; |
|---|
| 294 |
else |
|---|
| 295 |
{ |
|---|
| 296 |
args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2); |
|---|
| 297 |
args2[0] = Qcall_process; |
|---|
| 298 |
for (i = 0; i < nargs; i++) args2[i + 1] = args[i]; |
|---|
| 299 |
coding_systems = Ffind_operation_coding_system (nargs + 1, args2); |
|---|
| 300 |
if (CONSP (coding_systems)) |
|---|
| 301 |
val = XCDR (coding_systems); |
|---|
| 302 |
else if (CONSP (Vdefault_process_coding_system)) |
|---|
| 303 |
val = XCDR (Vdefault_process_coding_system); |
|---|
| 304 |
else |
|---|
| 305 |
val = Qnil; |
|---|
| 306 |
} |
|---|
| 307 |
setup_coding_system (Fcheck_coding_system (val), &argument_coding); |
|---|
| 308 |
if (argument_coding.common_flags & CODING_ASCII_INCOMPATIBLE_MASK) |
|---|
| 309 |
setup_coding_system (Qraw_text, &argument_coding); |
|---|
| 310 |
if (argument_coding.eol_type == CODING_EOL_UNDECIDED) |
|---|
| 311 |
argument_coding.eol_type = system_eol_type; |
|---|
| 312 |
} |
|---|
| 313 |
} |
|---|
| 314 |
|
|---|
| 315 |
if (nargs >= 2 && ! NILP (args[1])) |
|---|
| 316 |
{ |
|---|
| 317 |
infile = Fexpand_file_name (args[1], current_buffer->directory); |
|---|
| 318 |
CHECK_STRING (infile); |
|---|
| 319 |
} |
|---|
| 320 |
else |
|---|
| 321 |
infile = build_string (NULL_DEVICE); |
|---|
| 322 |
|
|---|
| 323 |
if (nargs >= 3) |
|---|
| 324 |
{ |
|---|
| 325 |
buffer = args[2]; |
|---|
| 326 |
|
|---|
| 327 |
|
|---|
| 328 |
|
|---|
| 329 |
if (CONSP (buffer)) |
|---|
| 330 |
{ |
|---|
| 331 |
if (CONSP (XCDR (buffer))) |
|---|
| 332 |
{ |
|---|
| 333 |
Lisp_Object stderr_file; |
|---|
| 334 |
stderr_file = XCAR (XCDR (buffer)); |
|---|
| 335 |
|
|---|
| 336 |
if (NILP (stderr_file) || EQ (Qt, stderr_file)) |
|---|
| 337 |
error_file = stderr_file; |
|---|
| 338 |
else |
|---|
| 339 |
error_file = Fexpand_file_name (stderr_file, Qnil); |
|---|
| 340 |
} |
|---|
| 341 |
|
|---|
| 342 |
buffer = XCAR (buffer); |
|---|
| 343 |
} |
|---|
| 344 |
|
|---|
| 345 |
if (!(EQ (buffer, Qnil) |
|---|
| 346 |
|| EQ (buffer, Qt) |
|---|
| 347 |
|| INTEGERP (buffer))) |
|---|
| 348 |
{ |
|---|
| 349 |
Lisp_Object spec_buffer; |
|---|
| 350 |
spec_buffer = buffer; |
|---|
| 351 |
buffer = Fget_buffer_create (buffer); |
|---|
| 352 |
|
|---|
| 353 |
if (NILP (buffer)) |
|---|
| 354 |
CHECK_BUFFER (spec_buffer); |
|---|
| 355 |
CHECK_BUFFER (buffer); |
|---|
| 356 |
} |
|---|
| 357 |
} |
|---|
| 358 |
else |
|---|
| 359 |
buffer = Qnil; |
|---|
| 360 |
|
|---|
| 361 |
|
|---|
| 362 |
|
|---|
| 363 |
|
|---|
| 364 |
|
|---|
| 365 |
|
|---|
| 366 |
|
|---|
| 367 |
|
|---|
| 368 |
|
|---|
| 369 |
|
|---|
| 370 |
|
|---|
| 371 |
{ |
|---|
| 372 |
struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
|---|
| 373 |
|
|---|
| 374 |
current_dir = current_buffer->directory; |
|---|
| 375 |
|
|---|
| 376 |
GCPRO4 (infile, buffer, current_dir, error_file); |
|---|
| 377 |
|
|---|
| 378 |
current_dir |
|---|
| 379 |
= expand_and_dir_to_file (Funhandled_file_name_directory (current_dir), |
|---|
| 380 |
Qnil); |
|---|
| 381 |
if (NILP (Ffile_accessible_directory_p (current_dir))) |
|---|
| 382 |
report_file_error ("Setting current directory", |
|---|
| 383 |
Fcons (current_buffer->directory, Qnil)); |
|---|
| 384 |
|
|---|
| 385 |
if (STRING_MULTIBYTE (infile)) |
|---|
| 386 |
infile = ENCODE_FILE (infile); |
|---|
| 387 |
if (STRING_MULTIBYTE (current_dir)) |
|---|
| 388 |
current_dir = ENCODE_FILE (current_dir); |
|---|
| 389 |
if (STRINGP (error_file) && STRING_MULTIBYTE (error_file)) |
|---|
| 390 |
error_file = ENCODE_FILE (error_file); |
|---|
| 391 |
UNGCPRO; |
|---|
| 392 |
} |
|---|
| 393 |
|
|---|
| 394 |
display_p = INTERACTIVE && nargs >= 4 && !NILP (args[3]); |
|---|
| 395 |
|
|---|
| 396 |
#ifdef MEADOW |
|---|
| 397 |
infile = ENCODE_FILE (infile); |
|---|
| 398 |
#endif |
|---|
| 399 |
filefd = emacs_open (SDATA (infile), O_RDONLY, 0); |
|---|
| 400 |
if (filefd < 0) |
|---|
| 401 |
{ |
|---|
| 402 |
infile = DECODE_FILE (infile); |
|---|
| 403 |
report_file_error ("Opening process input file", Fcons (infile, Qnil)); |
|---|
| 404 |
} |
|---|
| 405 |
|
|---|
| 406 |
{ |
|---|
| 407 |
struct gcpro gcpro1; |
|---|
| 408 |
|
|---|
| 409 |
GCPRO1 (current_dir); |
|---|
| 410 |
#ifndef MEADOW |
|---|
| 411 |
openp (Vexec_path, args[0], Vexec_suffixes, &path, make_number (X_OK)); |
|---|
| 412 |
#else |
|---|
| 413 |
|
|---|
| 414 |
|
|---|
| 415 |
{ |
|---|
| 416 |
int fd = openp (Vexec_path, args[0], Vexec_suffixes, &path, Qnil); |
|---|
| 417 |
if (fd > 0) close(fd); |
|---|
| 418 |
} |
|---|
| 419 |
#endif |
|---|
| 420 |
UNGCPRO; |
|---|
| 421 |
} |
|---|
| 422 |
if (NILP (path)) |
|---|
| 423 |
{ |
|---|
| 424 |
emacs_close (filefd); |
|---|
| 425 |
report_file_error ("Searching for program", Fcons (args[0], Qnil)); |
|---|
| 426 |
} |
|---|
| 427 |
|
|---|
| 428 |
|
|---|
| 429 |
|
|---|
| 430 |
if (SBYTES (path) > 2 && SREF (path, 0) == '/' |
|---|
| 431 |
&& SREF (path, 1) == ':') |
|---|
| 432 |
path = Fsubstring (path, make_number (2), Qnil); |
|---|
| 433 |
|
|---|
| 434 |
#ifdef MEADOW |
|---|
| 435 |
path = ENCODE_FILE (path); |
|---|
| 436 |
#endif |
|---|
| 437 |
new_argv[0] = SDATA (path); |
|---|
| 438 |
if (nargs > 4) |
|---|
| 439 |
{ |
|---|
| 440 |
register int i; |
|---|
| 441 |
struct gcpro gcpro1, gcpro2, gcpro3; |
|---|
| 442 |
|
|---|
| 443 |
GCPRO3 (infile, buffer, current_dir); |
|---|
| 444 |
argument_coding.dst_multibyte = 0; |
|---|
| 445 |
for (i = 4; i < nargs; i++) |
|---|
| 446 |
{ |
|---|
| 447 |
argument_coding.src_multibyte = STRING_MULTIBYTE (args[i]); |
|---|
| 448 |
if (CODING_REQUIRE_ENCODING (&argument_coding)) |
|---|
| 449 |
{ |
|---|
| 450 |
|
|---|
| 451 |
args[i] = encode_coding_string (args[i], &argument_coding, 1); |
|---|
| 452 |
if (argument_coding.type == coding_type_ccl) |
|---|
| 453 |
setup_ccl_program (&(argument_coding.spec.ccl.encoder), Qnil); |
|---|
| 454 |
} |
|---|
| 455 |
new_argv[i - 3] = SDATA (args[i]); |
|---|
| 456 |
} |
|---|
| 457 |
UNGCPRO; |
|---|
| 458 |
new_argv[nargs - 3] = 0; |
|---|
| 459 |
} |
|---|
| 460 |
else |
|---|
| 461 |
new_argv[1] = 0; |
|---|
| 462 |
|
|---|
| 463 |
#ifdef MSDOS |
|---|
| 464 |
if ((outf = egetenv ("TMPDIR"))) |
|---|
| 465 |
strcpy (tempfile = alloca (strlen (outf) + 20), outf); |
|---|
| 466 |
else |
|---|
| 467 |
{ |
|---|
| 468 |
tempfile = alloca (20); |
|---|
| 469 |
*tempfile = '\0'; |
|---|
| 470 |
} |
|---|
| 471 |
dostounix_filename (tempfile); |
|---|
| 472 |
if (*tempfile == '\0' || tempfile[strlen (tempfile) - 1] != '/') |
|---|
| 473 |
strcat (tempfile, "/"); |
|---|
| 474 |
strcat (tempfile, "detmp.XXX"); |
|---|
| 475 |
mktemp (tempfile); |
|---|
| 476 |
|
|---|
| 477 |
outfilefd = creat (tempfile, S_IREAD | S_IWRITE); |
|---|
| 478 |
if (outfilefd < 0) |
|---|
| 479 |
{ |
|---|
| 480 |
emacs_close (filefd); |
|---|
| 481 |
report_file_error ("Opening process output file", |
|---|
| 482 |
Fcons (build_string (tempfile), Qnil)); |
|---|
| 483 |
} |
|---|
| 484 |
fd[0] = filefd; |
|---|
| 485 |
fd[1] = outfilefd; |
|---|
| 486 |
#endif |
|---|
| 487 |
|
|---|
| 488 |
#ifdef MAC_OS8 |
|---|
| 489 |
|
|---|
| 490 |
|
|---|
| 491 |
tempfile = (char *) alloca (SBYTES (Vtemp_file_name_pattern) + 1); |
|---|
| 492 |
bcopy (SDATA (Vtemp_file_name_pattern), tempfile, |
|---|
| 493 |
SBYTES (Vtemp_file_name_pattern) + 1); |
|---|
| 494 |
|
|---|
| 495 |
mktemp (tempfile); |
|---|
| 496 |
|
|---|
| 497 |
outfilefd = creat (tempfile, S_IREAD | S_IWRITE); |
|---|
| 498 |
if (outfilefd < 0) |
|---|
| 499 |
{ |
|---|
| 500 |
close (filefd); |
|---|
| 501 |
report_file_error ("Opening process output file", |
|---|
| 502 |
Fcons (build_string (tempfile), Qnil)); |
|---|
| 503 |
} |
|---|
| 504 |
fd[0] = filefd; |
|---|
| 505 |
fd[1] = outfilefd; |
|---|
| 506 |
#endif |
|---|
| 507 |
|
|---|
| 508 |
if (INTEGERP (buffer)) |
|---|
| 509 |
fd[1] = emacs_open (NULL_DEVICE, O_WRONLY, 0), fd[0] = -1; |
|---|
| 510 |
else |
|---|
| 511 |
{ |
|---|
| 512 |
#ifndef MSDOS |
|---|
| 513 |
#ifndef MAC_OS8 |
|---|
| 514 |
errno = 0; |
|---|
| 515 |
if (pipe (fd) == -1) |
|---|
| 516 |
{ |
|---|
| 517 |
emacs_close (filefd); |
|---|
| 518 |
report_file_error ("Creating process pipe", Qnil); |
|---|
| 519 |
} |
|---|
| 520 |
#endif |
|---|
| 521 |
#endif |
|---|
| 522 |
#if 0 |
|---|
| 523 |
|
|---|
| 524 |
set_exclusive_use (fd[0]); |
|---|
| 525 |
#endif |
|---|
| 526 |
} |
|---|
| 527 |
|
|---|
| 528 |
{ |
|---|
| 529 |
|
|---|
| 530 |
|
|---|
| 531 |
register char **save_environ = environ; |
|---|
| 532 |
register int fd1 = fd[1]; |
|---|
| 533 |
int fd_error = fd1; |
|---|
| 534 |
|
|---|
| 535 |
#if 0 |
|---|
| 536 |
mask = sigblock (sigmask (SIGCHLD)); |
|---|
| 537 |
#endif |
|---|
| 538 |
|
|---|
| 539 |
|
|---|
| 540 |
synch_process_alive = 1; |
|---|
| 541 |
|
|---|
| 542 |
|
|---|
| 543 |
|
|---|
| 544 |
|
|---|
| 545 |
synch_process_death = 0; |
|---|
| 546 |
synch_process_retcode = 0; |
|---|
| 547 |
synch_process_termsig = 0; |
|---|
| 548 |
|
|---|
| 549 |
if (NILP (error_file)) |
|---|
| 550 |
fd_error = emacs_open (NULL_DEVICE, O_WRONLY, 0); |
|---|
| 551 |
else if (STRINGP (error_file)) |
|---|
| 552 |
{ |
|---|
| 553 |
#ifdef DOS_NT |
|---|
| 554 |
#ifdef MEADOW |
|---|
| 555 |
error_file = ENCODE_FILE (error_file); |
|---|
| 556 |
#endif |
|---|
| 557 |
fd_error = emacs_open (SDATA (error_file), |
|---|
| 558 |
O_WRONLY | O_TRUNC | O_CREAT | O_TEXT, |
|---|
| 559 |
S_IREAD | S_IWRITE); |
|---|
| 560 |
#else |
|---|
| 561 |
fd_error = creat (SDATA (error_file), 0666); |
|---|
| 562 |
#endif |
|---|
| 563 |
} |
|---|
| 564 |
|
|---|
| 565 |
if (fd_error < 0) |
|---|
| 566 |
{ |
|---|
| 567 |
emacs_close (filefd); |
|---|
| 568 |
if (fd[0] != filefd) |
|---|
| 569 |
emacs_close (fd[0]); |
|---|
| 570 |
if (fd1 >= 0) |
|---|
| 571 |
emacs_close (fd1); |
|---|
| 572 |
#ifdef MSDOS |
|---|
| 573 |
unlink (tempfile); |
|---|
| 574 |
#endif |
|---|
| 575 |
if (NILP (error_file)) |
|---|
| 576 |
error_file = build_string (NULL_DEVICE); |
|---|
| 577 |
else if (STRINGP (error_file)) |
|---|
| 578 |
error_file = DECODE_FILE (error_file); |
|---|
| 579 |
report_file_error ("Cannot redirect stderr", Fcons (error_file, Qnil)); |
|---|
| 580 |
} |
|---|
| 581 |
|
|---|
| 582 |
#ifdef MAC_OS8 |
|---|
| 583 |
{ |
|---|
| 584 |
|
|---|
| 585 |
|
|---|
| 586 |
|
|---|
| 587 |
|
|---|
| 588 |
char *infn, *outfn, *errfn, *currdn; |
|---|
| 589 |
|
|---|
| 590 |
|
|---|
| 591 |
close (outfilefd); |
|---|
| 592 |
if (fd_error != outfilefd) |
|---|
| 593 |
close (fd_error); |
|---|
| 594 |
fd1 = -1; |
|---|
| 595 |
|
|---|
| 596 |
infn = SDATA (infile); |
|---|
| 597 |
outfn = tempfile; |
|---|
| 598 |
if (NILP (error_file)) |
|---|
| 599 |
errfn = NULL_DEVICE; |
|---|
| 600 |
else if (EQ (Qt, error_file)) |
|---|
| 601 |
errfn = outfn; |
|---|
| 602 |
else |
|---|
| 603 |
errfn = |
|---|