aboutsummaryrefslogtreecommitdiffstats
path: root/src/process.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c280
1 files changed, 195 insertions, 85 deletions
diff --git a/src/process.c b/src/process.c
index 1a884357b86..f2f33a9eafc 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-2011 3Copyright (C) 1985-1988, 1993-1996, 1998-1999, 2001-2012
4 Free Software Foundation, Inc. 4 Free Software Foundation, Inc.
5 5
6This file is part of GNU Emacs. 6This file is part of GNU Emacs.
@@ -54,10 +54,21 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
54#endif 54#endif
55 55
56#include <sys/ioctl.h> 56#include <sys/ioctl.h>
57#if defined(HAVE_NET_IF_H) 57#if defined (HAVE_NET_IF_H)
58#include <net/if.h> 58#include <net/if.h>
59#endif /* HAVE_NET_IF_H */ 59#endif /* HAVE_NET_IF_H */
60 60
61#if defined (HAVE_IFADDRS_H)
62/* Must be after net/if.h */
63#include <ifaddrs.h>
64
65/* We only use structs from this header when we use getifaddrs. */
66#if defined (HAVE_NET_IF_DL_H)
67#include <net/if_dl.h>
68#endif
69
70#endif
71
61#ifdef NEED_BSDTTY 72#ifdef NEED_BSDTTY
62#include <bsdtty.h> 73#include <bsdtty.h>
63#endif 74#endif
@@ -245,7 +256,7 @@ static void create_pty (Lisp_Object);
245 256
246/* If we support a window system, turn on the code to poll periodically 257/* If we support a window system, turn on the code to poll periodically
247 to detect C-g. It isn't actually used when doing interrupt input. */ 258 to detect C-g. It isn't actually used when doing interrupt input. */
248#ifdef HAVE_WINDOW_SYSTEM 259#if defined (HAVE_WINDOW_SYSTEM) && !defined (USE_ASYNC_EVENTS)
249#define POLL_FOR_INPUT 260#define POLL_FOR_INPUT
250#endif 261#endif
251 262
@@ -605,8 +616,8 @@ make_process (Lisp_Object name)
605{ 616{
606 register Lisp_Object val, tem, name1; 617 register Lisp_Object val, tem, name1;
607 register struct Lisp_Process *p; 618 register struct Lisp_Process *p;
608 char suffix[10]; 619 char suffix[sizeof "<>" + INT_STRLEN_BOUND (printmax_t)];
609 register int i; 620 printmax_t i;
610 621
611 p = allocate_process (); 622 p = allocate_process ();
612 623
@@ -631,6 +642,9 @@ make_process (Lisp_Object name)
631 p->gnutls_initstage = GNUTLS_STAGE_EMPTY; 642 p->gnutls_initstage = GNUTLS_STAGE_EMPTY;
632 p->gnutls_log_level = 0; 643 p->gnutls_log_level = 0;
633 p->gnutls_p = 0; 644 p->gnutls_p = 0;
645 p->gnutls_state = NULL;
646 p->gnutls_x509_cred = NULL;
647 p->gnutls_anon_cred = NULL;
634#endif 648#endif
635 649
636 /* If name is already in use, modify it until it is unused. */ 650 /* If name is already in use, modify it until it is unused. */
@@ -640,7 +654,7 @@ make_process (Lisp_Object name)
640 { 654 {
641 tem = Fget_process (name1); 655 tem = Fget_process (name1);
642 if (NILP (tem)) break; 656 if (NILP (tem)) break;
643 sprintf (suffix, "<%d>", i); 657 sprintf (suffix, "<%"pMd">", i);
644 name1 = concat2 (name, build_string (suffix)); 658 name1 = concat2 (name, build_string (suffix));
645 } 659 }
646 name = name1; 660 name = name1;
@@ -1400,7 +1414,7 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
1400 val = XCDR (Vdefault_process_coding_system); 1414 val = XCDR (Vdefault_process_coding_system);
1401 } 1415 }
1402 XPROCESS (proc)->encode_coding_system = val; 1416 XPROCESS (proc)->encode_coding_system = val;
1403 /* Note: At this momemnt, the above coding system may leave 1417 /* Note: At this moment, the above coding system may leave
1404 text-conversion or eol-conversion unspecified. They will be 1418 text-conversion or eol-conversion unspecified. They will be
1405 decided after we read output from the process and decode it by 1419 decided after we read output from the process and decode it by
1406 some coding system, or just before we actually send a text to 1420 some coding system, or just before we actually send a text to
@@ -1507,8 +1521,9 @@ start_process_unwind (Lisp_Object proc)
1507 if (!PROCESSP (proc)) 1521 if (!PROCESSP (proc))
1508 abort (); 1522 abort ();
1509 1523
1510 /* Was PROC started successfully? */ 1524 /* Was PROC started successfully?
1511 if (XPROCESS (proc)->pid == -1) 1525 -2 is used for a pty with no process, eg for gdb. */
1526 if (XPROCESS (proc)->pid <= 0 && XPROCESS (proc)->pid != -2)
1512 remove_process (proc); 1527 remove_process (proc);
1513 1528
1514 return Qnil; 1529 return Qnil;
@@ -1632,7 +1647,6 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1632 1647
1633 XPROCESS (process)->pty_flag = pty_flag; 1648 XPROCESS (process)->pty_flag = pty_flag;
1634 XPROCESS (process)->status = Qrun; 1649 XPROCESS (process)->status = Qrun;
1635 setup_process_coding_systems (process);
1636 1650
1637 /* Delay interrupts until we have a chance to store 1651 /* Delay interrupts until we have a chance to store
1638 the new fork's pid in its process structure */ 1652 the new fork's pid in its process structure */
@@ -1667,6 +1681,10 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1667 processes to get their return values scrambled. */ 1681 processes to get their return values scrambled. */
1668 XPROCESS (process)->pid = -1; 1682 XPROCESS (process)->pid = -1;
1669 1683
1684 /* This must be called after the above line because it may signal an
1685 error. */
1686 setup_process_coding_systems (process);
1687
1670 BLOCK_INPUT; 1688 BLOCK_INPUT;
1671 1689
1672 { 1690 {
@@ -2907,7 +2925,7 @@ usage: (make-network-process &rest ARGS) */)
2907 { 2925 {
2908 /* Don't support network sockets when non-blocking mode is 2926 /* Don't support network sockets when non-blocking mode is
2909 not available, since a blocked Emacs is not useful. */ 2927 not available, since a blocked Emacs is not useful. */
2910#if !defined(O_NONBLOCK) && !defined(O_NDELAY) 2928#if !defined (O_NONBLOCK) && !defined (O_NDELAY)
2911 error ("Network servers not supported"); 2929 error ("Network servers not supported");
2912#else 2930#else
2913 is_server = 1; 2931 is_server = 1;
@@ -2961,7 +2979,7 @@ usage: (make-network-process &rest ARGS) */)
2961 tem = Fplist_get (contact, QCfamily); 2979 tem = Fplist_get (contact, QCfamily);
2962 if (NILP (tem)) 2980 if (NILP (tem))
2963 { 2981 {
2964#if defined(HAVE_GETADDRINFO) && defined(AF_INET6) 2982#if defined (HAVE_GETADDRINFO) && defined (AF_INET6)
2965 family = AF_UNSPEC; 2983 family = AF_UNSPEC;
2966#else 2984#else
2967 family = AF_INET; 2985 family = AF_INET;
@@ -3103,7 +3121,7 @@ usage: (make-network-process &rest ARGS) */)
3103 { 3121 {
3104 struct hostent *host_info_ptr; 3122 struct hostent *host_info_ptr;
3105 3123
3106 /* gethostbyname may fail with TRY_AGAIN, but we don't honour that, 3124 /* gethostbyname may fail with TRY_AGAIN, but we don't honor that,
3107 as it may `hang' Emacs for a very long time. */ 3125 as it may `hang' Emacs for a very long time. */
3108 immediate_quit = 1; 3126 immediate_quit = 1;
3109 QUIT; 3127 QUIT;
@@ -3457,7 +3475,7 @@ usage: (make-network-process &rest ARGS) */)
3457 3475
3458 { 3476 {
3459 /* Setup coding systems for communicating with the network stream. */ 3477 /* Setup coding systems for communicating with the network stream. */
3460 struct gcpro inner_gcpro1; 3478 struct gcpro gcpro1;
3461 /* Qt denotes we have not yet called Ffind_operation_coding_system. */ 3479 /* Qt denotes we have not yet called Ffind_operation_coding_system. */
3462 Lisp_Object coding_systems = Qt; 3480 Lisp_Object coding_systems = Qt;
3463 Lisp_Object fargs[5], val; 3481 Lisp_Object fargs[5], val;
@@ -3474,7 +3492,7 @@ usage: (make-network-process &rest ARGS) */)
3474 || (NILP (buffer) && NILP (BVAR (&buffer_defaults, enable_multibyte_characters)))) 3492 || (NILP (buffer) && NILP (BVAR (&buffer_defaults, enable_multibyte_characters))))
3475 /* We dare not decode end-of-line format by setting VAL to 3493 /* We dare not decode end-of-line format by setting VAL to
3476 Qraw_text, because the existing Emacs Lisp libraries 3494 Qraw_text, because the existing Emacs Lisp libraries
3477 assume that they receive bare code including a sequene of 3495 assume that they receive bare code including a sequence of
3478 CR LF. */ 3496 CR LF. */
3479 val = Qnil; 3497 val = Qnil;
3480 else 3498 else
@@ -3485,9 +3503,9 @@ usage: (make-network-process &rest ARGS) */)
3485 { 3503 {
3486 fargs[0] = Qopen_network_stream, fargs[1] = name, 3504 fargs[0] = Qopen_network_stream, fargs[1] = name,
3487 fargs[2] = buffer, fargs[3] = host, fargs[4] = service; 3505 fargs[2] = buffer, fargs[3] = host, fargs[4] = service;
3488 GCPRO1_VAR (proc, inner_gcpro); 3506 GCPRO1 (proc);
3489 coding_systems = Ffind_operation_coding_system (5, fargs); 3507 coding_systems = Ffind_operation_coding_system (5, fargs);
3490 UNGCPRO_VAR (inner_gcpro); 3508 UNGCPRO;
3491 } 3509 }
3492 if (CONSP (coding_systems)) 3510 if (CONSP (coding_systems))
3493 val = XCAR (coding_systems); 3511 val = XCAR (coding_systems);
@@ -3518,9 +3536,9 @@ usage: (make-network-process &rest ARGS) */)
3518 { 3536 {
3519 fargs[0] = Qopen_network_stream, fargs[1] = name, 3537 fargs[0] = Qopen_network_stream, fargs[1] = name,
3520 fargs[2] = buffer, fargs[3] = host, fargs[4] = service; 3538 fargs[2] = buffer, fargs[3] = host, fargs[4] = service;
3521 GCPRO1_VAR (proc, inner_gcpro); 3539 GCPRO1 (proc);
3522 coding_systems = Ffind_operation_coding_system (5, fargs); 3540 coding_systems = Ffind_operation_coding_system (5, fargs);
3523 UNGCPRO_VAR (inner_gcpro); 3541 UNGCPRO;
3524 } 3542 }
3525 } 3543 }
3526 if (CONSP (coding_systems)) 3544 if (CONSP (coding_systems))
@@ -3546,7 +3564,7 @@ usage: (make-network-process &rest ARGS) */)
3546} 3564}
3547 3565
3548 3566
3549#if defined(HAVE_NET_IF_H) 3567#if defined (HAVE_NET_IF_H)
3550 3568
3551#ifdef SIOCGIFCONF 3569#ifdef SIOCGIFCONF
3552DEFUN ("network-interface-list", Fnetwork_interface_list, Snetwork_interface_list, 0, 0, 0, 3570DEFUN ("network-interface-list", Fnetwork_interface_list, Snetwork_interface_list, 0, 0, 0,
@@ -3557,46 +3575,53 @@ format; see the description of ADDRESS in `make-network-process'. */)
3557 (void) 3575 (void)
3558{ 3576{
3559 struct ifconf ifconf; 3577 struct ifconf ifconf;
3560 struct ifreq *ifreqs = NULL; 3578 struct ifreq *ifreq;
3561 int ifaces = 0; 3579 void *buf = NULL;
3562 int buf_size, s; 3580 ptrdiff_t buf_size = 512;
3581 int s, i;
3563 Lisp_Object res; 3582 Lisp_Object res;
3564 3583
3565 s = socket (AF_INET, SOCK_STREAM, 0); 3584 s = socket (AF_INET, SOCK_STREAM, 0);
3566 if (s < 0) 3585 if (s < 0)
3567 return Qnil; 3586 return Qnil;
3568 3587
3569 again: 3588 do
3570 ifaces += 25;
3571 buf_size = ifaces * sizeof (ifreqs[0]);
3572 ifreqs = (struct ifreq *)xrealloc(ifreqs, buf_size);
3573 if (!ifreqs)
3574 {
3575 close (s);
3576 return Qnil;
3577 }
3578
3579 ifconf.ifc_len = buf_size;
3580 ifconf.ifc_req = ifreqs;
3581 if (ioctl (s, SIOCGIFCONF, &ifconf))
3582 { 3589 {
3583 close (s); 3590 buf = xpalloc (buf, &buf_size, 1, INT_MAX, 1);
3584 return Qnil; 3591 ifconf.ifc_buf = buf;
3592 ifconf.ifc_len = buf_size;
3593 if (ioctl (s, SIOCGIFCONF, &ifconf))
3594 {
3595 close (s);
3596 xfree (buf);
3597 return Qnil;
3598 }
3585 } 3599 }
3586 3600 while (ifconf.ifc_len == buf_size);
3587 if (ifconf.ifc_len == buf_size)
3588 goto again;
3589 3601
3590 close (s); 3602 close (s);
3591 ifaces = ifconf.ifc_len / sizeof (ifreqs[0]);
3592 3603
3593 res = Qnil; 3604 res = Qnil;
3594 while (--ifaces >= 0) 3605 ifreq = ifconf.ifc_req;
3606 while ((char *) ifreq < (char *) ifconf.ifc_req + ifconf.ifc_len)
3595 { 3607 {
3596 struct ifreq *ifq = &ifreqs[ifaces]; 3608 struct ifreq *ifq = ifreq;
3609#ifdef HAVE_STRUCT_IFREQ_IFR_ADDR_SA_LEN
3610#define SIZEOF_IFREQ(sif) \
3611 ((sif)->ifr_addr.sa_len < sizeof (struct sockaddr) \
3612 ? sizeof (*(sif)) : sizeof ((sif)->ifr_name) + (sif)->ifr_addr.sa_len)
3613
3614 int len = SIZEOF_IFREQ (ifq);
3615#else
3616 int len = sizeof (*ifreq);
3617#endif
3597 char namebuf[sizeof (ifq->ifr_name) + 1]; 3618 char namebuf[sizeof (ifq->ifr_name) + 1];
3619 i += len;
3620 ifreq = (struct ifreq *) ((char *) ifreq + len);
3621
3598 if (ifq->ifr_addr.sa_family != AF_INET) 3622 if (ifq->ifr_addr.sa_family != AF_INET)
3599 continue; 3623 continue;
3624
3600 memcpy (namebuf, ifq->ifr_name, sizeof (ifq->ifr_name)); 3625 memcpy (namebuf, ifq->ifr_name, sizeof (ifq->ifr_name));
3601 namebuf[sizeof (ifq->ifr_name)] = 0; 3626 namebuf[sizeof (ifq->ifr_name)] = 0;
3602 res = Fcons (Fcons (build_string (namebuf), 3627 res = Fcons (Fcons (build_string (namebuf),
@@ -3605,11 +3630,12 @@ format; see the description of ADDRESS in `make-network-process'. */)
3605 res); 3630 res);
3606 } 3631 }
3607 3632
3633 xfree (buf);
3608 return res; 3634 return res;
3609} 3635}
3610#endif /* SIOCGIFCONF */ 3636#endif /* SIOCGIFCONF */
3611 3637
3612#if defined(SIOCGIFADDR) || defined(SIOCGIFHWADDR) || defined(SIOCGIFFLAGS) 3638#if defined (SIOCGIFADDR) || defined (SIOCGIFHWADDR) || defined (SIOCGIFFLAGS)
3613 3639
3614struct ifflag_def { 3640struct ifflag_def {
3615 int flag_bit; 3641 int flag_bit;
@@ -3642,8 +3668,13 @@ static const struct ifflag_def ifflag_table[] = {
3642 { IFF_PROMISC, "promisc" }, 3668 { IFF_PROMISC, "promisc" },
3643#endif 3669#endif
3644#ifdef IFF_NOTRAILERS 3670#ifdef IFF_NOTRAILERS
3671#ifdef NS_IMPL_COCOA
3672 /* Really means smart, notrailers is obsolete */
3673 { IFF_NOTRAILERS, "smart" },
3674#else
3645 { IFF_NOTRAILERS, "notrailers" }, 3675 { IFF_NOTRAILERS, "notrailers" },
3646#endif 3676#endif
3677#endif
3647#ifdef IFF_ALLMULTI 3678#ifdef IFF_ALLMULTI
3648 { IFF_ALLMULTI, "allmulti" }, 3679 { IFF_ALLMULTI, "allmulti" },
3649#endif 3680#endif
@@ -3687,7 +3718,7 @@ DEFUN ("network-interface-info", Fnetwork_interface_info, Snetwork_interface_inf
3687 doc: /* Return information about network interface named IFNAME. 3718 doc: /* Return information about network interface named IFNAME.
3688The return value is a list (ADDR BCAST NETMASK HWADDR FLAGS), 3719The return value is a list (ADDR BCAST NETMASK HWADDR FLAGS),
3689where ADDR is the layer 3 address, BCAST is the layer 3 broadcast address, 3720where ADDR is the layer 3 address, BCAST is the layer 3 broadcast address,
3690NETMASK is the layer 3 network mask, HWADDR is the layer 2 addres, and 3721NETMASK is the layer 3 network mask, HWADDR is the layer 2 address, and
3691FLAGS is the current flags of the interface. */) 3722FLAGS is the current flags of the interface. */)
3692 (Lisp_Object ifname) 3723 (Lisp_Object ifname)
3693{ 3724{
@@ -3696,6 +3727,10 @@ FLAGS is the current flags of the interface. */)
3696 Lisp_Object elt; 3727 Lisp_Object elt;
3697 int s; 3728 int s;
3698 int any = 0; 3729 int any = 0;
3730#if (! (defined SIOCGIFHWADDR && defined HAVE_STRUCT_IFREQ_IFR_HWADDR) \
3731 && defined HAVE_GETIFADDRS && defined LLADDR)
3732 struct ifaddrs *ifap;
3733#endif
3699 3734
3700 CHECK_STRING (ifname); 3735 CHECK_STRING (ifname);
3701 3736
@@ -3707,13 +3742,19 @@ FLAGS is the current flags of the interface. */)
3707 return Qnil; 3742 return Qnil;
3708 3743
3709 elt = Qnil; 3744 elt = Qnil;
3710#if defined(SIOCGIFFLAGS) && defined(HAVE_STRUCT_IFREQ_IFR_FLAGS) 3745#if defined (SIOCGIFFLAGS) && defined (HAVE_STRUCT_IFREQ_IFR_FLAGS)
3711 if (ioctl (s, SIOCGIFFLAGS, &rq) == 0) 3746 if (ioctl (s, SIOCGIFFLAGS, &rq) == 0)
3712 { 3747 {
3713 int flags = rq.ifr_flags; 3748 int flags = rq.ifr_flags;
3714 const struct ifflag_def *fp; 3749 const struct ifflag_def *fp;
3715 int fnum; 3750 int fnum;
3716 3751
3752 /* If flags is smaller than int (i.e. short) it may have the high bit set
3753 due to IFF_MULTICAST. In that case, sign extending it into
3754 an int is wrong. */
3755 if (flags < 0 && sizeof (rq.ifr_flags) < sizeof (flags))
3756 flags = (unsigned short) rq.ifr_flags;
3757
3717 any = 1; 3758 any = 1;
3718 for (fp = ifflag_table; flags != 0 && fp->flag_sym; fp++) 3759 for (fp = ifflag_table; flags != 0 && fp->flag_sym; fp++)
3719 { 3760 {
@@ -3735,7 +3776,7 @@ FLAGS is the current flags of the interface. */)
3735 res = Fcons (elt, res); 3776 res = Fcons (elt, res);
3736 3777
3737 elt = Qnil; 3778 elt = Qnil;
3738#if defined(SIOCGIFHWADDR) && defined(HAVE_STRUCT_IFREQ_IFR_HWADDR) 3779#if defined (SIOCGIFHWADDR) && defined (HAVE_STRUCT_IFREQ_IFR_HWADDR)
3739 if (ioctl (s, SIOCGIFHWADDR, &rq) == 0) 3780 if (ioctl (s, SIOCGIFHWADDR, &rq) == 0)
3740 { 3781 {
3741 Lisp_Object hwaddr = Fmake_vector (make_number (6), Qnil); 3782 Lisp_Object hwaddr = Fmake_vector (make_number (6), Qnil);
@@ -3747,11 +3788,42 @@ FLAGS is the current flags of the interface. */)
3747 p->contents[n] = make_number (((unsigned char *)&rq.ifr_hwaddr.sa_data[0])[n]); 3788 p->contents[n] = make_number (((unsigned char *)&rq.ifr_hwaddr.sa_data[0])[n]);
3748 elt = Fcons (make_number (rq.ifr_hwaddr.sa_family), hwaddr); 3789 elt = Fcons (make_number (rq.ifr_hwaddr.sa_family), hwaddr);
3749 } 3790 }
3791#elif defined (HAVE_GETIFADDRS) && defined (LLADDR)
3792 if (getifaddrs (&ifap) != -1)
3793 {
3794 Lisp_Object hwaddr = Fmake_vector (make_number (6), Qnil);
3795 register struct Lisp_Vector *p = XVECTOR (hwaddr);
3796 struct ifaddrs *it;
3797
3798 for (it = ifap; it != NULL; it = it->ifa_next)
3799 {
3800 struct sockaddr_dl *sdl = (struct sockaddr_dl*) it->ifa_addr;
3801 unsigned char linkaddr[6];
3802 int n;
3803
3804 if (it->ifa_addr->sa_family != AF_LINK
3805 || strcmp (it->ifa_name, SSDATA (ifname)) != 0
3806 || sdl->sdl_alen != 6)
3807 continue;
3808
3809 memcpy (linkaddr, LLADDR (sdl), sdl->sdl_alen);
3810 for (n = 0; n < 6; n++)
3811 p->contents[n] = make_number (linkaddr[n]);
3812
3813 elt = Fcons (make_number (it->ifa_addr->sa_family), hwaddr);
3814 break;
3815 }
3816 }
3817#ifdef HAVE_FREEIFADDRS
3818 freeifaddrs (ifap);
3750#endif 3819#endif
3820
3821#endif /* HAVE_GETIFADDRS && LLADDR */
3822
3751 res = Fcons (elt, res); 3823 res = Fcons (elt, res);
3752 3824
3753 elt = Qnil; 3825 elt = Qnil;
3754#if defined(SIOCGIFNETMASK) && (defined(HAVE_STRUCT_IFREQ_IFR_NETMASK) || defined(HAVE_STRUCT_IFREQ_IFR_ADDR)) 3826#if defined (SIOCGIFNETMASK) && (defined (HAVE_STRUCT_IFREQ_IFR_NETMASK) || defined (HAVE_STRUCT_IFREQ_IFR_ADDR))
3755 if (ioctl (s, SIOCGIFNETMASK, &rq) == 0) 3827 if (ioctl (s, SIOCGIFNETMASK, &rq) == 0)
3756 { 3828 {
3757 any = 1; 3829 any = 1;
@@ -3765,7 +3837,7 @@ FLAGS is the current flags of the interface. */)
3765 res = Fcons (elt, res); 3837 res = Fcons (elt, res);
3766 3838
3767 elt = Qnil; 3839 elt = Qnil;
3768#if defined(SIOCGIFBRDADDR) && defined(HAVE_STRUCT_IFREQ_IFR_BROADADDR) 3840#if defined (SIOCGIFBRDADDR) && defined (HAVE_STRUCT_IFREQ_IFR_BROADADDR)
3769 if (ioctl (s, SIOCGIFBRDADDR, &rq) == 0) 3841 if (ioctl (s, SIOCGIFBRDADDR, &rq) == 0)
3770 { 3842 {
3771 any = 1; 3843 any = 1;
@@ -3775,7 +3847,7 @@ FLAGS is the current flags of the interface. */)
3775 res = Fcons (elt, res); 3847 res = Fcons (elt, res);
3776 3848
3777 elt = Qnil; 3849 elt = Qnil;
3778#if defined(SIOCGIFADDR) && defined(HAVE_STRUCT_IFREQ_IFR_ADDR) 3850#if defined (SIOCGIFADDR) && defined (HAVE_STRUCT_IFREQ_IFR_ADDR)
3779 if (ioctl (s, SIOCGIFADDR, &rq) == 0) 3851 if (ioctl (s, SIOCGIFADDR, &rq) == 0)
3780 { 3852 {
3781 any = 1; 3853 any = 1;
@@ -3789,7 +3861,7 @@ FLAGS is the current flags of the interface. */)
3789 return any ? res : Qnil; 3861 return any ? res : Qnil;
3790} 3862}
3791#endif 3863#endif
3792#endif /* defined(HAVE_NET_IF_H) */ 3864#endif /* defined (HAVE_NET_IF_H) */
3793 3865
3794/* Turn off input and output for process PROC. */ 3866/* Turn off input and output for process PROC. */
3795 3867
@@ -3799,6 +3871,11 @@ deactivate_process (Lisp_Object proc)
3799 register int inchannel, outchannel; 3871 register int inchannel, outchannel;
3800 register struct Lisp_Process *p = XPROCESS (proc); 3872 register struct Lisp_Process *p = XPROCESS (proc);
3801 3873
3874#ifdef HAVE_GNUTLS
3875 /* Delete GnuTLS structures in PROC, if any. */
3876 emacs_gnutls_deinit (proc);
3877#endif /* HAVE_GNUTLS */
3878
3802 inchannel = p->infd; 3879 inchannel = p->infd;
3803 outchannel = p->outfd; 3880 outchannel = p->outfd;
3804 3881
@@ -4544,15 +4621,46 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4544 some data in the TCP buffers so that select works, but 4621 some data in the TCP buffers so that select works, but
4545 with custom pull/push functions we need to check if some 4622 with custom pull/push functions we need to check if some
4546 data is available in the buffers manually. */ 4623 data is available in the buffers manually. */
4547 if (nfds == 0 && 4624 if (nfds == 0)
4548 wait_proc && wait_proc->gnutls_p /* Check for valid process. */ 4625 {
4549 /* Do we have pending data? */ 4626 if (! wait_proc)
4550 && emacs_gnutls_record_check_pending (wait_proc->gnutls_state) > 0) 4627 {
4551 { 4628 /* We're not waiting on a specific process, so loop
4552 nfds = 1; 4629 through all the channels and check for data.
4553 /* Set to Available. */ 4630 This is a workaround needed for some versions of
4554 FD_SET (wait_proc->infd, &Available); 4631 the gnutls library -- 2.12.14 has been confirmed
4555 } 4632 to need it. See
4633 http://comments.gmane.org/gmane.emacs.devel/145074 */
4634 for (channel = 0; channel < MAXDESC; ++channel)
4635 if (! NILP (chan_process[channel]))
4636 {
4637 struct Lisp_Process *p =
4638 XPROCESS (chan_process[channel]);
4639 if (p && p->gnutls_p && p->infd
4640 && ((emacs_gnutls_record_check_pending
4641 (p->gnutls_state))
4642 > 0))
4643 {
4644 nfds++;
4645 FD_SET (p->infd, &Available);
4646 }
4647 }
4648 }
4649 else
4650 {
4651 /* Check this specific channel. */
4652 if (wait_proc->gnutls_p /* Check for valid process. */
4653 /* Do we have pending data? */
4654 && ((emacs_gnutls_record_check_pending
4655 (wait_proc->gnutls_state))
4656 > 0))
4657 {
4658 nfds = 1;
4659 /* Set to Available. */
4660 FD_SET (wait_proc->infd, &Available);
4661 }
4662 }
4663 }
4556#endif 4664#endif
4557 } 4665 }
4558 4666
@@ -4780,20 +4888,20 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4780 It can't hurt. */ 4888 It can't hurt. */
4781 else if (nread == -1 && errno == EIO) 4889 else if (nread == -1 && errno == EIO)
4782 { 4890 {
4783 /* Clear the descriptor now, so we only raise the 4891 /* Don't do anything if only a pty, with no associated
4784 signal once. Don't do this if `process' is only 4892 process (bug#10933). */
4785 a pty. */ 4893 if (XPROCESS (proc)->pid != -2) {
4786 if (XPROCESS (proc)->pid != -2) 4894 /* Clear the descriptor now, so we only raise the signal
4787 { 4895 once. */
4788 FD_CLR (channel, &input_wait_mask); 4896 FD_CLR (channel, &input_wait_mask);
4789 FD_CLR (channel, &non_keyboard_wait_mask); 4897 FD_CLR (channel, &non_keyboard_wait_mask);
4790 4898
4791 kill (getpid (), SIGCHLD); 4899 kill (getpid (), SIGCHLD);
4792 } 4900 }
4793 } 4901 }
4794#endif /* HAVE_PTYS */ 4902#endif /* HAVE_PTYS */
4795 /* If we can detect process termination, don't consider the process 4903 /* If we can detect process termination, don't consider the
4796 gone just because its pipe is closed. */ 4904 process gone just because its pipe is closed. */
4797#ifdef SIGCHLD 4905#ifdef SIGCHLD
4798 else if (nread == 0 && !NETCONN_P (proc) && !SERIALCONN_P (proc)) 4906 else if (nread == 0 && !NETCONN_P (proc) && !SERIALCONN_P (proc))
4799 ; 4907 ;
@@ -4957,9 +5065,8 @@ read_process_output (Lisp_Object proc, register int channel)
4957 proc_buffered_char[channel] = -1; 5065 proc_buffered_char[channel] = -1;
4958 } 5066 }
4959#ifdef HAVE_GNUTLS 5067#ifdef HAVE_GNUTLS
4960 if (XPROCESS (proc)->gnutls_p) 5068 if (p->gnutls_p)
4961 nbytes = emacs_gnutls_read (XPROCESS (proc), 5069 nbytes = emacs_gnutls_read (p, chars + carryover + buffered,
4962 chars + carryover + buffered,
4963 readmax - buffered); 5070 readmax - buffered);
4964 else 5071 else
4965#endif 5072#endif
@@ -5093,6 +5200,9 @@ read_process_output (Lisp_Object proc, register int channel)
5093 p->decoding_carryover = coding->carryover_bytes; 5200 p->decoding_carryover = coding->carryover_bytes;
5094 } 5201 }
5095 if (SBYTES (text) > 0) 5202 if (SBYTES (text) > 0)
5203 /* FIXME: It's wrong to wrap or not based on debug-on-error, and
5204 sometimes it's simply wrong to wrap (e.g. when called from
5205 accept-process-output). */
5096 internal_condition_case_1 (read_process_output_call, 5206 internal_condition_case_1 (read_process_output_call,
5097 Fcons (outstream, 5207 Fcons (outstream,
5098 Fcons (proc, Fcons (text, Qnil))), 5208 Fcons (proc, Fcons (text, Qnil))),
@@ -5303,8 +5413,8 @@ send_process (volatile Lisp_Object proc, const char *volatile buf,
5303 sending a multibyte text, thus we must encode it by the 5413 sending a multibyte text, thus we must encode it by the
5304 original coding system specified for the current process. 5414 original coding system specified for the current process.
5305 5415
5306 Another reason we comming here is that the coding system 5416 Another reason we come here is that the coding system
5307 was just complemented and new one was returned by 5417 was just complemented and a new one was returned by
5308 complement_process_encoding_system. */ 5418 complement_process_encoding_system. */
5309 setup_coding_system (p->encode_coding_system, coding); 5419 setup_coding_system (p->encode_coding_system, coding);
5310 Vlast_coding_system_used = p->encode_coding_system; 5420 Vlast_coding_system_used = p->encode_coding_system;
@@ -5313,6 +5423,7 @@ send_process (volatile Lisp_Object proc, const char *volatile buf,
5313 } 5423 }
5314 else 5424 else
5315 { 5425 {
5426 coding->src_multibyte = 0;
5316 /* For sending a unibyte text, character code conversion should 5427 /* For sending a unibyte text, character code conversion should
5317 not take place but EOL conversion should. So, setup raw-text 5428 not take place but EOL conversion should. So, setup raw-text
5318 or one of the subsidiary if we have not yet done it. */ 5429 or one of the subsidiary if we have not yet done it. */
@@ -5420,9 +5531,8 @@ send_process (volatile Lisp_Object proc, const char *volatile buf,
5420#endif 5531#endif
5421 { 5532 {
5422#ifdef HAVE_GNUTLS 5533#ifdef HAVE_GNUTLS
5423 if (XPROCESS (proc)->gnutls_p) 5534 if (p->gnutls_p)
5424 written = emacs_gnutls_write (XPROCESS (proc), 5535 written = emacs_gnutls_write (p, buf, this);
5425 buf, this);
5426 else 5536 else
5427#endif 5537#endif
5428 written = emacs_write (outfd, buf, this); 5538 written = emacs_write (outfd, buf, this);
@@ -7209,7 +7319,7 @@ init_process (void)
7209#ifdef HAVE_GETSOCKNAME 7319#ifdef HAVE_GETSOCKNAME
7210 ADD_SUBFEATURE (QCservice, Qt); 7320 ADD_SUBFEATURE (QCservice, Qt);
7211#endif 7321#endif
7212#if defined(O_NONBLOCK) || defined(O_NDELAY) 7322#if defined (O_NONBLOCK) || defined (O_NDELAY)
7213 ADD_SUBFEATURE (QCserver, Qt); 7323 ADD_SUBFEATURE (QCserver, Qt);
7214#endif 7324#endif
7215 7325
@@ -7401,14 +7511,14 @@ The variable takes effect when `start-process' is called. */);
7401 defsubr (&Sset_network_process_option); 7511 defsubr (&Sset_network_process_option);
7402 defsubr (&Smake_network_process); 7512 defsubr (&Smake_network_process);
7403 defsubr (&Sformat_network_address); 7513 defsubr (&Sformat_network_address);
7404#if defined(HAVE_NET_IF_H) 7514#if defined (HAVE_NET_IF_H)
7405#ifdef SIOCGIFCONF 7515#ifdef SIOCGIFCONF
7406 defsubr (&Snetwork_interface_list); 7516 defsubr (&Snetwork_interface_list);
7407#endif 7517#endif
7408#if defined(SIOCGIFADDR) || defined(SIOCGIFHWADDR) || defined(SIOCGIFFLAGS) 7518#if defined (SIOCGIFADDR) || defined (SIOCGIFHWADDR) || defined (SIOCGIFFLAGS)
7409 defsubr (&Snetwork_interface_info); 7519 defsubr (&Snetwork_interface_info);
7410#endif 7520#endif
7411#endif /* defined(HAVE_NET_IF_H) */ 7521#endif /* defined (HAVE_NET_IF_H) */
7412#ifdef DATAGRAM_SOCKETS 7522#ifdef DATAGRAM_SOCKETS
7413 defsubr (&Sprocess_datagram_address); 7523 defsubr (&Sprocess_datagram_address);
7414 defsubr (&Sset_process_datagram_address); 7524 defsubr (&Sset_process_datagram_address);