diff options
| author | Paul Eggert | 2011-09-03 16:03:38 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-09-03 16:03:38 -0700 |
| commit | b49e353d9d01adbe60bc5d0b1658b4ef978b0b06 (patch) | |
| tree | 9f2ffa6f7a6562abf661a4951012b488ad8b1ae7 /src/process.c | |
| parent | 74b880cbc18bd0194c7b1fc44c4a983ee05adae2 (diff) | |
| parent | bc3200871917d5c54c8c4299a06bf8f8ba2ea02d (diff) | |
| download | emacs-b49e353d9d01adbe60bc5d0b1658b4ef978b0b06.tar.gz emacs-b49e353d9d01adbe60bc5d0b1658b4ef978b0b06.zip | |
Merge from trunk.
Diffstat (limited to 'src/process.c')
| -rw-r--r-- | src/process.c | 121 |
1 files changed, 96 insertions, 25 deletions
diff --git a/src/process.c b/src/process.c index 236c27e5c3a..a8088322147 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -58,6 +58,17 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 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 |
| @@ -1632,7 +1643,6 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) | |||
| 1632 | 1643 | ||
| 1633 | XPROCESS (process)->pty_flag = pty_flag; | 1644 | XPROCESS (process)->pty_flag = pty_flag; |
| 1634 | XPROCESS (process)->status = Qrun; | 1645 | XPROCESS (process)->status = Qrun; |
| 1635 | setup_process_coding_systems (process); | ||
| 1636 | 1646 | ||
| 1637 | /* Delay interrupts until we have a chance to store | 1647 | /* Delay interrupts until we have a chance to store |
| 1638 | the new fork's pid in its process structure */ | 1648 | the new fork's pid in its process structure */ |
| @@ -1667,6 +1677,10 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) | |||
| 1667 | processes to get their return values scrambled. */ | 1677 | processes to get their return values scrambled. */ |
| 1668 | XPROCESS (process)->pid = -1; | 1678 | XPROCESS (process)->pid = -1; |
| 1669 | 1679 | ||
| 1680 | /* This must be called after the above line because it may signal an | ||
| 1681 | error. */ | ||
| 1682 | setup_process_coding_systems (process); | ||
| 1683 | |||
| 1670 | BLOCK_INPUT; | 1684 | BLOCK_INPUT; |
| 1671 | 1685 | ||
| 1672 | { | 1686 | { |
| @@ -3557,46 +3571,53 @@ format; see the description of ADDRESS in `make-network-process'. */) | |||
| 3557 | (void) | 3571 | (void) |
| 3558 | { | 3572 | { |
| 3559 | struct ifconf ifconf; | 3573 | struct ifconf ifconf; |
| 3560 | struct ifreq *ifreqs = NULL; | 3574 | struct ifreq *ifreq; |
| 3561 | int ifaces = 0; | 3575 | void *buf = NULL; |
| 3562 | int buf_size, s; | 3576 | ptrdiff_t buf_size = 512; |
| 3577 | int s, i; | ||
| 3563 | Lisp_Object res; | 3578 | Lisp_Object res; |
| 3564 | 3579 | ||
| 3565 | s = socket (AF_INET, SOCK_STREAM, 0); | 3580 | s = socket (AF_INET, SOCK_STREAM, 0); |
| 3566 | if (s < 0) | 3581 | if (s < 0) |
| 3567 | return Qnil; | 3582 | return Qnil; |
| 3568 | 3583 | ||
| 3569 | again: | 3584 | do |
| 3570 | ifaces += 25; | ||
| 3571 | buf_size = ifaces * sizeof (ifreqs[0]); | ||
| 3572 | ifreqs = (struct ifreq *)xrealloc(ifreqs, buf_size); | ||
| 3573 | if (!ifreqs) | ||
| 3574 | { | 3585 | { |
| 3575 | close (s); | 3586 | buf = xpalloc (buf, &buf_size, 1, INT_MAX, 1); |
| 3576 | return Qnil; | 3587 | ifconf.ifc_buf = buf; |
| 3577 | } | 3588 | ifconf.ifc_len = buf_size; |
| 3578 | 3589 | if (ioctl (s, SIOCGIFCONF, &ifconf)) | |
| 3579 | ifconf.ifc_len = buf_size; | 3590 | { |
| 3580 | ifconf.ifc_req = ifreqs; | 3591 | close (s); |
| 3581 | if (ioctl (s, SIOCGIFCONF, &ifconf)) | 3592 | xfree (buf); |
| 3582 | { | 3593 | return Qnil; |
| 3583 | close (s); | 3594 | } |
| 3584 | return Qnil; | ||
| 3585 | } | 3595 | } |
| 3586 | 3596 | while (ifconf.ifc_len == buf_size); | |
| 3587 | if (ifconf.ifc_len == buf_size) | ||
| 3588 | goto again; | ||
| 3589 | 3597 | ||
| 3590 | close (s); | 3598 | close (s); |
| 3591 | ifaces = ifconf.ifc_len / sizeof (ifreqs[0]); | ||
| 3592 | 3599 | ||
| 3593 | res = Qnil; | 3600 | res = Qnil; |
| 3594 | while (--ifaces >= 0) | 3601 | ifreq = ifconf.ifc_req; |
| 3602 | while ((char *) ifreq < (char *) ifconf.ifc_req + ifconf.ifc_len) | ||
| 3595 | { | 3603 | { |
| 3596 | struct ifreq *ifq = &ifreqs[ifaces]; | 3604 | struct ifreq *ifq = ifreq; |
| 3605 | #ifdef HAVE_STRUCT_IFREQ_IFR_ADDR_SA_LEN | ||
| 3606 | #define SIZEOF_IFREQ(sif) \ | ||
| 3607 | ((sif)->ifr_addr.sa_len < sizeof (struct sockaddr) \ | ||
| 3608 | ? sizeof (*(sif)) : sizeof ((sif)->ifr_name) + (sif)->ifr_addr.sa_len) | ||
| 3609 | |||
| 3610 | int len = SIZEOF_IFREQ (ifq); | ||
| 3611 | #else | ||
| 3612 | int len = sizeof (*ifreq); | ||
| 3613 | #endif | ||
| 3597 | char namebuf[sizeof (ifq->ifr_name) + 1]; | 3614 | char namebuf[sizeof (ifq->ifr_name) + 1]; |
| 3615 | i += len; | ||
| 3616 | ifreq = (struct ifreq *) ((char *) ifreq + len); | ||
| 3617 | |||
| 3598 | if (ifq->ifr_addr.sa_family != AF_INET) | 3618 | if (ifq->ifr_addr.sa_family != AF_INET) |
| 3599 | continue; | 3619 | continue; |
| 3620 | |||
| 3600 | memcpy (namebuf, ifq->ifr_name, sizeof (ifq->ifr_name)); | 3621 | memcpy (namebuf, ifq->ifr_name, sizeof (ifq->ifr_name)); |
| 3601 | namebuf[sizeof (ifq->ifr_name)] = 0; | 3622 | namebuf[sizeof (ifq->ifr_name)] = 0; |
| 3602 | res = Fcons (Fcons (build_string (namebuf), | 3623 | res = Fcons (Fcons (build_string (namebuf), |
| @@ -3605,6 +3626,7 @@ format; see the description of ADDRESS in `make-network-process'. */) | |||
| 3605 | res); | 3626 | res); |
| 3606 | } | 3627 | } |
| 3607 | 3628 | ||
| 3629 | xfree (buf); | ||
| 3608 | return res; | 3630 | return res; |
| 3609 | } | 3631 | } |
| 3610 | #endif /* SIOCGIFCONF */ | 3632 | #endif /* SIOCGIFCONF */ |
| @@ -3642,8 +3664,13 @@ static const struct ifflag_def ifflag_table[] = { | |||
| 3642 | { IFF_PROMISC, "promisc" }, | 3664 | { IFF_PROMISC, "promisc" }, |
| 3643 | #endif | 3665 | #endif |
| 3644 | #ifdef IFF_NOTRAILERS | 3666 | #ifdef IFF_NOTRAILERS |
| 3667 | #ifdef NS_IMPL_COCOA | ||
| 3668 | /* Really means smart, notrailers is obsolete */ | ||
| 3669 | { IFF_NOTRAILERS, "smart" }, | ||
| 3670 | #else | ||
| 3645 | { IFF_NOTRAILERS, "notrailers" }, | 3671 | { IFF_NOTRAILERS, "notrailers" }, |
| 3646 | #endif | 3672 | #endif |
| 3673 | #endif | ||
| 3647 | #ifdef IFF_ALLMULTI | 3674 | #ifdef IFF_ALLMULTI |
| 3648 | { IFF_ALLMULTI, "allmulti" }, | 3675 | { IFF_ALLMULTI, "allmulti" }, |
| 3649 | #endif | 3676 | #endif |
| @@ -3696,6 +3723,10 @@ FLAGS is the current flags of the interface. */) | |||
| 3696 | Lisp_Object elt; | 3723 | Lisp_Object elt; |
| 3697 | int s; | 3724 | int s; |
| 3698 | int any = 0; | 3725 | int any = 0; |
| 3726 | #if (! (defined SIOCGIFHWADDR && defined HAVE_STRUCT_IFREQ_IFR_HWADDR) \ | ||
| 3727 | && defined HAVE_GETIFADDRS && defined LLADDR) | ||
| 3728 | struct ifaddrs *ifap; | ||
| 3729 | #endif | ||
| 3699 | 3730 | ||
| 3700 | CHECK_STRING (ifname); | 3731 | CHECK_STRING (ifname); |
| 3701 | 3732 | ||
| @@ -3714,6 +3745,12 @@ FLAGS is the current flags of the interface. */) | |||
| 3714 | const struct ifflag_def *fp; | 3745 | const struct ifflag_def *fp; |
| 3715 | int fnum; | 3746 | int fnum; |
| 3716 | 3747 | ||
| 3748 | /* If flags is smaller than int (i.e. short) it may have the high bit set | ||
| 3749 | due to IFF_MULTICAST. In that case, sign extending it into | ||
| 3750 | an int is wrong. */ | ||
| 3751 | if (flags < 0 && sizeof (rq.ifr_flags) < sizeof (flags)) | ||
| 3752 | flags = (unsigned short) rq.ifr_flags; | ||
| 3753 | |||
| 3717 | any = 1; | 3754 | any = 1; |
| 3718 | for (fp = ifflag_table; flags != 0 && fp->flag_sym; fp++) | 3755 | for (fp = ifflag_table; flags != 0 && fp->flag_sym; fp++) |
| 3719 | { | 3756 | { |
| @@ -3747,7 +3784,38 @@ FLAGS is the current flags of the interface. */) | |||
| 3747 | p->contents[n] = make_number (((unsigned char *)&rq.ifr_hwaddr.sa_data[0])[n]); | 3784 | 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); | 3785 | elt = Fcons (make_number (rq.ifr_hwaddr.sa_family), hwaddr); |
| 3749 | } | 3786 | } |
| 3787 | #elif defined(HAVE_GETIFADDRS) && defined(LLADDR) | ||
| 3788 | if (getifaddrs (&ifap) != -1) | ||
| 3789 | { | ||
| 3790 | Lisp_Object hwaddr = Fmake_vector (make_number (6), Qnil); | ||
| 3791 | register struct Lisp_Vector *p = XVECTOR (hwaddr); | ||
| 3792 | struct ifaddrs *it; | ||
| 3793 | |||
| 3794 | for (it = ifap; it != NULL; it = it->ifa_next) | ||
| 3795 | { | ||
| 3796 | struct sockaddr_dl *sdl = (struct sockaddr_dl*) it->ifa_addr; | ||
| 3797 | unsigned char linkaddr[6]; | ||
| 3798 | int n; | ||
| 3799 | |||
| 3800 | if (it->ifa_addr->sa_family != AF_LINK | ||
| 3801 | || strcmp (it->ifa_name, SSDATA (ifname)) != 0 | ||
| 3802 | || sdl->sdl_alen != 6) | ||
| 3803 | continue; | ||
| 3804 | |||
| 3805 | memcpy (linkaddr, LLADDR(sdl), sdl->sdl_alen); | ||
| 3806 | for (n = 0; n < 6; n++) | ||
| 3807 | p->contents[n] = make_number (linkaddr[n]); | ||
| 3808 | |||
| 3809 | elt = Fcons (make_number (it->ifa_addr->sa_family), hwaddr); | ||
| 3810 | break; | ||
| 3811 | } | ||
| 3812 | } | ||
| 3813 | #ifdef HAVE_FREEIFADDRS | ||
| 3814 | freeifaddrs (ifap); | ||
| 3750 | #endif | 3815 | #endif |
| 3816 | |||
| 3817 | #endif /* HAVE_GETIFADDRS && LLADDR */ | ||
| 3818 | |||
| 3751 | res = Fcons (elt, res); | 3819 | res = Fcons (elt, res); |
| 3752 | 3820 | ||
| 3753 | elt = Qnil; | 3821 | elt = Qnil; |
| @@ -5093,6 +5161,9 @@ read_process_output (Lisp_Object proc, register int channel) | |||
| 5093 | p->decoding_carryover = coding->carryover_bytes; | 5161 | p->decoding_carryover = coding->carryover_bytes; |
| 5094 | } | 5162 | } |
| 5095 | if (SBYTES (text) > 0) | 5163 | if (SBYTES (text) > 0) |
| 5164 | /* FIXME: It's wrong to wrap or not based on debug-on-error, and | ||
| 5165 | sometimes it's simply wrong to wrap (e.g. when called from | ||
| 5166 | accept-process-output). */ | ||
| 5096 | internal_condition_case_1 (read_process_output_call, | 5167 | internal_condition_case_1 (read_process_output_call, |
| 5097 | Fcons (outstream, | 5168 | Fcons (outstream, |
| 5098 | Fcons (proc, Fcons (text, Qnil))), | 5169 | Fcons (proc, Fcons (text, Qnil))), |