aboutsummaryrefslogtreecommitdiffstats
path: root/src/callproc.c
diff options
context:
space:
mode:
authorJoakim Verona2012-05-30 14:08:12 +0200
committerJoakim Verona2012-05-30 14:08:12 +0200
commit70700d8c47a35b19e29607ac5f0ed322bdd78249 (patch)
tree4fa00d3fac00025354f0b6e23dcda1b58689a094 /src/callproc.c
parent44fce8ffe7198991c41c985ff4e67ec7d407907e (diff)
parent72cb32cf2f0938dd7dc733eed77b1ed1e497b053 (diff)
downloademacs-70700d8c47a35b19e29607ac5f0ed322bdd78249.tar.gz
emacs-70700d8c47a35b19e29607ac5f0ed322bdd78249.zip
upstream
Diffstat (limited to 'src/callproc.c')
-rw-r--r--src/callproc.c69
1 files changed, 39 insertions, 30 deletions
diff --git a/src/callproc.c b/src/callproc.c
index 9528c9644d8..f7c9971907d 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -102,8 +102,12 @@ static Lisp_Object Fgetenv_internal (Lisp_Object, Lisp_Object);
102static Lisp_Object 102static Lisp_Object
103call_process_kill (Lisp_Object fdpid) 103call_process_kill (Lisp_Object fdpid)
104{ 104{
105 emacs_close (XFASTINT (Fcar (fdpid))); 105 int fd;
106 EMACS_KILLPG (XFASTINT (Fcdr (fdpid)), SIGKILL); 106 pid_t pid;
107 CONS_TO_INTEGER (Fcar (fdpid), int, fd);
108 CONS_TO_INTEGER (Fcdr (fdpid), pid_t, pid);
109 emacs_close (fd);
110 EMACS_KILLPG (pid, SIGKILL);
107 synch_process_alive = 0; 111 synch_process_alive = 0;
108 return Qnil; 112 return Qnil;
109} 113}
@@ -112,18 +116,18 @@ static Lisp_Object
112call_process_cleanup (Lisp_Object arg) 116call_process_cleanup (Lisp_Object arg)
113{ 117{
114 Lisp_Object fdpid = Fcdr (arg); 118 Lisp_Object fdpid = Fcdr (arg);
119 int fd;
115#if defined (MSDOS) 120#if defined (MSDOS)
116 Lisp_Object file; 121 Lisp_Object file;
117 int fd;
118#else 122#else
119 int pid; 123 pid_t pid;
120#endif 124#endif
121 125
122 Fset_buffer (Fcar (arg)); 126 Fset_buffer (Fcar (arg));
127 CONS_TO_INTEGER (Fcar (fdpid), int, fd);
123 128
124#if defined (MSDOS) 129#if defined (MSDOS)
125 /* for MSDOS fdpid is really (fd . tempfile) */ 130 /* for MSDOS fdpid is really (fd . tempfile) */
126 fd = XFASTINT (Fcar (fdpid));
127 file = Fcdr (fdpid); 131 file = Fcdr (fdpid);
128 /* FD is -1 and FILE is "" when we didn't actually create a 132 /* FD is -1 and FILE is "" when we didn't actually create a
129 temporary file in call-process. */ 133 temporary file in call-process. */
@@ -132,17 +136,17 @@ call_process_cleanup (Lisp_Object arg)
132 if (!(strcmp (SDATA (file), NULL_DEVICE) == 0 || SREF (file, 0) == '\0')) 136 if (!(strcmp (SDATA (file), NULL_DEVICE) == 0 || SREF (file, 0) == '\0'))
133 unlink (SDATA (file)); 137 unlink (SDATA (file));
134#else /* not MSDOS */ 138#else /* not MSDOS */
135 pid = XFASTINT (Fcdr (fdpid)); 139 CONS_TO_INTEGER (Fcdr (fdpid), pid_t, pid);
136 140
137 if (call_process_exited) 141 if (call_process_exited)
138 { 142 {
139 emacs_close (XFASTINT (Fcar (fdpid))); 143 emacs_close (fd);
140 return Qnil; 144 return Qnil;
141 } 145 }
142 146
143 if (EMACS_KILLPG (pid, SIGINT) == 0) 147 if (EMACS_KILLPG (pid, SIGINT) == 0)
144 { 148 {
145 int count = SPECPDL_INDEX (); 149 ptrdiff_t count = SPECPDL_INDEX ();
146 record_unwind_protect (call_process_kill, fdpid); 150 record_unwind_protect (call_process_kill, fdpid);
147 message1 ("Waiting for process to die...(type C-g again to kill it instantly)"); 151 message1 ("Waiting for process to die...(type C-g again to kill it instantly)");
148 immediate_quit = 1; 152 immediate_quit = 1;
@@ -153,7 +157,7 @@ call_process_cleanup (Lisp_Object arg)
153 message1 ("Waiting for process to die...done"); 157 message1 ("Waiting for process to die...done");
154 } 158 }
155 synch_process_alive = 0; 159 synch_process_alive = 0;
156 emacs_close (XFASTINT (Fcar (fdpid))); 160 emacs_close (fd);
157#endif /* not MSDOS */ 161#endif /* not MSDOS */
158 return Qnil; 162 return Qnil;
159} 163}
@@ -187,17 +191,16 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.
187usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */) 191usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
188 (ptrdiff_t nargs, Lisp_Object *args) 192 (ptrdiff_t nargs, Lisp_Object *args)
189{ 193{
190 Lisp_Object infile, buffer, current_dir, path; 194 Lisp_Object infile, buffer, current_dir, path, cleanup_info_tail;
191 volatile int display_p_volatile; 195 int display_p;
192 int fd[2]; 196 int fd[2];
193 int filefd; 197 int filefd;
194 register int pid;
195#define CALLPROC_BUFFER_SIZE_MIN (16 * 1024) 198#define CALLPROC_BUFFER_SIZE_MIN (16 * 1024)
196#define CALLPROC_BUFFER_SIZE_MAX (4 * CALLPROC_BUFFER_SIZE_MIN) 199#define CALLPROC_BUFFER_SIZE_MAX (4 * CALLPROC_BUFFER_SIZE_MIN)
197 char buf[CALLPROC_BUFFER_SIZE_MAX]; 200 char buf[CALLPROC_BUFFER_SIZE_MAX];
198 int bufsize = CALLPROC_BUFFER_SIZE_MIN; 201 int bufsize = CALLPROC_BUFFER_SIZE_MIN;
199 int count = SPECPDL_INDEX (); 202 ptrdiff_t count = SPECPDL_INDEX ();
200 volatile USE_SAFE_ALLOCA; 203 USE_SAFE_ALLOCA;
201 204
202 register const unsigned char **new_argv; 205 register const unsigned char **new_argv;
203 /* File to use for stderr in the child. 206 /* File to use for stderr in the child.
@@ -207,6 +210,9 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
207#ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */ 210#ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
208 char *outf, *tempfile = NULL; 211 char *outf, *tempfile = NULL;
209 int outfilefd; 212 int outfilefd;
213 int pid;
214#else
215 pid_t pid;
210#endif 216#endif
211 int fd_output = -1; 217 int fd_output = -1;
212 struct coding_system process_coding; /* coding-system of process output */ 218 struct coding_system process_coding; /* coding-system of process output */
@@ -371,7 +377,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
371 UNGCPRO; 377 UNGCPRO;
372 } 378 }
373 379
374 display_p_volatile = INTERACTIVE && nargs >= 4 && !NILP (args[3]); 380 display_p = INTERACTIVE && nargs >= 4 && !NILP (args[3]);
375 381
376 filefd = emacs_open (SSDATA (infile), O_RDONLY, 0); 382 filefd = emacs_open (SSDATA (infile), O_RDONLY, 0);
377 if (filefd < 0) 383 if (filefd < 0)
@@ -607,10 +613,13 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
607 Lisp_Object volatile buffer_volatile = buffer; 613 Lisp_Object volatile buffer_volatile = buffer;
608 Lisp_Object volatile coding_systems_volatile = coding_systems; 614 Lisp_Object volatile coding_systems_volatile = coding_systems;
609 Lisp_Object volatile current_dir_volatile = current_dir; 615 Lisp_Object volatile current_dir_volatile = current_dir;
616 int volatile display_p_volatile = display_p;
610 int volatile fd1_volatile = fd1; 617 int volatile fd1_volatile = fd1;
611 int volatile fd_error_volatile = fd_error; 618 int volatile fd_error_volatile = fd_error;
612 int volatile fd_output_volatile = fd_output; 619 int volatile fd_output_volatile = fd_output;
613 int volatile output_to_buffer_volatile = output_to_buffer; 620 int volatile output_to_buffer_volatile = output_to_buffer;
621 int volatile sa_must_free_volatile = sa_must_free;
622 ptrdiff_t volatile sa_count_volatile = sa_count;
614 unsigned char const **volatile new_argv_volatile = new_argv; 623 unsigned char const **volatile new_argv_volatile = new_argv;
615 624
616 pid = vfork (); 625 pid = vfork ();
@@ -618,10 +627,13 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
618 buffer = buffer_volatile; 627 buffer = buffer_volatile;
619 coding_systems = coding_systems_volatile; 628 coding_systems = coding_systems_volatile;
620 current_dir = current_dir_volatile; 629 current_dir = current_dir_volatile;
630 display_p = display_p_volatile;
621 fd1 = fd1_volatile; 631 fd1 = fd1_volatile;
622 fd_error = fd_error_volatile; 632 fd_error = fd_error_volatile;
623 fd_output = fd_output_volatile; 633 fd_output = fd_output_volatile;
624 output_to_buffer = output_to_buffer_volatile; 634 output_to_buffer = output_to_buffer_volatile;
635 sa_must_free = sa_must_free_volatile;
636 sa_count = sa_count_volatile;
625 new_argv = new_argv_volatile; 637 new_argv = new_argv_volatile;
626 } 638 }
627 639
@@ -640,7 +652,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
640 652
641 /* GConf causes us to ignore SIGPIPE, make sure it is restored 653 /* GConf causes us to ignore SIGPIPE, make sure it is restored
642 in the child. */ 654 in the child. */
643 //signal (SIGPIPE, SIG_DFL); 655 signal (SIGPIPE, SIG_DFL);
644#ifdef HAVE_WORKING_VFORK 656#ifdef HAVE_WORKING_VFORK
645 pthread_sigmask (SIG_SETMASK, &procmask, 0); 657 pthread_sigmask (SIG_SETMASK, &procmask, 0);
646#endif 658#endif
@@ -694,16 +706,14 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
694 706
695#if defined (MSDOS) 707#if defined (MSDOS)
696 /* MSDOS needs different cleanup information. */ 708 /* MSDOS needs different cleanup information. */
697 record_unwind_protect (call_process_cleanup, 709 cleanup_info_tail = build_string (tempfile ? tempfile : "");
698 Fcons (Fcurrent_buffer (),
699 Fcons (make_number (fd[0]),
700 build_string (tempfile ? tempfile : ""))));
701#else 710#else
711 cleanup_info_tail = INTEGER_TO_CONS (pid);
712#endif /* not MSDOS */
702 record_unwind_protect (call_process_cleanup, 713 record_unwind_protect (call_process_cleanup,
703 Fcons (Fcurrent_buffer (), 714 Fcons (Fcurrent_buffer (),
704 Fcons (make_number (fd[0]), make_number (pid)))); 715 Fcons (INTEGER_TO_CONS (fd[0]),
705#endif /* not MSDOS */ 716 cleanup_info_tail)));
706
707 717
708 if (BUFFERP (buffer)) 718 if (BUFFERP (buffer))
709 Fset_buffer (buffer); 719 Fset_buffer (buffer);
@@ -759,11 +769,10 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
759 769
760 if (output_to_buffer) 770 if (output_to_buffer)
761 { 771 {
762 register EMACS_INT nread; 772 register int nread;
763 int first = 1; 773 int first = 1;
764 EMACS_INT total_read = 0; 774 EMACS_INT total_read = 0;
765 int carryover = 0; 775 int carryover = 0;
766 int display_p = display_p_volatile;
767 int display_on_the_fly = display_p; 776 int display_on_the_fly = display_p;
768 struct coding_system saved_coding; 777 struct coding_system saved_coding;
769 778
@@ -806,7 +815,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
806 else 815 else
807 { /* We have to decode the input. */ 816 { /* We have to decode the input. */
808 Lisp_Object curbuf; 817 Lisp_Object curbuf;
809 int count1 = SPECPDL_INDEX (); 818 ptrdiff_t count1 = SPECPDL_INDEX ();
810 819
811 XSETBUFFER (curbuf, current_buffer); 820 XSETBUFFER (curbuf, current_buffer);
812 /* We cannot allow after-change-functions be run 821 /* We cannot allow after-change-functions be run
@@ -925,7 +934,7 @@ static Lisp_Object
925delete_temp_file (Lisp_Object name) 934delete_temp_file (Lisp_Object name)
926{ 935{
927 /* Suppress jka-compr handling, etc. */ 936 /* Suppress jka-compr handling, etc. */
928 int count = SPECPDL_INDEX (); 937 ptrdiff_t count = SPECPDL_INDEX ();
929 specbind (intern ("file-name-handler-alist"), Qnil); 938 specbind (intern ("file-name-handler-alist"), Qnil);
930 internal_delete_file (name); 939 internal_delete_file (name);
931 unbind_to (count, Qnil); 940 unbind_to (count, Qnil);
@@ -962,7 +971,7 @@ usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &r
962 struct gcpro gcpro1; 971 struct gcpro gcpro1;
963 Lisp_Object filename_string; 972 Lisp_Object filename_string;
964 register Lisp_Object start, end; 973 register Lisp_Object start, end;
965 int count = SPECPDL_INDEX (); 974 ptrdiff_t count = SPECPDL_INDEX ();
966 /* Qt denotes we have not yet called Ffind_operation_coding_system. */ 975 /* Qt denotes we have not yet called Ffind_operation_coding_system. */
967 Lisp_Object coding_systems; 976 Lisp_Object coding_systems;
968 Lisp_Object val, *args2; 977 Lisp_Object val, *args2;
@@ -1039,7 +1048,7 @@ usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &r
1039 val = complement_process_encoding_system (val); 1048 val = complement_process_encoding_system (val);
1040 1049
1041 { 1050 {
1042 int count1 = SPECPDL_INDEX (); 1051 ptrdiff_t count1 = SPECPDL_INDEX ();
1043 1052
1044 specbind (intern ("coding-system-for-write"), val); 1053 specbind (intern ("coding-system-for-write"), val);
1045 /* POSIX lets mk[s]temp use "."; don't invoke jka-compr if we 1054 /* POSIX lets mk[s]temp use "."; don't invoke jka-compr if we
@@ -1139,7 +1148,7 @@ child_setup (int in, int out, int err, register char **new_argv, int set_pgrp, L
1139 HANDLE handles[3]; 1148 HANDLE handles[3];
1140#endif /* WINDOWSNT */ 1149#endif /* WINDOWSNT */
1141 1150
1142 int pid = getpid (); 1151 pid_t pid = getpid ();
1143 1152
1144 /* Close Emacs's descriptors that this process should not have. */ 1153 /* Close Emacs's descriptors that this process should not have. */
1145 close_process_descs (); 1154 close_process_descs ();