aboutsummaryrefslogtreecommitdiffstats
path: root/src/process.c
diff options
context:
space:
mode:
authorLars Ingebrigtsen2016-02-01 00:27:07 +0100
committerLars Ingebrigtsen2016-02-01 00:27:07 +0100
commit4ff81f8fac1270a829bb2725911bf6b614711257 (patch)
tree5c3a640b436037a3d2f6a4e8bb569c01cc9a3599 /src/process.c
parent9972329387b7f1e1a9b1c8713a1d5bbdd032de12 (diff)
downloademacs-4ff81f8fac1270a829bb2725911bf6b614711257.tar.gz
emacs-4ff81f8fac1270a829bb2725911bf6b614711257.zip
Further TLS async work
* gnutls.c (boot_error): New function to either signal an error or return an error code. (Fgnutls_boot): Don't signal errors when running asynchronously. * process.h (pset_status): Move here from process.c to be able to use from gnutls.c. * process.c (connect_network_socket): Do the TLS boot here when running asynchronously. (wait_reading_process_output): Rework the dns_processes handling for more safety.
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c75
1 files changed, 54 insertions, 21 deletions
diff --git a/src/process.c b/src/process.c
index 55264058340..afb98256ba5 100644
--- a/src/process.c
+++ b/src/process.c
@@ -385,11 +385,6 @@ pset_sentinel (struct Lisp_Process *p, Lisp_Object val)
385 p->sentinel = NILP (val) ? Qinternal_default_process_sentinel : val; 385 p->sentinel = NILP (val) ? Qinternal_default_process_sentinel : val;
386} 386}
387static void 387static void
388pset_status (struct Lisp_Process *p, Lisp_Object val)
389{
390 p->status = val;
391}
392static void
393pset_tty_name (struct Lisp_Process *p, Lisp_Object val) 388pset_tty_name (struct Lisp_Process *p, Lisp_Object val)
394{ 389{
395 p->tty_name = val; 390 p->tty_name = val;
@@ -3309,11 +3304,17 @@ void connect_network_socket (Lisp_Object proc, Lisp_Object ip_addresses)
3309 3304
3310#ifdef HAVE_GNUTLS 3305#ifdef HAVE_GNUTLS
3311 if (!NILP (p->gnutls_async_parameters) && p->is_non_blocking_client) { 3306 if (!NILP (p->gnutls_async_parameters) && p->is_non_blocking_client) {
3312 Fgnutls_boot (proc, Fcar (p->gnutls_async_parameters), 3307 Lisp_Object params = p->gnutls_async_parameters, boot = Qnil;
3313 Fcdr (p->gnutls_async_parameters)); 3308
3314 p->gnutls_async_parameters = Qnil; 3309 p->gnutls_async_parameters = Qnil;
3310 boot = Fgnutls_boot (proc, Fcar (params), Fcdr (params));
3311 if (STRINGP (boot)) {
3312 pset_status (p, Qfailed);
3313 deactivate_process (proc);
3314 }
3315 } 3315 }
3316#endif 3316#endif
3317
3317} 3318}
3318 3319
3319 3320
@@ -3798,6 +3799,9 @@ usage: (make-network-process &rest ARGS) */)
3798#ifdef HAVE_GETADDRINFO_A 3799#ifdef HAVE_GETADDRINFO_A
3799 p->dns_requests = NULL; 3800 p->dns_requests = NULL;
3800#endif 3801#endif
3802#ifdef HAVE_GNUTLS
3803 p->gnutls_async_parameters = Qnil;
3804#endif
3801 3805
3802 unbind_to (count, Qnil); 3806 unbind_to (count, Qnil);
3803 3807
@@ -4545,13 +4549,12 @@ server_accept_connection (Lisp_Object server, int channel)
4545} 4549}
4546 4550
4547#ifdef HAVE_GETADDRINFO_A 4551#ifdef HAVE_GETADDRINFO_A
4548static int 4552static Lisp_Object
4549check_for_dns (Lisp_Object proc) 4553check_for_dns (Lisp_Object proc)
4550{ 4554{
4551 struct Lisp_Process *p = XPROCESS (proc); 4555 struct Lisp_Process *p = XPROCESS (proc);
4552 Lisp_Object ip_addresses = Qnil; 4556 Lisp_Object ip_addresses = Qnil;
4553 int ret = 0; 4557 int ret = 0;
4554 int connect = 0;
4555 4558
4556 /* Sanity check. */ 4559 /* Sanity check. */
4557 if (! p->dns_requests) 4560 if (! p->dns_requests)
@@ -4559,7 +4562,7 @@ check_for_dns (Lisp_Object proc)
4559 4562
4560 ret = gai_error (p->dns_requests[0]); 4563 ret = gai_error (p->dns_requests[0]);
4561 if (ret == EAI_INPROGRESS) 4564 if (ret == EAI_INPROGRESS)
4562 return 0; 4565 return Qt;
4563 4566
4564 /* We got a response. */ 4567 /* We got a response. */
4565 if (ret == 0) 4568 if (ret == 0)
@@ -4575,10 +4578,13 @@ check_for_dns (Lisp_Object proc)
4575 4578
4576 ip_addresses = Fnreverse (ip_addresses); 4579 ip_addresses = Fnreverse (ip_addresses);
4577 freeaddrinfo (p->dns_requests[0]->ar_result); 4580 freeaddrinfo (p->dns_requests[0]->ar_result);
4578 connect = 1;
4579 } 4581 }
4582 /* The DNS lookup failed. */
4580 else 4583 else
4581 pset_status (p, Qfailed); 4584 {
4585 pset_status (p, Qfailed);
4586 deactivate_process (proc);
4587 }
4582 4588
4583 xfree ((void *)p->dns_requests[0]->ar_request); 4589 xfree ((void *)p->dns_requests[0]->ar_request);
4584 xfree ((void *)p->dns_requests[0]->ar_name); 4590 xfree ((void *)p->dns_requests[0]->ar_name);
@@ -4587,10 +4593,7 @@ check_for_dns (Lisp_Object proc)
4587 xfree (p->dns_requests); 4593 xfree (p->dns_requests);
4588 p->dns_requests = NULL; 4594 p->dns_requests = NULL;
4589 4595
4590 if (connect) 4596 return ip_addresses;
4591 connect_network_socket (proc, ip_addresses);
4592
4593 return 1;
4594} 4597}
4595#endif /* HAVE_GETADDRINFO_A */ 4598#endif /* HAVE_GETADDRINFO_A */
4596 4599
@@ -4722,18 +4725,47 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4722#ifdef HAVE_GETADDRINFO_A 4725#ifdef HAVE_GETADDRINFO_A
4723 if (!NILP (dns_processes)) 4726 if (!NILP (dns_processes))
4724 { 4727 {
4725 Lisp_Object dns_list = dns_processes, dns; 4728 Lisp_Object dns_list = dns_processes, dns, ip_addresses,
4729 answers = Qnil, answer, new = Qnil;
4726 struct Lisp_Process *p; 4730 struct Lisp_Process *p;
4727 4731
4732 /* This is programmed in a somewhat awkward fashion because
4733 calling connect_network_socket might make us end up back
4734 here again, and we would have a race condition with
4735 segfaults. So first go through all pending requests and see
4736 whether we got any answers. */
4728 while (!NILP (dns_list)) 4737 while (!NILP (dns_list))
4729 { 4738 {
4730 dns = Fcar (dns_list); 4739 dns = Fcar (dns_list);
4731 dns_list = Fcdr (dns_list); 4740 dns_list = Fcdr (dns_list);
4732 p = XPROCESS (dns); 4741 p = XPROCESS (dns);
4733 if (p && p->dns_requests && 4742 if (p && p->dns_requests)
4734 (! wait_proc || p == wait_proc) && 4743 {
4735 check_for_dns (dns)) 4744 if (! wait_proc || p == wait_proc)
4736 dns_processes = Fdelq (dns, dns_processes); 4745 {
4746 ip_addresses = check_for_dns (dns);
4747 if (EQ (ip_addresses, Qt))
4748 new = Fcons (dns, new);
4749 else
4750 answers = Fcons (Fcons (dns, ip_addresses), answers);
4751 }
4752 else
4753 new = Fcons (dns, new);
4754 }
4755 }
4756
4757 /* Replace with the list of DNS requests still not responded
4758 to. */
4759 dns_processes = new;
4760
4761 /* Then continue the connection for the successful
4762 requests. */
4763 while (!NILP (answers))
4764 {
4765 answer = Fcar (answers);
4766 answers = Fcdr (answers);
4767 if (!NILP (Fcdr (answer)))
4768 connect_network_socket (Fcar (answer), Fcdr (answer));
4737 } 4769 }
4738 } 4770 }
4739#endif /* HAVE_GETADDRINFO_A */ 4771#endif /* HAVE_GETADDRINFO_A */
@@ -7685,6 +7717,7 @@ syms_of_process (void)
7685 7717
7686 staticpro (&Vprocess_alist); 7718 staticpro (&Vprocess_alist);
7687 staticpro (&deleted_pid_list); 7719 staticpro (&deleted_pid_list);
7720 staticpro (&dns_processes);
7688 7721
7689#endif /* subprocesses */ 7722#endif /* subprocesses */
7690 7723