aboutsummaryrefslogtreecommitdiffstats
path: root/src/callproc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/callproc.c')
-rw-r--r--src/callproc.c88
1 files changed, 51 insertions, 37 deletions
diff --git a/src/callproc.c b/src/callproc.c
index c53a92bbaf8..eb2a2268fe1 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -107,7 +107,7 @@ call_process_kill (Lisp_Object fdpid)
107 return Qnil; 107 return Qnil;
108} 108}
109 109
110Lisp_Object 110static Lisp_Object
111call_process_cleanup (Lisp_Object arg) 111call_process_cleanup (Lisp_Object arg)
112{ 112{
113 Lisp_Object fdpid = Fcdr (arg); 113 Lisp_Object fdpid = Fcdr (arg);
@@ -177,10 +177,10 @@ and returns a numeric exit status or a signal description string.
177If you quit, the process is killed with SIGINT, or SIGKILL if you quit again. 177If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.
178 178
179usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */) 179usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
180 (int nargs, register Lisp_Object *args) 180 (size_t nargs, register Lisp_Object *args)
181{ 181{
182 Lisp_Object infile, buffer, current_dir, path; 182 Lisp_Object infile, buffer, current_dir, path;
183 int display_p; 183 volatile int display_p_volatile;
184 int fd[2]; 184 int fd[2];
185 int filefd; 185 int filefd;
186 register int pid; 186 register int pid;
@@ -189,7 +189,9 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
189 char buf[CALLPROC_BUFFER_SIZE_MAX]; 189 char buf[CALLPROC_BUFFER_SIZE_MAX];
190 int bufsize = CALLPROC_BUFFER_SIZE_MIN; 190 int bufsize = CALLPROC_BUFFER_SIZE_MIN;
191 int count = SPECPDL_INDEX (); 191 int count = SPECPDL_INDEX ();
192 volatile USE_SAFE_ALLOCA;
192 193
194 const unsigned char **volatile new_argv_volatile;
193 register const unsigned char **new_argv; 195 register const unsigned char **new_argv;
194 /* File to use for stderr in the child. 196 /* File to use for stderr in the child.
195 t means use same as standard output. */ 197 t means use same as standard output. */
@@ -220,7 +222,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
220 /* Decide the coding-system for giving arguments. */ 222 /* Decide the coding-system for giving arguments. */
221 { 223 {
222 Lisp_Object val, *args2; 224 Lisp_Object val, *args2;
223 int i; 225 size_t i;
224 226
225 /* If arguments are supplied, we may have to encode them. */ 227 /* If arguments are supplied, we may have to encode them. */
226 if (nargs >= 5) 228 if (nargs >= 5)
@@ -241,7 +243,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
241 val = Qraw_text; 243 val = Qraw_text;
242 else 244 else
243 { 245 {
244 args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2); 246 SAFE_ALLOCA (args2, Lisp_Object *, (nargs + 1) * sizeof *args2);
245 args2[0] = Qcall_process; 247 args2[0] = Qcall_process;
246 for (i = 0; i < nargs; i++) args2[i + 1] = args[i]; 248 for (i = 0; i < nargs; i++) args2[i + 1] = args[i];
247 coding_systems = Ffind_operation_coding_system (nargs + 1, args2); 249 coding_systems = Ffind_operation_coding_system (nargs + 1, args2);
@@ -343,7 +345,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
343 UNGCPRO; 345 UNGCPRO;
344 } 346 }
345 347
346 display_p = INTERACTIVE && nargs >= 4 && !NILP (args[3]); 348 display_p_volatile = INTERACTIVE && nargs >= 4 && !NILP (args[3]);
347 349
348 filefd = emacs_open (SSDATA (infile), O_RDONLY, 0); 350 filefd = emacs_open (SSDATA (infile), O_RDONLY, 0);
349 if (filefd < 0) 351 if (filefd < 0)
@@ -371,11 +373,12 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
371 && SREF (path, 1) == ':') 373 && SREF (path, 1) == ':')
372 path = Fsubstring (path, make_number (2), Qnil); 374 path = Fsubstring (path, make_number (2), Qnil);
373 375
374 new_argv = (const unsigned char **) 376 SAFE_ALLOCA (new_argv, const unsigned char **,
375 alloca (max (2, nargs - 2) * sizeof (char *)); 377 (nargs > 4 ? nargs - 2 : 2) * sizeof *new_argv);
378 new_argv_volatile = new_argv;
376 if (nargs > 4) 379 if (nargs > 4)
377 { 380 {
378 register int i; 381 register size_t i;
379 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; 382 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
380 383
381 GCPRO5 (infile, buffer, current_dir, path, error_file); 384 GCPRO5 (infile, buffer, current_dir, path, error_file);
@@ -542,6 +545,8 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
542 545
543 pid = vfork (); 546 pid = vfork ();
544 547
548 new_argv = new_argv_volatile;
549
545 if (pid == 0) 550 if (pid == 0)
546 { 551 {
547 if (fd[0] >= 0) 552 if (fd[0] >= 0)
@@ -640,9 +645,9 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
640 { 645 {
641 if (EQ (coding_systems, Qt)) 646 if (EQ (coding_systems, Qt))
642 { 647 {
643 int i; 648 size_t i;
644 649
645 args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2); 650 SAFE_ALLOCA (args2, Lisp_Object *, (nargs + 1) * sizeof *args2);
646 args2[0] = Qcall_process; 651 args2[0] = Qcall_process;
647 for (i = 0; i < nargs; i++) args2[i + 1] = args[i]; 652 for (i = 0; i < nargs; i++) args2[i + 1] = args[i];
648 coding_systems 653 coding_systems
@@ -673,6 +678,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
673 int first = 1; 678 int first = 1;
674 EMACS_INT total_read = 0; 679 EMACS_INT total_read = 0;
675 int carryover = 0; 680 int carryover = 0;
681 int display_p = display_p_volatile;
676 int display_on_the_fly = display_p; 682 int display_on_the_fly = display_p;
677 struct coding_system saved_coding; 683 struct coding_system saved_coding;
678 684
@@ -805,6 +811,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
805 when exiting. */ 811 when exiting. */
806 call_process_exited = 1; 812 call_process_exited = 1;
807 813
814 SAFE_FREE ();
808 unbind_to (count, Qnil); 815 unbind_to (count, Qnil);
809 816
810 if (synch_process_termsig) 817 if (synch_process_termsig)
@@ -860,7 +867,7 @@ and returns a numeric exit status or a signal description string.
860If you quit, the process is killed with SIGINT, or SIGKILL if you quit again. 867If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.
861 868
862usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &rest ARGS) */) 869usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &rest ARGS) */)
863 (int nargs, register Lisp_Object *args) 870 (size_t nargs, register Lisp_Object *args)
864{ 871{
865 struct gcpro gcpro1; 872 struct gcpro gcpro1;
866 Lisp_Object filename_string; 873 Lisp_Object filename_string;
@@ -869,7 +876,7 @@ usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &r
869 /* Qt denotes we have not yet called Ffind_operation_coding_system. */ 876 /* Qt denotes we have not yet called Ffind_operation_coding_system. */
870 Lisp_Object coding_systems; 877 Lisp_Object coding_systems;
871 Lisp_Object val, *args2; 878 Lisp_Object val, *args2;
872 int i; 879 size_t i;
873 char *tempfile; 880 char *tempfile;
874 Lisp_Object tmpdir, pattern; 881 Lisp_Object tmpdir, pattern;
875 882
@@ -893,30 +900,35 @@ usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &r
893#endif 900#endif
894 } 901 }
895 902
896 pattern = Fexpand_file_name (Vtemp_file_name_pattern, tmpdir); 903 {
897 tempfile = (char *) alloca (SBYTES (pattern) + 1); 904 USE_SAFE_ALLOCA;
898 memcpy (tempfile, SDATA (pattern), SBYTES (pattern) + 1); 905 pattern = Fexpand_file_name (Vtemp_file_name_pattern, tmpdir);
899 coding_systems = Qt; 906 SAFE_ALLOCA (tempfile, char *, SBYTES (pattern) + 1);
907 memcpy (tempfile, SDATA (pattern), SBYTES (pattern) + 1);
908 coding_systems = Qt;
900 909
901#ifdef HAVE_MKSTEMP 910#ifdef HAVE_MKSTEMP
902 { 911 {
903 int fd; 912 int fd;
904 913
905 BLOCK_INPUT; 914 BLOCK_INPUT;
906 fd = mkstemp (tempfile); 915 fd = mkstemp (tempfile);
907 UNBLOCK_INPUT; 916 UNBLOCK_INPUT;
908 if (fd == -1) 917 if (fd == -1)
909 report_file_error ("Failed to open temporary file", 918 report_file_error ("Failed to open temporary file",
910 Fcons (Vtemp_file_name_pattern, Qnil)); 919 Fcons (Vtemp_file_name_pattern, Qnil));
911 else 920 else
912 close (fd); 921 close (fd);
913 } 922 }
914#else 923#else
915 mktemp (tempfile); 924 mktemp (tempfile);
916#endif 925#endif
917 926
918 filename_string = build_string (tempfile); 927 filename_string = build_string (tempfile);
919 GCPRO1 (filename_string); 928 GCPRO1 (filename_string);
929 SAFE_FREE ();
930 }
931
920 start = args[0]; 932 start = args[0];
921 end = args[1]; 933 end = args[1];
922 /* Decide coding-system of the contents of the temporary file. */ 934 /* Decide coding-system of the contents of the temporary file. */
@@ -926,11 +938,13 @@ usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &r
926 val = Qraw_text; 938 val = Qraw_text;
927 else 939 else
928 { 940 {
929 args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2); 941 USE_SAFE_ALLOCA;
942 SAFE_ALLOCA (args2, Lisp_Object *, (nargs + 1) * sizeof *args2);
930 args2[0] = Qcall_process_region; 943 args2[0] = Qcall_process_region;
931 for (i = 0; i < nargs; i++) args2[i + 1] = args[i]; 944 for (i = 0; i < nargs; i++) args2[i + 1] = args[i];
932 coding_systems = Ffind_operation_coding_system (nargs + 1, args2); 945 coding_systems = Ffind_operation_coding_system (nargs + 1, args2);
933 val = CONSP (coding_systems) ? XCDR (coding_systems) : Qnil; 946 val = CONSP (coding_systems) ? XCDR (coding_systems) : Qnil;
947 SAFE_FREE ();
934 } 948 }
935 val = complement_process_encoding_system (val); 949 val = complement_process_encoding_system (val);
936 950
@@ -1272,12 +1286,12 @@ relocate_fd (int fd, int minfd)
1272#endif 1286#endif
1273 if (new == -1) 1287 if (new == -1)
1274 { 1288 {
1275 const char *message1 = "Error while setting up child: "; 1289 const char *message_1 = "Error while setting up child: ";
1276 const char *errmessage = strerror (errno); 1290 const char *errmessage = strerror (errno);
1277 const char *message2 = "\n"; 1291 const char *message_2 = "\n";
1278 emacs_write (2, message1, strlen (message1)); 1292 emacs_write (2, message_1, strlen (message_1));
1279 emacs_write (2, errmessage, strlen (errmessage)); 1293 emacs_write (2, errmessage, strlen (errmessage));
1280 emacs_write (2, message2, strlen (message2)); 1294 emacs_write (2, message_2, strlen (message_2));
1281 _exit (1); 1295 _exit (1);
1282 } 1296 }
1283 emacs_close (fd); 1297 emacs_close (fd);