aboutsummaryrefslogtreecommitdiffstats
path: root/src/process.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c131
1 files changed, 93 insertions, 38 deletions
diff --git a/src/process.c b/src/process.c
index 8e0b2349f9d..6717ccb4187 100644
--- a/src/process.c
+++ b/src/process.c
@@ -1,6 +1,6 @@
1/* Asynchronous subprocess control for GNU Emacs. 1/* Asynchronous subprocess control for GNU Emacs.
2 2
3Copyright (C) 1985-1988, 1993-1996, 1998-1999, 2001-2018 Free Software 3Copyright (C) 1985-1988, 1993-1996, 1998-1999, 2001-2019 Free Software
4Foundation, Inc. 4Foundation, Inc.
5 5
6This file is part of GNU Emacs. 6This file is part of GNU Emacs.
@@ -858,7 +858,8 @@ allocate_pty (char pty_name[PTY_NAME_SIZE])
858static struct Lisp_Process * 858static struct Lisp_Process *
859allocate_process (void) 859allocate_process (void)
860{ 860{
861 return ALLOCATE_ZEROED_PSEUDOVECTOR (struct Lisp_Process, pid, PVEC_PROCESS); 861 return ALLOCATE_ZEROED_PSEUDOVECTOR (struct Lisp_Process, thread,
862 PVEC_PROCESS);
862} 863}
863 864
864static Lisp_Object 865static Lisp_Object
@@ -1360,7 +1361,7 @@ If THREAD is nil, the process is unlocked. */)
1360 1361
1361DEFUN ("process-thread", Fprocess_thread, Sprocess_thread, 1362DEFUN ("process-thread", Fprocess_thread, Sprocess_thread,
1362 1, 1, 0, 1363 1, 1, 0,
1363 doc: /* Ret the locking thread of PROCESS. 1364 doc: /* Return the locking thread of PROCESS.
1364If PROCESS is unlocked, this function returns nil. */) 1365If PROCESS is unlocked, this function returns nil. */)
1365 (Lisp_Object process) 1366 (Lisp_Object process)
1366{ 1367{
@@ -1642,10 +1643,11 @@ ENCODING is used for writing.
1642:noquery BOOL -- When exiting Emacs, query the user if BOOL is nil and 1643:noquery BOOL -- When exiting Emacs, query the user if BOOL is nil and
1643the process is running. If BOOL is not given, query before exiting. 1644the process is running. If BOOL is not given, query before exiting.
1644 1645
1645:stop BOOL -- Start process in the `stopped' state if BOOL non-nil. 1646:stop BOOL -- BOOL must be nil. The `:stop' key is ignored otherwise
1646In the stopped state, a process does not accept incoming data, but you 1647and is retained for compatibility with other process types such as
1647can send outgoing data. The stopped state is cleared by 1648pipe processes. Asynchronous subprocesses never start in the
1648`continue-process' and set by `stop-process'. 1649`stopped' state. Use `stop-process' and `continue-process' to send
1650signals to stop and continue a process.
1649 1651
1650:connection-type TYPE -- TYPE is control type of device used to 1652:connection-type TYPE -- TYPE is control type of device used to
1651communicate with subprocesses. Values are `pipe' to use a pipe, `pty' 1653communicate with subprocesses. Values are `pipe' to use a pipe, `pty'
@@ -1661,6 +1663,11 @@ to the standard error of subprocess. Specifying this implies
1661`:connection-type' is set to `pipe'. If STDERR is nil, standard error 1663`:connection-type' is set to `pipe'. If STDERR is nil, standard error
1662is mixed with standard output and sent to BUFFER or FILTER. 1664is mixed with standard output and sent to BUFFER or FILTER.
1663 1665
1666:file-handler FILE-HANDLER -- If FILE-HANDLER is non-nil, then look
1667for a file name handler for the current buffer's `default-directory'
1668and invoke that file name handler to make the process. If there is no
1669such handler, proceed as if FILE-HANDLER were nil.
1670
1664usage: (make-process &rest ARGS) */) 1671usage: (make-process &rest ARGS) */)
1665 (ptrdiff_t nargs, Lisp_Object *args) 1672 (ptrdiff_t nargs, Lisp_Object *args)
1666{ 1673{
@@ -1674,6 +1681,15 @@ usage: (make-process &rest ARGS) */)
1674 /* Save arguments for process-contact and clone-process. */ 1681 /* Save arguments for process-contact and clone-process. */
1675 contact = Flist (nargs, args); 1682 contact = Flist (nargs, args);
1676 1683
1684 if (!NILP (Fplist_get (contact, QCfile_handler)))
1685 {
1686 Lisp_Object file_handler
1687 = Ffind_file_name_handler (BVAR (current_buffer, directory),
1688 Qmake_process);
1689 if (!NILP (file_handler))
1690 return CALLN (Fapply, file_handler, Qmake_process, contact);
1691 }
1692
1677 buffer = Fplist_get (contact, QCbuffer); 1693 buffer = Fplist_get (contact, QCbuffer);
1678 if (!NILP (buffer)) 1694 if (!NILP (buffer))
1679 buffer = Fget_buffer_create (buffer); 1695 buffer = Fget_buffer_create (buffer);
@@ -1731,8 +1747,10 @@ usage: (make-process &rest ARGS) */)
1731 1747
1732 if (!query_on_exit) 1748 if (!query_on_exit)
1733 XPROCESS (proc)->kill_without_query = 1; 1749 XPROCESS (proc)->kill_without_query = 1;
1734 if (tem = Fplist_get (contact, QCstop), !NILP (tem)) 1750 tem = Fplist_get (contact, QCstop);
1735 pset_command (XPROCESS (proc), Qt); 1751 /* Normal processes can't be started in a stopped state, see
1752 Bug#30460. */
1753 CHECK_TYPE (NILP (tem), Qnull, tem);
1736 1754
1737 tem = Fplist_get (contact, QCconnection_type); 1755 tem = Fplist_get (contact, QCconnection_type);
1738 if (EQ (tem, Qpty)) 1756 if (EQ (tem, Qpty))
@@ -1790,7 +1808,7 @@ usage: (make-process &rest ARGS) */)
1790 val = Vcoding_system_for_read; 1808 val = Vcoding_system_for_read;
1791 if (NILP (val)) 1809 if (NILP (val))
1792 { 1810 {
1793 ptrdiff_t nargs2 = 3 + XFIXNUM (Flength (command)); 1811 ptrdiff_t nargs2 = 3 + list_length (command);
1794 Lisp_Object tem2; 1812 Lisp_Object tem2;
1795 SAFE_ALLOCA_LISP (args2, nargs2); 1813 SAFE_ALLOCA_LISP (args2, nargs2);
1796 ptrdiff_t i = 0; 1814 ptrdiff_t i = 0;
@@ -1820,7 +1838,7 @@ usage: (make-process &rest ARGS) */)
1820 { 1838 {
1821 if (EQ (coding_systems, Qt)) 1839 if (EQ (coding_systems, Qt))
1822 { 1840 {
1823 ptrdiff_t nargs2 = 3 + XFIXNUM (Flength (command)); 1841 ptrdiff_t nargs2 = 3 + list_length (command);
1824 Lisp_Object tem2; 1842 Lisp_Object tem2;
1825 SAFE_ALLOCA_LISP (args2, nargs2); 1843 SAFE_ALLOCA_LISP (args2, nargs2);
1826 ptrdiff_t i = 0; 1844 ptrdiff_t i = 0;
@@ -2218,7 +2236,7 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
2218 unblock_input (); 2236 unblock_input ();
2219 2237
2220 if (pid < 0) 2238 if (pid < 0)
2221 report_file_errno ("Doing vfork", Qnil, vfork_errno); 2239 report_file_errno (CHILD_SETUP_ERROR_DESC, Qnil, vfork_errno);
2222 else 2240 else
2223 { 2241 {
2224 /* vfork succeeded. */ 2242 /* vfork succeeded. */
@@ -3719,6 +3737,8 @@ also nil, meaning that this process is not associated with any buffer.
3719address. The symbol `local' specifies the local host. If specified 3737address. The symbol `local' specifies the local host. If specified
3720for a server process, it must be a valid name or address for the local 3738for a server process, it must be a valid name or address for the local
3721host, and only clients connecting to that address will be accepted. 3739host, and only clients connecting to that address will be accepted.
3740`local' will use IPv4 by default, use a FAMILY of 'ipv6 to override
3741this.
3722 3742
3723:service SERVICE -- SERVICE is name of the service desired, or an 3743:service SERVICE -- SERVICE is name of the service desired, or an
3724integer specifying a port number to connect to. If SERVICE is t, 3744integer specifying a port number to connect to. If SERVICE is t,
@@ -3969,14 +3989,24 @@ usage: (make-network-process &rest ARGS) */)
3969#ifdef HAVE_LOCAL_SOCKETS 3989#ifdef HAVE_LOCAL_SOCKETS
3970 if (family != AF_LOCAL) 3990 if (family != AF_LOCAL)
3971#endif 3991#endif
3972 host = build_string ("127.0.0.1"); 3992 {
3993 if (family == AF_INET6)
3994 host = build_string ("::1");
3995 else
3996 host = build_string ("127.0.0.1");
3997 }
3973 } 3998 }
3974 else 3999 else
3975 { 4000 {
3976 if (EQ (host, Qlocal)) 4001 if (EQ (host, Qlocal))
4002 {
3977 /* Depending on setup, "localhost" may map to different IPv4 and/or 4003 /* Depending on setup, "localhost" may map to different IPv4 and/or
3978 IPv6 addresses, so it's better to be explicit (Bug#6781). */ 4004 IPv6 addresses, so it's better to be explicit (Bug#6781). */
3979 host = build_string ("127.0.0.1"); 4005 if (family == AF_INET6)
4006 host = build_string ("::1");
4007 else
4008 host = build_string ("127.0.0.1");
4009 }
3980 CHECK_STRING (host); 4010 CHECK_STRING (host);
3981 } 4011 }
3982 4012
@@ -4593,8 +4623,8 @@ DEFUN ("accept-process-output", Faccept_process_output, Saccept_process_output,
4593 0, 4, 0, 4623 0, 4, 0,
4594 doc: /* Allow any pending output from subprocesses to be read by Emacs. 4624 doc: /* Allow any pending output from subprocesses to be read by Emacs.
4595It is given to their filter functions. 4625It is given to their filter functions.
4596Optional argument PROCESS means do not return until output has been 4626Optional argument PROCESS means to return only after output is
4597received from PROCESS. 4627received from PROCESS or PROCESS closes the connection.
4598 4628
4599Optional second argument SECONDS and third argument MILLISEC 4629Optional second argument SECONDS and third argument MILLISEC
4600specify a timeout; return after that much time even if there is 4630specify a timeout; return after that much time even if there is
@@ -4606,7 +4636,8 @@ If optional fourth argument JUST-THIS-ONE is non-nil, accept output
4606from PROCESS only, suspending reading output from other processes. 4636from PROCESS only, suspending reading output from other processes.
4607If JUST-THIS-ONE is an integer, don't run any timers either. 4637If JUST-THIS-ONE is an integer, don't run any timers either.
4608Return non-nil if we received any output from PROCESS (or, if PROCESS 4638Return non-nil if we received any output from PROCESS (or, if PROCESS
4609is nil, from any process) before the timeout expired. */) 4639is nil, from any process) before the timeout expired or the
4640corresponding connection was closed. */)
4610 (Lisp_Object process, Lisp_Object seconds, Lisp_Object millisec, 4641 (Lisp_Object process, Lisp_Object seconds, Lisp_Object millisec,
4611 Lisp_Object just_this_one) 4642 Lisp_Object just_this_one)
4612{ 4643{
@@ -4726,19 +4757,24 @@ server_accept_connection (Lisp_Object server, int channel)
4726 service = Qnil; 4757 service = Qnil;
4727 Lisp_Object args[11]; 4758 Lisp_Object args[11];
4728 int nargs = 0; 4759 int nargs = 0;
4729 AUTO_STRING (procname_format_in, "%s <%d.%d.%d.%d:%d>"); 4760 #define HOST_FORMAT_IN "%d.%d.%d.%d"
4730 AUTO_STRING (procname_format_in6, "%s <[%x:%x:%x:%x:%x:%x:%x:%x]:%d>"); 4761 #define HOST_FORMAT_IN6 "%x:%x:%x:%x:%x:%x:%x:%x"
4762 AUTO_STRING (host_format_in, HOST_FORMAT_IN);
4763 AUTO_STRING (host_format_in6, HOST_FORMAT_IN6);
4764 AUTO_STRING (procname_format_in, "%s <"HOST_FORMAT_IN":%d>");
4765 AUTO_STRING (procname_format_in6, "%s <["HOST_FORMAT_IN6"]:%d>");
4731 AUTO_STRING (procname_format_default, "%s <%d>"); 4766 AUTO_STRING (procname_format_default, "%s <%d>");
4732 switch (saddr.sa.sa_family) 4767 switch (saddr.sa.sa_family)
4733 { 4768 {
4734 case AF_INET: 4769 case AF_INET:
4735 { 4770 {
4736 args[nargs++] = procname_format_in; 4771 args[nargs++] = procname_format_in;
4737 nargs++; 4772 args[nargs++] = host_format_in;
4738 unsigned char *ip = (unsigned char *)&saddr.in.sin_addr.s_addr; 4773 unsigned char *ip = (unsigned char *)&saddr.in.sin_addr.s_addr;
4739 service = make_fixnum (ntohs (saddr.in.sin_port)); 4774 service = make_fixnum (ntohs (saddr.in.sin_port));
4740 for (int i = 0; i < 4; i++) 4775 for (int i = 0; i < 4; i++)
4741 args[nargs++] = make_fixnum (ip[i]); 4776 args[nargs++] = make_fixnum (ip[i]);
4777 host = Fformat (5, args + 1);
4742 args[nargs++] = service; 4778 args[nargs++] = service;
4743 } 4779 }
4744 break; 4780 break;
@@ -4747,11 +4783,12 @@ server_accept_connection (Lisp_Object server, int channel)
4747 case AF_INET6: 4783 case AF_INET6:
4748 { 4784 {
4749 args[nargs++] = procname_format_in6; 4785 args[nargs++] = procname_format_in6;
4750 nargs++; 4786 args[nargs++] = host_format_in6;
4751 DECLARE_POINTER_ALIAS (ip6, uint16_t, &saddr.in6.sin6_addr); 4787 DECLARE_POINTER_ALIAS (ip6, uint16_t, &saddr.in6.sin6_addr);
4752 service = make_fixnum (ntohs (saddr.in.sin_port)); 4788 service = make_fixnum (ntohs (saddr.in.sin_port));
4753 for (int i = 0; i < 8; i++) 4789 for (int i = 0; i < 8; i++)
4754 args[nargs++] = make_fixnum (ip6[i]); 4790 args[nargs++] = make_fixnum (ip6[i]);
4791 host = Fformat (9, args + 1);
4755 args[nargs++] = service; 4792 args[nargs++] = service;
4756 } 4793 }
4757 break; 4794 break;
@@ -5825,7 +5862,8 @@ read_and_dispose_of_process_output (struct Lisp_Process *p, char *chars,
5825 5862
5826/* Read pending output from the process channel, 5863/* Read pending output from the process channel,
5827 starting with our buffered-ahead character if we have one. 5864 starting with our buffered-ahead character if we have one.
5828 Yield number of decoded characters read. 5865 Yield number of decoded characters read,
5866 or -1 (setting errno) if there is a read error.
5829 5867
5830 This function reads at most 4096 characters. 5868 This function reads at most 4096 characters.
5831 If you want to read all available subprocess output, 5869 If you want to read all available subprocess output,
@@ -5855,8 +5893,10 @@ read_process_output (Lisp_Object proc, int channel)
5855 if (DATAGRAM_CHAN_P (channel)) 5893 if (DATAGRAM_CHAN_P (channel))
5856 { 5894 {
5857 socklen_t len = datagram_address[channel].len; 5895 socklen_t len = datagram_address[channel].len;
5858 nbytes = recvfrom (channel, chars + carryover, readmax, 5896 do
5859 0, datagram_address[channel].sa, &len); 5897 nbytes = recvfrom (channel, chars + carryover, readmax,
5898 0, datagram_address[channel].sa, &len);
5899 while (nbytes < 0 && errno == EINTR);
5860 } 5900 }
5861 else 5901 else
5862#endif 5902#endif
@@ -5906,8 +5946,6 @@ read_process_output (Lisp_Object proc, int channel)
5906 5946
5907 p->decoding_carryover = 0; 5947 p->decoding_carryover = 0;
5908 5948
5909 /* At this point, NBYTES holds number of bytes just received
5910 (including the one in proc_buffered_char[channel]). */
5911 if (nbytes <= 0) 5949 if (nbytes <= 0)
5912 { 5950 {
5913 if (nbytes < 0 || coding->mode & CODING_MODE_LAST_BLOCK) 5951 if (nbytes < 0 || coding->mode & CODING_MODE_LAST_BLOCK)
@@ -5915,6 +5953,9 @@ read_process_output (Lisp_Object proc, int channel)
5915 coding->mode |= CODING_MODE_LAST_BLOCK; 5953 coding->mode |= CODING_MODE_LAST_BLOCK;
5916 } 5954 }
5917 5955
5956 /* At this point, NBYTES holds number of bytes just received
5957 (including the one in proc_buffered_char[channel]). */
5958
5918 /* Ignore carryover, it's been added by a previous iteration already. */ 5959 /* Ignore carryover, it's been added by a previous iteration already. */
5919 p->nbytes_read += nbytes; 5960 p->nbytes_read += nbytes;
5920 5961
@@ -6357,9 +6398,17 @@ send_process (Lisp_Object proc, const char *buf, ptrdiff_t len,
6357#ifdef DATAGRAM_SOCKETS 6398#ifdef DATAGRAM_SOCKETS
6358 if (DATAGRAM_CHAN_P (outfd)) 6399 if (DATAGRAM_CHAN_P (outfd))
6359 { 6400 {
6360 rv = sendto (outfd, cur_buf, cur_len, 6401 while (true)
6361 0, datagram_address[outfd].sa, 6402 {
6362 datagram_address[outfd].len); 6403 rv = sendto (outfd, cur_buf, cur_len, 0,
6404 datagram_address[outfd].sa,
6405 datagram_address[outfd].len);
6406 if (! (rv < 0 && errno == EINTR))
6407 break;
6408 if (pending_signals)
6409 process_pending_signals ();
6410 }
6411
6363 if (rv >= 0) 6412 if (rv >= 0)
6364 written = rv; 6413 written = rv;
6365 else if (errno == EMSGSIZE) 6414 else if (errno == EMSGSIZE)
@@ -6449,9 +6498,11 @@ DEFUN ("process-send-region", Fprocess_send_region, Sprocess_send_region,
6449PROCESS may be a process, a buffer, the name of a process or buffer, or 6498PROCESS may be a process, a buffer, the name of a process or buffer, or
6450nil, indicating the current buffer's process. 6499nil, indicating the current buffer's process.
6451Called from program, takes three arguments, PROCESS, START and END. 6500Called from program, takes three arguments, PROCESS, START and END.
6452If the region is more than 500 characters long, 6501If the region is larger than the input buffer of the process (the
6453it is sent in several bunches. This may happen even for shorter regions. 6502length of which depends on the process connection type and the
6454Output from processes can arrive in between bunches. 6503operating system), it is sent in several bunches. This may happen
6504even for shorter regions. Output from processes can arrive in between
6505bunches.
6455 6506
6456If PROCESS is a non-blocking network process that hasn't been fully 6507If PROCESS is a non-blocking network process that hasn't been fully
6457set up yet, this function will block until socket setup has completed. */) 6508set up yet, this function will block until socket setup has completed. */)
@@ -6482,9 +6533,10 @@ DEFUN ("process-send-string", Fprocess_send_string, Sprocess_send_string,
6482 doc: /* Send PROCESS the contents of STRING as input. 6533 doc: /* Send PROCESS the contents of STRING as input.
6483PROCESS may be a process, a buffer, the name of a process or buffer, or 6534PROCESS may be a process, a buffer, the name of a process or buffer, or
6484nil, indicating the current buffer's process. 6535nil, indicating the current buffer's process.
6485If STRING is more than 500 characters long, 6536If STRING is larger than the input buffer of the process (the length
6486it is sent in several bunches. This may happen even for shorter strings. 6537of which depends on the process connection type and the operating
6487Output from processes can arrive in between bunches. 6538system), it is sent in several bunches. This may happen even for
6539shorter strings. Output from processes can arrive in between bunches.
6488 6540
6489If PROCESS is a non-blocking network process that hasn't been fully 6541If PROCESS is a non-blocking network process that hasn't been fully
6490set up yet, this function will block until socket setup has completed. */) 6542set up yet, this function will block until socket setup has completed. */)
@@ -8010,9 +8062,7 @@ init_process_emacs (int sockfd)
8010 8062
8011 inhibit_sentinels = 0; 8063 inhibit_sentinels = 0;
8012 8064
8013#ifndef CANNOT_DUMP 8065 if (!will_dump_with_unexec_p ())
8014 if (! noninteractive || initialized)
8015#endif
8016 { 8066 {
8017#if defined HAVE_GLIB && !defined WINDOWSNT 8067#if defined HAVE_GLIB && !defined WINDOWSNT
8018 /* Tickle glib's child-handling code. Ask glib to wait for Emacs itself; 8068 /* Tickle glib's child-handling code. Ask glib to wait for Emacs itself;
@@ -8098,6 +8148,8 @@ init_process_emacs (int sockfd)
8098void 8148void
8099syms_of_process (void) 8149syms_of_process (void)
8100{ 8150{
8151 DEFSYM (Qmake_process, "make-process");
8152
8101#ifdef subprocesses 8153#ifdef subprocesses
8102 8154
8103 DEFSYM (Qprocessp, "processp"); 8155 DEFSYM (Qprocessp, "processp");
@@ -8138,6 +8190,7 @@ syms_of_process (void)
8138 DEFSYM (Qreal, "real"); 8190 DEFSYM (Qreal, "real");
8139 DEFSYM (Qnetwork, "network"); 8191 DEFSYM (Qnetwork, "network");
8140 DEFSYM (Qserial, "serial"); 8192 DEFSYM (Qserial, "serial");
8193 DEFSYM (QCfile_handler, ":file-handler");
8141 DEFSYM (QCbuffer, ":buffer"); 8194 DEFSYM (QCbuffer, ":buffer");
8142 DEFSYM (QChost, ":host"); 8195 DEFSYM (QChost, ":host");
8143 DEFSYM (QCservice, ":service"); 8196 DEFSYM (QCservice, ":service");
@@ -8250,6 +8303,8 @@ returns non-`nil'. */);
8250 "internal-default-interrupt-process"); 8303 "internal-default-interrupt-process");
8251 DEFSYM (Qinterrupt_process_functions, "interrupt-process-functions"); 8304 DEFSYM (Qinterrupt_process_functions, "interrupt-process-functions");
8252 8305
8306 DEFSYM (Qnull, "null");
8307
8253 defsubr (&Sprocessp); 8308 defsubr (&Sprocessp);
8254 defsubr (&Sget_process); 8309 defsubr (&Sget_process);
8255 defsubr (&Sdelete_process); 8310 defsubr (&Sdelete_process);