summaryrefslogtreecommitdiff
path: root/src/process.c
diff options
context:
space:
mode:
authorAndrea Corallo <akrl@sdf.org>2020-12-27 17:54:57 +0100
committerAndrea Corallo <akrl@sdf.org>2020-12-27 17:54:57 +0100
commit8fb94630136700aa4e74c7fc212b019d2db380ae (patch)
tree69b3938a89f450509a7001f45ba3acca057fb40d /src/process.c
parent271fb8a269aff924070b188f23355d0c368356dd (diff)
parentdf882c9701755e2ae063f05d3381de14ae09951e (diff)
downloademacs-8fb94630136700aa4e74c7fc212b019d2db380ae.tar.gz
emacs-8fb94630136700aa4e74c7fc212b019d2db380ae.tar.bz2
emacs-8fb94630136700aa4e74c7fc212b019d2db380ae.zip
Merge remote-tracking branch 'savannah/master' into HEAD
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c157
1 files changed, 14 insertions, 143 deletions
diff --git a/src/process.c b/src/process.c
index 15b4a23784e..28ab15c9038 100644
--- a/src/process.c
+++ b/src/process.c
@@ -2047,13 +2047,12 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
{
struct Lisp_Process *p = XPROCESS (process);
int inchannel, outchannel;
- pid_t pid;
+ pid_t pid = -1;
int vfork_errno;
int forkin, forkout, forkerr = -1;
bool pty_flag = 0;
char pty_name[PTY_NAME_SIZE];
Lisp_Object lisp_pty_name = Qnil;
- sigset_t oldset;
inchannel = outchannel = -1;
@@ -2128,156 +2127,22 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
/* This may signal an error. */
setup_process_coding_systems (process);
- char *const *env = make_environment_block (current_dir);
-
- block_input ();
- block_child_signal (&oldset);
-
-#ifndef WINDOWSNT
- /* vfork, and prevent local vars from being clobbered by the vfork. */
- Lisp_Object volatile current_dir_volatile = current_dir;
- Lisp_Object volatile lisp_pty_name_volatile = lisp_pty_name;
- char **volatile new_argv_volatile = new_argv;
- int volatile forkin_volatile = forkin;
- int volatile forkout_volatile = forkout;
- int volatile forkerr_volatile = forkerr;
- struct Lisp_Process *p_volatile = p;
- char *const *volatile env_volatile = env;
-
-#ifdef DARWIN_OS
- /* Darwin doesn't let us run setsid after a vfork, so use fork when
- necessary. Also, reset SIGCHLD handling after a vfork, as
- apparently macOS can mistakenly deliver SIGCHLD to the child. */
- if (pty_flag)
- pid = fork ();
- else
- {
- pid = vfork ();
- if (pid == 0)
- signal (SIGCHLD, SIG_DFL);
- }
-#else
- pid = vfork ();
-#endif
-
- current_dir = current_dir_volatile;
- lisp_pty_name = lisp_pty_name_volatile;
- new_argv = new_argv_volatile;
- forkin = forkin_volatile;
- forkout = forkout_volatile;
- forkerr = forkerr_volatile;
- p = p_volatile;
- env = env_volatile;
+ char **env = make_environment_block (current_dir);
pty_flag = p->pty_flag;
+ eassert (pty_flag == ! NILP (lisp_pty_name));
- if (pid == 0)
-#endif /* not WINDOWSNT */
- {
- /* Make the pty be the controlling terminal of the process. */
-#ifdef HAVE_PTYS
- dissociate_controlling_tty ();
-
- /* Make the pty's terminal the controlling terminal. */
- if (pty_flag && forkin >= 0)
- {
-#ifdef TIOCSCTTY
- /* We ignore the return value
- because faith@cs.unc.edu says that is necessary on Linux. */
- ioctl (forkin, TIOCSCTTY, 0);
-#endif
- }
-#if defined (LDISC1)
- if (pty_flag && forkin >= 0)
- {
- struct termios t;
- tcgetattr (forkin, &t);
- t.c_lflag = LDISC1;
- if (tcsetattr (forkin, TCSANOW, &t) < 0)
- emacs_perror ("create_process/tcsetattr LDISC1");
- }
-#else
-#if defined (NTTYDISC) && defined (TIOCSETD)
- if (pty_flag && forkin >= 0)
- {
- /* Use new line discipline. */
- int ldisc = NTTYDISC;
- ioctl (forkin, TIOCSETD, &ldisc);
- }
-#endif
-#endif
-
-#if !defined (DONT_REOPEN_PTY)
-/*** There is a suggestion that this ought to be a
- conditional on TIOCSPGRP, or !defined TIOCSCTTY.
- Trying the latter gave the wrong results on Debian GNU/Linux 1.1;
- that system does seem to need this code, even though
- both TIOCSCTTY is defined. */
- /* Now close the pty (if we had it open) and reopen it.
- This makes the pty the controlling terminal of the subprocess. */
- if (pty_flag)
- {
+ vfork_errno
+ = emacs_spawn (&pid, forkin, forkout, forkerr, new_argv, env,
+ SSDATA (current_dir),
+ pty_flag ? SSDATA (lisp_pty_name) : NULL);
- /* I wonder if emacs_close (emacs_open (SSDATA (lisp_pty_name), ...))
- would work? */
- if (forkin >= 0)
- emacs_close (forkin);
- forkout = forkin = emacs_open (SSDATA (lisp_pty_name), O_RDWR, 0);
+ eassert ((vfork_errno == 0) == (0 < pid));
- if (forkin < 0)
- {
- emacs_perror (SSDATA (lisp_pty_name));
- _exit (EXIT_CANCELED);
- }
-
- }
-#endif /* not DONT_REOPEN_PTY */
-
-#ifdef SETUP_SLAVE_PTY
- if (pty_flag)
- {
- SETUP_SLAVE_PTY;
- }
-#endif /* SETUP_SLAVE_PTY */
-#endif /* HAVE_PTYS */
-
- signal (SIGINT, SIG_DFL);
- signal (SIGQUIT, SIG_DFL);
-#ifdef SIGPROF
- signal (SIGPROF, SIG_DFL);
-#endif
-
- /* Emacs ignores SIGPIPE, but the child should not. */
- signal (SIGPIPE, SIG_DFL);
-
- /* Stop blocking SIGCHLD in the child. */
- unblock_child_signal (&oldset);
-
- if (pty_flag)
- child_setup_tty (forkout);
-
- if (forkerr < 0)
- forkerr = forkout;
-#ifdef WINDOWSNT
- pid = child_setup (forkin, forkout, forkerr, new_argv, env,
- SSDATA (current_dir));
-#else /* not WINDOWSNT */
- child_setup (forkin, forkout, forkerr, new_argv, env,
- SSDATA (current_dir));
-#endif /* not WINDOWSNT */
- }
-
- /* Back in the parent process. */
-
- vfork_errno = errno;
p->pid = pid;
if (pid >= 0)
p->alive = 1;
- /* Stop blocking in the parent. */
- unblock_child_signal (&oldset);
- unblock_input ();
-
/* Environment block no longer needed. */
unbind_to (count, Qnil);
@@ -4647,6 +4512,12 @@ network_lookup_address_info_1 (Lisp_Object host, const char *service,
if (STRING_MULTIBYTE (host) && SBYTES (host) != SCHARS (host))
error ("Non-ASCII hostname %s detected, please use puny-encode-domain",
SSDATA (host));
+
+#ifdef WINDOWSNT
+ /* Ensure socket support is loaded if available. */
+ init_winsock (TRUE);
+#endif
+
ret = getaddrinfo (SSDATA (host), service, hints, res);
if (ret)
{