aboutsummaryrefslogtreecommitdiffstats
path: root/src/callproc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/callproc.c')
-rw-r--r--src/callproc.c67
1 files changed, 38 insertions, 29 deletions
diff --git a/src/callproc.c b/src/callproc.c
index 97531f73848..4eb83824b83 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}
@@ -186,17 +190,16 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.
186usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */) 190usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
187 (ptrdiff_t nargs, Lisp_Object *args) 191 (ptrdiff_t nargs, Lisp_Object *args)
188{ 192{
189 Lisp_Object infile, buffer, current_dir, path; 193 Lisp_Object infile, buffer, current_dir, path, cleanup_info_tail;
190 volatile int display_p_volatile; 194 int display_p;
191 int fd[2]; 195 int fd[2];
192 int filefd; 196 int filefd;
193 register int pid;
194#define CALLPROC_BUFFER_SIZE_MIN (16 * 1024) 197#define CALLPROC_BUFFER_SIZE_MIN (16 * 1024)
195#define CALLPROC_BUFFER_SIZE_MAX (4 * CALLPROC_BUFFER_SIZE_MIN) 198#define CALLPROC_BUFFER_SIZE_MAX (4 * CALLPROC_BUFFER_SIZE_MIN)
196 char buf[CALLPROC_BUFFER_SIZE_MAX]; 199 char buf[CALLPROC_BUFFER_SIZE_MAX];
197 int bufsize = CALLPROC_BUFFER_SIZE_MIN; 200 int bufsize = CALLPROC_BUFFER_SIZE_MIN;
198 int count = SPECPDL_INDEX (); 201 ptrdiff_t count = SPECPDL_INDEX ();
199 volatile USE_SAFE_ALLOCA; 202 USE_SAFE_ALLOCA;
200 203
201 register const unsigned char **new_argv; 204 register const unsigned char **new_argv;
202 /* File to use for stderr in the child. 205 /* File to use for stderr in the child.
@@ -206,6 +209,9 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
206#ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */ 209#ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
207 char *outf, *tempfile = NULL; 210 char *outf, *tempfile = NULL;
208 int outfilefd; 211 int outfilefd;
212 int pid;
213#else
214 pid_t pid;
209#endif 215#endif
210 int fd_output = -1; 216 int fd_output = -1;
211 struct coding_system process_coding; /* coding-system of process output */ 217 struct coding_system process_coding; /* coding-system of process output */
@@ -370,7 +376,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
370 UNGCPRO; 376 UNGCPRO;
371 } 377 }
372 378
373 display_p_volatile = INTERACTIVE && nargs >= 4 && !NILP (args[3]); 379 display_p = INTERACTIVE && nargs >= 4 && !NILP (args[3]);
374 380
375 filefd = emacs_open (SSDATA (infile), O_RDONLY, 0); 381 filefd = emacs_open (SSDATA (infile), O_RDONLY, 0);
376 if (filefd < 0) 382 if (filefd < 0)
@@ -606,10 +612,13 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
606 Lisp_Object volatile buffer_volatile = buffer; 612 Lisp_Object volatile buffer_volatile = buffer;
607 Lisp_Object volatile coding_systems_volatile = coding_systems; 613 Lisp_Object volatile coding_systems_volatile = coding_systems;
608 Lisp_Object volatile current_dir_volatile = current_dir; 614 Lisp_Object volatile current_dir_volatile = current_dir;
615 int volatile display_p_volatile = display_p;
609 int volatile fd1_volatile = fd1; 616 int volatile fd1_volatile = fd1;
610 int volatile fd_error_volatile = fd_error; 617 int volatile fd_error_volatile = fd_error;
611 int volatile fd_output_volatile = fd_output; 618 int volatile fd_output_volatile = fd_output;
612 int volatile output_to_buffer_volatile = output_to_buffer; 619 int volatile output_to_buffer_volatile = output_to_buffer;
620 int volatile sa_must_free_volatile = sa_must_free;
621 ptrdiff_t volatile sa_count_volatile = sa_count;
613 unsigned char const **volatile new_argv_volatile = new_argv; 622 unsigned char const **volatile new_argv_volatile = new_argv;
614 623
615 pid = vfork (); 624 pid = vfork ();
@@ -617,10 +626,13 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
617 buffer = buffer_volatile; 626 buffer = buffer_volatile;
618 coding_systems = coding_systems_volatile; 627 coding_systems = coding_systems_volatile;
619 current_dir = current_dir_volatile; 628 current_dir = current_dir_volatile;
629 display_p = display_p_volatile;
620 fd1 = fd1_volatile; 630 fd1 = fd1_volatile;
621 fd_error = fd_error_volatile; 631 fd_error = fd_error_volatile;
622 fd_output = fd_output_volatile; 632 fd_output = fd_output_volatile;
623 output_to_buffer = output_to_buffer_volatile; 633 output_to_buffer = output_to_buffer_volatile;
634 sa_must_free_volatile = sa_must_free;
635 sa_count = sa_count_volatile;
624 new_argv = new_argv_volatile; 636 new_argv = new_argv_volatile;
625 } 637 }
626 638
@@ -693,16 +705,14 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
693 705
694#if defined (MSDOS) 706#if defined (MSDOS)
695 /* MSDOS needs different cleanup information. */ 707 /* MSDOS needs different cleanup information. */
696 record_unwind_protect (call_process_cleanup, 708 cleanup_info_tail = build_string (tempfile ? tempfile : "");
697 Fcons (Fcurrent_buffer (),
698 Fcons (make_number (fd[0]),
699 build_string (tempfile ? tempfile : ""))));
700#else 709#else
710 cleanup_info_tail = INTEGER_TO_CONS (pid);
711#endif /* not MSDOS */
701 record_unwind_protect (call_process_cleanup, 712 record_unwind_protect (call_process_cleanup,
702 Fcons (Fcurrent_buffer (), 713 Fcons (Fcurrent_buffer (),
703 Fcons (make_number (fd[0]), make_number (pid)))); 714 Fcons (INTEGER_TO_CONS (fd[0]),
704#endif /* not MSDOS */ 715 cleanup_info_tail)));
705
706 716
707 if (BUFFERP (buffer)) 717 if (BUFFERP (buffer))
708 Fset_buffer (buffer); 718 Fset_buffer (buffer);
@@ -754,11 +764,10 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
754 764
755 if (output_to_buffer) 765 if (output_to_buffer)
756 { 766 {
757 register EMACS_INT nread; 767 register int nread;
758 int first = 1; 768 int first = 1;
759 EMACS_INT total_read = 0; 769 EMACS_INT total_read = 0;
760 int carryover = 0; 770 int carryover = 0;
761 int display_p = display_p_volatile;
762 int display_on_the_fly = display_p; 771 int display_on_the_fly = display_p;
763 struct coding_system saved_coding; 772 struct coding_system saved_coding;
764 773
@@ -801,7 +810,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
801 else 810 else
802 { /* We have to decode the input. */ 811 { /* We have to decode the input. */
803 Lisp_Object curbuf; 812 Lisp_Object curbuf;
804 int count1 = SPECPDL_INDEX (); 813 ptrdiff_t count1 = SPECPDL_INDEX ();
805 814
806 XSETBUFFER (curbuf, current_buffer); 815 XSETBUFFER (curbuf, current_buffer);
807 /* We cannot allow after-change-functions be run 816 /* We cannot allow after-change-functions be run
@@ -920,7 +929,7 @@ static Lisp_Object
920delete_temp_file (Lisp_Object name) 929delete_temp_file (Lisp_Object name)
921{ 930{
922 /* Suppress jka-compr handling, etc. */ 931 /* Suppress jka-compr handling, etc. */
923 int count = SPECPDL_INDEX (); 932 ptrdiff_t count = SPECPDL_INDEX ();
924 specbind (intern ("file-name-handler-alist"), Qnil); 933 specbind (intern ("file-name-handler-alist"), Qnil);
925 internal_delete_file (name); 934 internal_delete_file (name);
926 unbind_to (count, Qnil); 935 unbind_to (count, Qnil);
@@ -957,7 +966,7 @@ usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &r
957 struct gcpro gcpro1; 966 struct gcpro gcpro1;
958 Lisp_Object filename_string; 967 Lisp_Object filename_string;
959 register Lisp_Object start, end; 968 register Lisp_Object start, end;
960 int count = SPECPDL_INDEX (); 969 ptrdiff_t count = SPECPDL_INDEX ();
961 /* Qt denotes we have not yet called Ffind_operation_coding_system. */ 970 /* Qt denotes we have not yet called Ffind_operation_coding_system. */
962 Lisp_Object coding_systems; 971 Lisp_Object coding_systems;
963 Lisp_Object val, *args2; 972 Lisp_Object val, *args2;
@@ -1034,7 +1043,7 @@ usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &r
1034 val = complement_process_encoding_system (val); 1043 val = complement_process_encoding_system (val);
1035 1044
1036 { 1045 {
1037 int count1 = SPECPDL_INDEX (); 1046 ptrdiff_t count1 = SPECPDL_INDEX ();
1038 1047
1039 specbind (intern ("coding-system-for-write"), val); 1048 specbind (intern ("coding-system-for-write"), val);
1040 /* POSIX lets mk[s]temp use "."; don't invoke jka-compr if we 1049 /* POSIX lets mk[s]temp use "."; don't invoke jka-compr if we
@@ -1134,7 +1143,7 @@ child_setup (int in, int out, int err, register char **new_argv, int set_pgrp, L
1134 HANDLE handles[3]; 1143 HANDLE handles[3];
1135#endif /* WINDOWSNT */ 1144#endif /* WINDOWSNT */
1136 1145
1137 int pid = getpid (); 1146 pid_t pid = getpid ();
1138 1147
1139 /* Close Emacs's descriptors that this process should not have. */ 1148 /* Close Emacs's descriptors that this process should not have. */
1140 close_process_descs (); 1149 close_process_descs ();