aboutsummaryrefslogtreecommitdiffstats
path: root/src/process.c
diff options
context:
space:
mode:
authorStefan Monnier2011-03-31 00:24:03 -0400
committerStefan Monnier2011-03-31 00:24:03 -0400
commit40d83b412f584cc02e68d4eac8fd5e6eb769e2fe (patch)
treeb56f27a7e6d75a8c1fd27b00179a27b5efea0a32 /src/process.c
parentf488fb6528738131ef41859e1f04125f2e50efce (diff)
parent44f230aa043ebb222aa0876b44d70484d5dd38db (diff)
downloademacs-40d83b412f584cc02e68d4eac8fd5e6eb769e2fe.tar.gz
emacs-40d83b412f584cc02e68d4eac8fd5e6eb769e2fe.zip
Merge from trunk
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c102
1 files changed, 48 insertions, 54 deletions
diff --git a/src/process.c b/src/process.c
index c9b420ab2ae..1abfbd3f2a4 100644
--- a/src/process.c
+++ b/src/process.c
@@ -159,9 +159,6 @@ extern Lisp_Object QCfilter;
159#define SERIALCONN_P(p) (EQ (XPROCESS (p)->type, Qserial)) 159#define SERIALCONN_P(p) (EQ (XPROCESS (p)->type, Qserial))
160#define SERIALCONN1_P(p) (EQ ((p)->type, Qserial)) 160#define SERIALCONN1_P(p) (EQ ((p)->type, Qserial))
161 161
162/* Define first descriptor number available for subprocesses. */
163#define FIRST_PROC_DESC 3
164
165#ifndef HAVE_H_ERRNO 162#ifndef HAVE_H_ERRNO
166extern int h_errno; 163extern int h_errno;
167#endif 164#endif
@@ -278,10 +275,6 @@ static SELECT_TYPE connect_wait_mask;
278 275
279/* Number of bits set in connect_wait_mask. */ 276/* Number of bits set in connect_wait_mask. */
280static int num_pending_connects; 277static int num_pending_connects;
281
282#define IF_NON_BLOCKING_CONNECT(s) s
283#else /* NON_BLOCKING_CONNECT */
284#define IF_NON_BLOCKING_CONNECT(s)
285#endif /* NON_BLOCKING_CONNECT */ 278#endif /* NON_BLOCKING_CONNECT */
286 279
287/* The largest descriptor currently in use for a process object. */ 280/* The largest descriptor currently in use for a process object. */
@@ -1250,8 +1243,8 @@ Returns nil if format of ADDRESS is invalid. */)
1250static Lisp_Object 1243static Lisp_Object
1251list_processes_1 (Lisp_Object query_only) 1244list_processes_1 (Lisp_Object query_only)
1252{ 1245{
1253 register Lisp_Object tail, tem; 1246 register Lisp_Object tail;
1254 Lisp_Object proc, minspace, tem1; 1247 Lisp_Object proc, minspace;
1255 register struct Lisp_Process *p; 1248 register struct Lisp_Process *p;
1256 char tembuf[300]; 1249 char tembuf[300];
1257 int w_proc, w_buffer, w_tty; 1250 int w_proc, w_buffer, w_tty;
@@ -1453,10 +1446,10 @@ list_processes_1 (Lisp_Object query_only)
1453 } 1446 }
1454 else 1447 else
1455 { 1448 {
1456 tem = p->command; 1449 Lisp_Object tem = p->command;
1457 while (1) 1450 while (1)
1458 { 1451 {
1459 tem1 = Fcar (tem); 1452 Lisp_Object tem1 = Fcar (tem);
1460 if (NILP (tem1)) 1453 if (NILP (tem1))
1461 break; 1454 break;
1462 Finsert (1, &tem1); 1455 Finsert (1, &tem1);
@@ -1519,11 +1512,11 @@ the command through a shell and redirect one of them using the shell
1519syntax. 1512syntax.
1520 1513
1521usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */) 1514usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
1522 (int nargs, register Lisp_Object *args) 1515 (size_t nargs, register Lisp_Object *args)
1523{ 1516{
1524 Lisp_Object buffer, name, program, proc, current_dir, tem; 1517 Lisp_Object buffer, name, program, proc, current_dir, tem;
1525 register unsigned char **new_argv; 1518 register unsigned char **new_argv;
1526 register int i; 1519 register size_t i;
1527 int count = SPECPDL_INDEX (); 1520 int count = SPECPDL_INDEX ();
1528 1521
1529 buffer = args[1]; 1522 buffer = args[1];
@@ -1729,7 +1722,7 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
1729 new_argv = (unsigned char **) alloca ((nargs - 1) * sizeof (char *)); 1722 new_argv = (unsigned char **) alloca ((nargs - 1) * sizeof (char *));
1730 new_argv[nargs - 2] = 0; 1723 new_argv[nargs - 2] = 0;
1731 1724
1732 for (i = nargs - 3; i >= 0; i--) 1725 for (i = nargs - 2; i-- != 0; )
1733 { 1726 {
1734 new_argv[i] = SDATA (XCAR (tem)); 1727 new_argv[i] = SDATA (XCAR (tem));
1735 tem = XCDR (tem); 1728 tem = XCDR (tem);
@@ -1919,8 +1912,7 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1919 /* child_setup must clobber environ on systems with true vfork. 1912 /* child_setup must clobber environ on systems with true vfork.
1920 Protect it from permanent change. */ 1913 Protect it from permanent change. */
1921 char **save_environ = environ; 1914 char **save_environ = environ;
1922 1915 volatile Lisp_Object encoded_current_dir = ENCODE_FILE (current_dir);
1923 current_dir = ENCODE_FILE (current_dir);
1924 1916
1925#ifndef WINDOWSNT 1917#ifndef WINDOWSNT
1926 pid = vfork (); 1918 pid = vfork ();
@@ -2061,13 +2053,13 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
2061 child_setup_tty (xforkout); 2053 child_setup_tty (xforkout);
2062#ifdef WINDOWSNT 2054#ifdef WINDOWSNT
2063 pid = child_setup (xforkin, xforkout, xforkout, 2055 pid = child_setup (xforkin, xforkout, xforkout,
2064 new_argv, 1, current_dir); 2056 new_argv, 1, encoded_current_dir);
2065#else /* not WINDOWSNT */ 2057#else /* not WINDOWSNT */
2066#ifdef FD_CLOEXEC 2058#ifdef FD_CLOEXEC
2067 emacs_close (wait_child_setup[0]); 2059 emacs_close (wait_child_setup[0]);
2068#endif 2060#endif
2069 child_setup (xforkin, xforkout, xforkout, 2061 child_setup (xforkin, xforkout, xforkout,
2070 new_argv, 1, current_dir); 2062 new_argv, 1, encoded_current_dir);
2071#endif /* not WINDOWSNT */ 2063#endif /* not WINDOWSNT */
2072 } 2064 }
2073 environ = save_environ; 2065 environ = save_environ;
@@ -2689,7 +2681,7 @@ Examples:
2689\(serial-process-configure :port "\\\\.\\COM13" :bytesize 7) 2681\(serial-process-configure :port "\\\\.\\COM13" :bytesize 7)
2690 2682
2691usage: (serial-process-configure &rest ARGS) */) 2683usage: (serial-process-configure &rest ARGS) */)
2692 (int nargs, Lisp_Object *args) 2684 (size_t nargs, Lisp_Object *args)
2693{ 2685{
2694 struct Lisp_Process *p; 2686 struct Lisp_Process *p;
2695 Lisp_Object contact = Qnil; 2687 Lisp_Object contact = Qnil;
@@ -2807,7 +2799,7 @@ Examples:
2807\(make-serial-process :port "/dev/tty.BlueConsole-SPP-1" :speed nil) 2799\(make-serial-process :port "/dev/tty.BlueConsole-SPP-1" :speed nil)
2808 2800
2809usage: (make-serial-process &rest ARGS) */) 2801usage: (make-serial-process &rest ARGS) */)
2810 (int nargs, Lisp_Object *args) 2802 (size_t nargs, Lisp_Object *args)
2811{ 2803{
2812 int fd = -1; 2804 int fd = -1;
2813 Lisp_Object proc, contact, port; 2805 Lisp_Object proc, contact, port;
@@ -3085,7 +3077,7 @@ The original argument list, modified with the actual connection
3085information, is available via the `process-contact' function. 3077information, is available via the `process-contact' function.
3086 3078
3087usage: (make-network-process &rest ARGS) */) 3079usage: (make-network-process &rest ARGS) */)
3088 (int nargs, Lisp_Object *args) 3080 (size_t nargs, Lisp_Object *args)
3089{ 3081{
3090 Lisp_Object proc; 3082 Lisp_Object proc;
3091 Lisp_Object contact; 3083 Lisp_Object contact;
@@ -3401,9 +3393,12 @@ usage: (make-network-process &rest ARGS) */)
3401 3393
3402 for (lres = res; lres; lres = lres->ai_next) 3394 for (lres = res; lres; lres = lres->ai_next)
3403 { 3395 {
3404 int optn, optbits; 3396 size_t optn;
3397 int optbits;
3405 3398
3399#ifdef WINDOWSNT
3406 retry_connect: 3400 retry_connect:
3401#endif
3407 3402
3408 s = socket (lres->ai_family, lres->ai_socktype, lres->ai_protocol); 3403 s = socket (lres->ai_family, lres->ai_socktype, lres->ai_protocol);
3409 if (s < 0) 3404 if (s < 0)
@@ -3467,7 +3462,7 @@ usage: (make-network-process &rest ARGS) */)
3467 if (EQ (service, Qt)) 3462 if (EQ (service, Qt))
3468 { 3463 {
3469 struct sockaddr_in sa1; 3464 struct sockaddr_in sa1;
3470 int len1 = sizeof (sa1); 3465 socklen_t len1 = sizeof (sa1);
3471 if (getsockname (s, (struct sockaddr *)&sa1, &len1) == 0) 3466 if (getsockname (s, (struct sockaddr *)&sa1, &len1) == 0)
3472 { 3467 {
3473 ((struct sockaddr_in *)(lres->ai_addr))->sin_port = sa1.sin_port; 3468 ((struct sockaddr_in *)(lres->ai_addr))->sin_port = sa1.sin_port;
@@ -3514,7 +3509,8 @@ usage: (make-network-process &rest ARGS) */)
3514 /* Unlike most other syscalls connect() cannot be called 3509 /* Unlike most other syscalls connect() cannot be called
3515 again. (That would return EALREADY.) The proper way to 3510 again. (That would return EALREADY.) The proper way to
3516 wait for completion is select(). */ 3511 wait for completion is select(). */
3517 int sc, len; 3512 int sc;
3513 socklen_t len;
3518 SELECT_TYPE fdset; 3514 SELECT_TYPE fdset;
3519 retry_select: 3515 retry_select:
3520 FD_ZERO (&fdset); 3516 FD_ZERO (&fdset);
@@ -3587,7 +3583,7 @@ usage: (make-network-process &rest ARGS) */)
3587 if (!is_server) 3583 if (!is_server)
3588 { 3584 {
3589 struct sockaddr_in sa1; 3585 struct sockaddr_in sa1;
3590 int len1 = sizeof (sa1); 3586 socklen_t len1 = sizeof (sa1);
3591 if (getsockname (s, (struct sockaddr *)&sa1, &len1) == 0) 3587 if (getsockname (s, (struct sockaddr *)&sa1, &len1) == 0)
3592 contact = Fplist_put (contact, QClocal, 3588 contact = Fplist_put (contact, QClocal,
3593 conv_sockaddr_to_lisp ((struct sockaddr *)&sa1, len1)); 3589 conv_sockaddr_to_lisp ((struct sockaddr *)&sa1, len1));
@@ -3705,10 +3701,10 @@ usage: (make-network-process &rest ARGS) */)
3705 3701
3706 { 3702 {
3707 /* Setup coding systems for communicating with the network stream. */ 3703 /* Setup coding systems for communicating with the network stream. */
3708 struct gcpro gcpro1; 3704 struct gcpro inner_gcpro1;
3709 /* Qt denotes we have not yet called Ffind_operation_coding_system. */ 3705 /* Qt denotes we have not yet called Ffind_operation_coding_system. */
3710 Lisp_Object coding_systems = Qt; 3706 Lisp_Object coding_systems = Qt;
3711 Lisp_Object args[5], val; 3707 Lisp_Object fargs[5], val;
3712 3708
3713 if (!NILP (tem)) 3709 if (!NILP (tem))
3714 { 3710 {
@@ -3731,11 +3727,11 @@ usage: (make-network-process &rest ARGS) */)
3731 coding_systems = Qnil; 3727 coding_systems = Qnil;
3732 else 3728 else
3733 { 3729 {
3734 args[0] = Qopen_network_stream, args[1] = name, 3730 fargs[0] = Qopen_network_stream, fargs[1] = name,
3735 args[2] = buffer, args[3] = host, args[4] = service; 3731 fargs[2] = buffer, fargs[3] = host, fargs[4] = service;
3736 GCPRO1 (proc); 3732 GCPRO1_VAR (proc, inner_gcpro);
3737 coding_systems = Ffind_operation_coding_system (5, args); 3733 coding_systems = Ffind_operation_coding_system (5, fargs);
3738 UNGCPRO; 3734 UNGCPRO_VAR (inner_gcpro);
3739 } 3735 }
3740 if (CONSP (coding_systems)) 3736 if (CONSP (coding_systems))
3741 val = XCAR (coding_systems); 3737 val = XCAR (coding_systems);
@@ -3764,11 +3760,11 @@ usage: (make-network-process &rest ARGS) */)
3764 coding_systems = Qnil; 3760 coding_systems = Qnil;
3765 else 3761 else
3766 { 3762 {
3767 args[0] = Qopen_network_stream, args[1] = name, 3763 fargs[0] = Qopen_network_stream, fargs[1] = name,
3768 args[2] = buffer, args[3] = host, args[4] = service; 3764 fargs[2] = buffer, fargs[3] = host, fargs[4] = service;
3769 GCPRO1 (proc); 3765 GCPRO1_VAR (proc, inner_gcpro);
3770 coding_systems = Ffind_operation_coding_system (5, args); 3766 coding_systems = Ffind_operation_coding_system (5, fargs);
3771 UNGCPRO; 3767 UNGCPRO_VAR (inner_gcpro);
3772 } 3768 }
3773 } 3769 }
3774 if (CONSP (coding_systems)) 3770 if (CONSP (coding_systems))
@@ -3948,7 +3944,7 @@ FLAGS is the current flags of the interface. */)
3948 CHECK_STRING (ifname); 3944 CHECK_STRING (ifname);
3949 3945
3950 memset (rq.ifr_name, 0, sizeof rq.ifr_name); 3946 memset (rq.ifr_name, 0, sizeof rq.ifr_name);
3951 strncpy (rq.ifr_name, SDATA (ifname), sizeof (rq.ifr_name)); 3947 strncpy (rq.ifr_name, SSDATA (ifname), sizeof (rq.ifr_name));
3952 3948
3953 s = socket (AF_INET, SOCK_STREAM, 0); 3949 s = socket (AF_INET, SOCK_STREAM, 0);
3954 if (s < 0) 3950 if (s < 0)
@@ -4192,7 +4188,7 @@ server_accept_connection (Lisp_Object server, int channel)
4192 struct sockaddr_un un; 4188 struct sockaddr_un un;
4193#endif 4189#endif
4194 } saddr; 4190 } saddr;
4195 int len = sizeof saddr; 4191 socklen_t len = sizeof saddr;
4196 4192
4197 s = accept (channel, &saddr.sa, &len); 4193 s = accept (channel, &saddr.sa, &len);
4198 4194
@@ -4553,7 +4549,7 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4553 struct buffer *old_buffer = current_buffer; 4549 struct buffer *old_buffer = current_buffer;
4554 Lisp_Object old_window = selected_window; 4550 Lisp_Object old_window = selected_window;
4555 4551
4556 timer_delay = timer_check (1); 4552 timer_delay = timer_check ();
4557 4553
4558 /* If a timer has run, this might have changed buffers 4554 /* If a timer has run, this might have changed buffers
4559 an alike. Make read_key_sequence aware of that. */ 4555 an alike. Make read_key_sequence aware of that. */
@@ -4928,8 +4924,6 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4928 d->func (channel, d->data, 0); 4924 d->func (channel, d->data, 0);
4929 } 4925 }
4930 4926
4931 /* Really FIRST_PROC_DESC should be 0 on Unix,
4932 but this is safer in the short run. */
4933 for (channel = 0; channel <= max_process_desc; channel++) 4927 for (channel = 0; channel <= max_process_desc; channel++)
4934 { 4928 {
4935 if (FD_ISSET (channel, &Available) 4929 if (FD_ISSET (channel, &Available)
@@ -5059,7 +5053,7 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
5059 /* getsockopt(,,SO_ERROR,,) is said to hang on some systems. 5053 /* getsockopt(,,SO_ERROR,,) is said to hang on some systems.
5060 So only use it on systems where it is known to work. */ 5054 So only use it on systems where it is known to work. */
5061 { 5055 {
5062 int xlen = sizeof (xerrno); 5056 socklen_t xlen = sizeof (xerrno);
5063 if (getsockopt (channel, SOL_SOCKET, SO_ERROR, &xerrno, &xlen)) 5057 if (getsockopt (channel, SOL_SOCKET, SO_ERROR, &xerrno, &xlen))
5064 xerrno = errno; 5058 xerrno = errno;
5065 } 5059 }
@@ -5128,9 +5122,9 @@ read_process_output_call (Lisp_Object fun_and_args)
5128} 5122}
5129 5123
5130static Lisp_Object 5124static Lisp_Object
5131read_process_output_error_handler (Lisp_Object error) 5125read_process_output_error_handler (Lisp_Object error_val)
5132{ 5126{
5133 cmd_error_internal (error, "error in process filter: "); 5127 cmd_error_internal (error_val, "error in process filter: ");
5134 Vinhibit_quit = Qt; 5128 Vinhibit_quit = Qt;
5135 update_echo_area (); 5129 update_echo_area ();
5136 Fsleep_for (make_number (2), Qnil); 5130 Fsleep_for (make_number (2), Qnil);
@@ -5171,7 +5165,7 @@ read_process_output (Lisp_Object proc, register int channel)
5171 /* We have a working select, so proc_buffered_char is always -1. */ 5165 /* We have a working select, so proc_buffered_char is always -1. */
5172 if (DATAGRAM_CHAN_P (channel)) 5166 if (DATAGRAM_CHAN_P (channel))
5173 { 5167 {
5174 int len = datagram_address[channel].len; 5168 socklen_t len = datagram_address[channel].len;
5175 nbytes = recvfrom (channel, chars + carryover, readmax, 5169 nbytes = recvfrom (channel, chars + carryover, readmax,
5176 0, datagram_address[channel].sa, &len); 5170 0, datagram_address[channel].sa, &len);
5177 } 5171 }
@@ -5477,7 +5471,7 @@ read_process_output (Lisp_Object proc, register int channel)
5477jmp_buf send_process_frame; 5471jmp_buf send_process_frame;
5478Lisp_Object process_sent_to; 5472Lisp_Object process_sent_to;
5479 5473
5480static SIGTYPE 5474static void
5481send_process_trap (int ignore) 5475send_process_trap (int ignore)
5482{ 5476{
5483 SIGNAL_THREAD_CHECK (SIGPIPE); 5477 SIGNAL_THREAD_CHECK (SIGPIPE);
@@ -5504,7 +5498,7 @@ send_process (volatile Lisp_Object proc, const char *volatile buf,
5504 EMACS_INT rv; 5498 EMACS_INT rv;
5505 struct coding_system *coding; 5499 struct coding_system *coding;
5506 struct gcpro gcpro1; 5500 struct gcpro gcpro1;
5507 SIGTYPE (*volatile old_sigpipe) (int); 5501 void (*volatile old_sigpipe) (int);
5508 5502
5509 GCPRO1 (object); 5503 GCPRO1 (object);
5510 5504
@@ -5626,7 +5620,7 @@ send_process (volatile Lisp_Object proc, const char *volatile buf,
5626 while (this > 0) 5620 while (this > 0)
5627 { 5621 {
5628 int outfd = p->outfd; 5622 int outfd = p->outfd;
5629 old_sigpipe = (SIGTYPE (*) (int)) signal (SIGPIPE, send_process_trap); 5623 old_sigpipe = (void (*) (int)) signal (SIGPIPE, send_process_trap);
5630#ifdef DATAGRAM_SOCKETS 5624#ifdef DATAGRAM_SOCKETS
5631 if (DATAGRAM_CHAN_P (outfd)) 5625 if (DATAGRAM_CHAN_P (outfd))
5632 { 5626 {
@@ -5925,7 +5919,7 @@ process_send_signal (Lisp_Object process, int signo, Lisp_Object current_group,
5925 5919
5926 if (sig_char && *sig_char != CDISABLE) 5920 if (sig_char && *sig_char != CDISABLE)
5927 { 5921 {
5928 send_process (proc, sig_char, 1, Qnil); 5922 send_process (proc, (char *) sig_char, 1, Qnil);
5929 return; 5923 return;
5930 } 5924 }
5931 /* If we can't send the signal with a character, 5925 /* If we can't send the signal with a character,
@@ -6386,7 +6380,7 @@ process has been transmitted to the serial port. */)
6386 indirectly; if it does, that is a bug */ 6380 indirectly; if it does, that is a bug */
6387 6381
6388#ifdef SIGCHLD 6382#ifdef SIGCHLD
6389static SIGTYPE 6383static void
6390sigchld_handler (int signo) 6384sigchld_handler (int signo)
6391{ 6385{
6392 int old_errno = errno; 6386 int old_errno = errno;
@@ -6534,9 +6528,9 @@ exec_sentinel_unwind (Lisp_Object data)
6534} 6528}
6535 6529
6536static Lisp_Object 6530static Lisp_Object
6537exec_sentinel_error_handler (Lisp_Object error) 6531exec_sentinel_error_handler (Lisp_Object error_val)
6538{ 6532{
6539 cmd_error_internal (error, "error in process sentinel: "); 6533 cmd_error_internal (error_val, "error in process sentinel: ");
6540 Vinhibit_quit = Qt; 6534 Vinhibit_quit = Qt;
6541 update_echo_area (); 6535 update_echo_area ();
6542 Fsleep_for (make_number (2), Qnil); 6536 Fsleep_for (make_number (2), Qnil);
@@ -6953,7 +6947,7 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
6953 do 6947 do
6954 { 6948 {
6955 int old_timers_run = timers_run; 6949 int old_timers_run = timers_run;
6956 timer_delay = timer_check (1); 6950 timer_delay = timer_check ();
6957 if (timers_run != old_timers_run && do_display) 6951 if (timers_run != old_timers_run && do_display)
6958 /* We must retry, since a timer may have requeued itself 6952 /* We must retry, since a timer may have requeued itself
6959 and that could alter the time delay. */ 6953 and that could alter the time delay. */