From: Eli Zaretskii Date: Sat, 7 May 2011 11:25:05 +0000 (+0300) Subject: Fix changes in 2011-05-01T00:04:17Z!larsi@gnus.org for MS-DOS. X-Git-Tag: emacs-pretest-24.0.90~104^2~275^2~72^2 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=888c9e865f8c9faea62621519da7e42ba1b7adbf;p=emacs.git Fix changes in 2011-05-01T00:04:17Z!larsi@gnus.org for MS-DOS. src/callproc.c (call_process_cleanup): Don't close and unlink the temporary file if Fcall_process didn't create it in the first place. (Fcall_process): Don't create tempfile if stdout of the child process will be redirected to a file specified with `:file'. Don't try to re-open tempfile in that case, and set fd[0] to -1 as cue to call_process_cleanup not to close that handle. --- diff --git a/src/ChangeLog b/src/ChangeLog index 199c270a018..394b7a172f5 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2011-05-07 Eli Zaretskii + + * callproc.c (call_process_cleanup): Don't close and unlink the + temporary file if Fcall_process didn't create it in the first + place. + (Fcall_process): Don't create tempfile if stdout of the child + process will be redirected to a file specified with `:file'. + Don't try to re-open tempfile in that case, and set fd[0] to -1 as + cue to call_process_cleanup not to close that handle. + 2011-05-07 Ben Key * makefile.w32-in: The bootstrap-temacs rule now makes use of diff --git a/src/callproc.c b/src/callproc.c index 946670320ca..a966a26b938 100644 --- a/src/callproc.c +++ b/src/callproc.c @@ -114,6 +114,7 @@ call_process_cleanup (Lisp_Object arg) Lisp_Object fdpid = Fcdr (arg); #if defined (MSDOS) Lisp_Object file; + int fd; #else int pid; #endif @@ -122,9 +123,13 @@ call_process_cleanup (Lisp_Object arg) #if defined (MSDOS) /* for MSDOS fdpid is really (fd . tempfile) */ + fd = XFASTINT (Fcar (fdpid)); file = Fcdr (fdpid); - emacs_close (XFASTINT (Fcar (fdpid))); - if (strcmp (SDATA (file), NULL_DEVICE) != 0) + /* FD is -1 and FILE is "" when we didn't actually create a + temporary file in call-process. */ + if (fd >= 0) + emacs_close (fd); + if (!(strcmp (SDATA (file), NULL_DEVICE) == 0 || SREF (file, 0) == '\0')) unlink (SDATA (file)); #else /* not MSDOS */ pid = XFASTINT (Fcdr (fdpid)); @@ -199,7 +204,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */) Lisp_Object error_file; Lisp_Object output_file = Qnil; #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */ - char *outf, *tempfile; + char *outf, *tempfile = NULL; int outfilefd; #endif int fd_output = -1; @@ -439,22 +444,23 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */) new_argv[0] = SDATA (path); #ifdef MSDOS /* MW, July 1993 */ - if ((outf = egetenv ("TMPDIR"))) - strcpy (tempfile = alloca (strlen (outf) + 20), outf); - else - { - tempfile = alloca (20); - *tempfile = '\0'; - } - dostounix_filename (tempfile); - if (*tempfile == '\0' || tempfile[strlen (tempfile) - 1] != '/') - strcat (tempfile, "/"); - strcat (tempfile, "detmp.XXX"); - mktemp (tempfile); - /* If we're redirecting STDOUT to a file, this is already opened. */ + /* If we're redirecting STDOUT to a file, that file is already open + on fd_output. */ if (fd_output < 0) { + if ((outf = egetenv ("TMPDIR"))) + strcpy (tempfile = alloca (strlen (outf) + 20), outf); + else + { + tempfile = alloca (20); + *tempfile = '\0'; + } + dostounix_filename (tempfile); + if (*tempfile == '\0' || tempfile[strlen (tempfile) - 1] != '/') + strcat (tempfile, "/"); + strcat (tempfile, "detmp.XXX"); + mktemp (tempfile); outfilefd = creat (tempfile, S_IREAD | S_IWRITE); if (outfilefd < 0) { emacs_close (filefd); @@ -561,15 +567,21 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */) if (fd_error != outfilefd) emacs_close (fd_error); fd1 = -1; /* No harm in closing that one! */ - /* Since CRLF is converted to LF within `decode_coding', we can - always open a file with binary mode. */ - fd[0] = emacs_open (tempfile, O_RDONLY | O_BINARY, 0); - if (fd[0] < 0) + if (tempfile) { - unlink (tempfile); - emacs_close (filefd); - report_file_error ("Cannot re-open temporary file", Qnil); + /* Since CRLF is converted to LF within `decode_coding', we + can always open a file with binary mode. */ + fd[0] = emacs_open (tempfile, O_RDONLY | O_BINARY, 0); + if (fd[0] < 0) + { + unlink (tempfile); + emacs_close (filefd); + report_file_error ("Cannot re-open temporary file", + Fcons (tempfile, Qnil)); + } } + else + fd[0] = -1; /* We are not going to read from tempfile. */ #else /* not MSDOS */ #ifdef WINDOWSNT pid = child_setup (filefd, fd1, fd_error, (char **) new_argv, @@ -676,7 +688,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */) record_unwind_protect (call_process_cleanup, Fcons (Fcurrent_buffer (), Fcons (make_number (fd[0]), - build_string (tempfile)))); + build_string (tempfile ? tempfile : "")))); #else record_unwind_protect (call_process_cleanup, Fcons (Fcurrent_buffer (),