From nobody Sat Apr 27 12:08:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1541857689538934.9846582378142; Sat, 10 Nov 2018 05:48:09 -0800 (PST) Received: from localhost ([::1]:38468 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLTcO-00050G-8N for importer@patchew.org; Sat, 10 Nov 2018 08:48:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36329) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLTaO-0004AZ-Es for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:46:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gLTaN-0006Tn-6m for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:46:04 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38136) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gLTaM-0006ST-UO for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:46:03 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4383658E2F; Sat, 10 Nov 2018 13:46:02 +0000 (UTC) Received: from localhost (ovpn-112-21.ams2.redhat.com [10.36.112.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9FA0A5D968; Sat, 10 Nov 2018 13:45:58 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 10 Nov 2018 17:45:36 +0400 Message-Id: <20181110134548.14741-2-marcandre.lureau@redhat.com> In-Reply-To: <20181110134548.14741-1-marcandre.lureau@redhat.com> References: <20181110134548.14741-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Sat, 10 Nov 2018 13:46:02 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-3.2 01/13] slirp: associate slirp_output callback with the Slirp context X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Kiszka , Jason Wang , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Let's make the slirp interface a bit more library-like. Associate the slirp_output() with a Slirp context. Signed-off-by: Marc-Andr=C3=A9 Lureau --- slirp/libslirp.h | 9 +++++---- slirp/slirp.h | 1 + net/slirp.c | 5 +++-- slirp/ncsi.c | 2 +- slirp/slirp.c | 11 +++++++---- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/slirp/libslirp.h b/slirp/libslirp.h index 42e42e9a2a..52dbb9feb5 100644 --- a/slirp/libslirp.h +++ b/slirp/libslirp.h @@ -5,6 +5,8 @@ =20 typedef struct Slirp Slirp; =20 +typedef void (*slirp_output)(void *opaque, const uint8_t *pkt, int pkt_len= ); + int get_dns_addr(struct in_addr *pdns_addr); int get_dns6_addr(struct in6_addr *pdns6_addr, uint32_t *scope_id); =20 @@ -17,7 +19,9 @@ Slirp *slirp_init(int restricted, bool in_enabled, struct= in_addr vnetwork, const char *tftp_path, const char *bootfile, struct in_addr vdhcp_start, struct in_addr vnameserver, struct in6_addr vnameserver6, const char **vdnssearch, - const char *vdomainname, void *opaque); + const char *vdomainname, + slirp_output output, + void *opaque); void slirp_cleanup(Slirp *slirp); =20 void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout); @@ -26,9 +30,6 @@ void slirp_pollfds_poll(GArray *pollfds, int select_error= ); =20 void slirp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len); =20 -/* you must provide the following functions: */ -void slirp_output(void *opaque, const uint8_t *pkt, int pkt_len); - int slirp_add_hostfwd(Slirp *slirp, int is_udp, struct in_addr host_addr, int host_port, struct in_addr guest_addr, int guest_port); diff --git a/slirp/slirp.h b/slirp/slirp.h index b80725a0d6..e3d65d68ec 100644 --- a/slirp/slirp.h +++ b/slirp/slirp.h @@ -220,6 +220,7 @@ struct Slirp { GRand *grand; QEMUTimer *ra_timer; =20 + slirp_output output; void *opaque; }; =20 diff --git a/net/slirp.c b/net/slirp.c index f6dc03963a..1dbd34a9da 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -99,7 +99,7 @@ static void slirp_smb_cleanup(SlirpState *s); static inline void slirp_smb_cleanup(SlirpState *s) { } #endif =20 -void slirp_output(void *opaque, const uint8_t *pkt, int pkt_len) +static void net_slirp_output(void *opaque, const uint8_t *pkt, int pkt_len) { SlirpState *s =3D opaque; =20 @@ -378,7 +378,8 @@ static int net_slirp_init(NetClientState *peer, const c= har *model, ipv6, ip6_prefix, vprefix6_len, ip6_host, vhostname, tftp_server_name, tftp_export, bootfile, dhcp, - dns, ip6_dns, dnssearch, vdomainname, s); + dns, ip6_dns, dnssearch, vdomainname, + net_slirp_output, s); QTAILQ_INSERT_TAIL(&slirp_stacks, s, entry); =20 for (config =3D slirp_configs; config; config =3D config->next) { diff --git a/slirp/ncsi.c b/slirp/ncsi.c index 7116034afc..d7701f7785 100644 --- a/slirp/ncsi.c +++ b/slirp/ncsi.c @@ -163,5 +163,5 @@ void ncsi_input(Slirp *slirp, const uint8_t *pkt, int p= kt_len) *pchecksum =3D htonl(checksum); ncsi_rsp_len +=3D 4; =20 - slirp_output(slirp->opaque, ncsi_reply, ETH_HLEN + ncsi_rsp_len); + slirp->output(slirp->opaque, ncsi_reply, ETH_HLEN + ncsi_rsp_len); } diff --git a/slirp/slirp.c b/slirp/slirp.c index 51de41fc02..878d6174a2 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -287,12 +287,15 @@ Slirp *slirp_init(int restricted, bool in_enabled, st= ruct in_addr vnetwork, const char *tftp_path, const char *bootfile, struct in_addr vdhcp_start, struct in_addr vnameserver, struct in6_addr vnameserver6, const char **vdnssearch, - const char *vdomainname, void *opaque) + const char *vdomainname, + slirp_output output, + void *opaque) { Slirp *slirp =3D g_malloc0(sizeof(Slirp)); =20 slirp_init_once(); =20 + slirp->output =3D output; slirp->grand =3D g_rand_new(); slirp->restricted =3D restricted; =20 @@ -832,7 +835,7 @@ static void arp_input(Slirp *slirp, const uint8_t *pkt,= int pkt_len) rah->ar_sip =3D ah->ar_tip; memcpy(rah->ar_tha, ah->ar_sha, ETH_ALEN); rah->ar_tip =3D ah->ar_sip; - slirp_output(slirp->opaque, arp_reply, sizeof(arp_reply)); + slirp->output(slirp->opaque, arp_reply, sizeof(arp_reply)); } break; case ARPOP_REPLY: @@ -932,7 +935,7 @@ static int if_encap4(Slirp *slirp, struct mbuf *ifm, st= ruct ethhdr *eh, /* target IP */ rah->ar_tip =3D iph->ip_dst.s_addr; slirp->client_ipaddr =3D iph->ip_dst; - slirp_output(slirp->opaque, arp_req, sizeof(arp_req)); + slirp->output(slirp->opaque, arp_req, sizeof(arp_req)); ifm->resolution_requested =3D true; =20 /* Expire request and drop outgoing packet after 1 second */ @@ -1018,7 +1021,7 @@ int if_encap(Slirp *slirp, struct mbuf *ifm) eh->h_dest[0], eh->h_dest[1], eh->h_dest[2], eh->h_dest[3], eh->h_dest[4], eh->h_dest[5])); memcpy(buf + sizeof(struct ethhdr), ifm->m_data, ifm->m_len); - slirp_output(slirp->opaque, buf, ifm->m_len + ETH_HLEN); + slirp->output(slirp->opaque, buf, ifm->m_len + ETH_HLEN); return 1; } =20 --=20 2.19.1.708.g4ede3d42df From nobody Sat Apr 27 12:08:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1541857744328754.2451474365763; Sat, 10 Nov 2018 05:49:04 -0800 (PST) Received: from localhost ([::1]:38469 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLTdH-0007lP-9s for importer@patchew.org; Sat, 10 Nov 2018 08:49:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36408) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLTat-0004S6-A5 for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:46:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gLTaa-0006tx-Vv for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:46:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56274) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gLTaZ-0006eL-Fo for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:46:16 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CE43F3082125; Sat, 10 Nov 2018 13:46:10 +0000 (UTC) Received: from localhost (ovpn-112-21.ams2.redhat.com [10.36.112.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0BB7E19754; Sat, 10 Nov 2018 13:46:06 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 10 Nov 2018 17:45:37 +0400 Message-Id: <20181110134548.14741-3-marcandre.lureau@redhat.com> In-Reply-To: <20181110134548.14741-1-marcandre.lureau@redhat.com> References: <20181110134548.14741-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Sat, 10 Nov 2018 13:46:10 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-3.2 02/13] slirp: remove do_pty from fork_exec() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Kiszka , Jason Wang , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" QEMU uses fork_exec() with do_pty values 0 or 3. Let's clean up some unused code. Signed-off-by: Marc-Andr=C3=A9 Lureau --- slirp/misc.h | 2 +- slirp/misc.c | 55 ++++++++++++++---------------------------------- slirp/tcp_subr.c | 2 +- 3 files changed, 18 insertions(+), 41 deletions(-) diff --git a/slirp/misc.h b/slirp/misc.h index 5211bbd30a..897650aea1 100644 --- a/slirp/misc.h +++ b/slirp/misc.h @@ -53,6 +53,6 @@ struct slirp_quehead { void slirp_insque(void *, void *); void slirp_remque(void *); int add_exec(struct ex_list **, int, char *, struct in_addr, int); -int fork_exec(struct socket *so, const char *ex, int do_pty); +int fork_exec(struct socket *so, const char *ex); =20 #endif diff --git a/slirp/misc.c b/slirp/misc.c index 260187b6b6..ec5d5ec073 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -63,7 +63,7 @@ int add_exec(struct ex_list **ex_ptr, int do_pty, char *e= xec, #ifdef _WIN32 =20 int -fork_exec(struct socket *so, const char *ex, int do_pty) +fork_exec(struct socket *so, const char *ex) { /* not implemented */ return 0; @@ -77,13 +77,9 @@ fork_exec(struct socket *so, const char *ex, int do_pty) * process, which connects to this socket, after which we * exec the wanted program. If something (strange) happens, * the accept() call could block us forever. - * - * do_pty =3D 0 Fork/exec inetd style - * do_pty =3D 1 Fork/exec using slirp.telnetd - * do_ptr =3D 2 Fork/exec using pty */ int -fork_exec(struct socket *so, const char *ex, int do_pty) +fork_exec(struct socket *so, const char *ex) { int s; struct sockaddr_in addr; @@ -99,26 +95,20 @@ fork_exec(struct socket *so, const char *ex, int do_pty) DEBUG_CALL("fork_exec"); DEBUG_ARG("so =3D %p", so); DEBUG_ARG("ex =3D %p", ex); - DEBUG_ARG("do_pty =3D %x", do_pty); - - if (do_pty =3D=3D 2) { - return 0; - } else { - addr.sin_family =3D AF_INET; - addr.sin_port =3D 0; - addr.sin_addr.s_addr =3D INADDR_ANY; =20 - if ((s =3D qemu_socket(AF_INET, SOCK_STREAM, 0)) < 0 || - bind(s, (struct sockaddr *)&addr, addrlen) < 0 || - listen(s, 1) < 0) { - error_report("Error: inet socket: %s", strerror(errno)); - if (s >=3D 0) { - closesocket(s); - } + addr.sin_family =3D AF_INET; + addr.sin_port =3D 0; + addr.sin_addr.s_addr =3D INADDR_ANY; =20 - return 0; - } - } + s =3D qemu_socket(AF_INET, SOCK_STREAM, 0); + if (s < 0 || bind(s, (struct sockaddr *)&addr, addrlen) < 0 || + listen(s, 1) < 0) { + error_report("Error: inet socket: %s", strerror(errno)); + if (s >=3D 0) { + closesocket(s); + } + return 0; + } =20 pid =3D fork(); switch(pid) { @@ -151,13 +141,7 @@ fork_exec(struct socket *so, const char *ex, int do_pt= y) =20 i =3D 0; bptr =3D g_strdup(ex); /* No need to free() this */ - if (do_pty =3D=3D 1) { - /* Setup "slirp.telnetd -x" */ - argv[i++] =3D "slirp.telnetd"; - argv[i++] =3D "-x"; - argv[i++] =3D bptr; - } else - do { + do { /* Change the string into argv[] */ curarg =3D bptr; while (*bptr !=3D ' ' && *bptr !=3D (char)0) @@ -165,7 +149,7 @@ fork_exec(struct socket *so, const char *ex, int do_pty) c =3D *bptr; *bptr++ =3D (char)0; argv[i++] =3D g_strdup(curarg); - } while (c); + } while (c); =20 argv[i] =3D NULL; execvp(argv[0], (char **)argv); @@ -193,13 +177,6 @@ fork_exec(struct socket *so, const char *ex, int do_pt= y) opt =3D 1; qemu_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, siz= eof(int)); qemu_set_nonblock(so->s); - - /* Append the telnet options now */ - if (so->so_m !=3D NULL && do_pty =3D=3D 1) { - sbappend(so, so->so_m); - so->so_m =3D NULL; - } - return 1; } } diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c index 8d0f94b75f..a82efe78d7 100644 --- a/slirp/tcp_subr.c +++ b/slirp/tcp_subr.c @@ -973,7 +973,7 @@ int tcp_ctl(struct socket *so) } do_pty =3D ex_ptr->ex_pty; DEBUG_MISC((dfd, " executing %s\n", ex_ptr->ex_exec)); - return fork_exec(so, ex_ptr->ex_exec, do_pty); + return fork_exec(so, ex_ptr->ex_exec); } } } --=20 2.19.1.708.g4ede3d42df From nobody Sat Apr 27 12:08:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1541857947517341.06856502923665; Sat, 10 Nov 2018 05:52:27 -0800 (PST) Received: from localhost ([::1]:38486 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLTgY-0001gA-7z for importer@patchew.org; Sat, 10 Nov 2018 08:52:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36442) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLTb7-0004YX-82 for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:46:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gLTat-00080u-9t for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:46:42 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47914) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gLTaf-000729-La for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:46:24 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 03C80C058CAD; Sat, 10 Nov 2018 13:46:18 +0000 (UTC) Received: from localhost (ovpn-112-21.ams2.redhat.com [10.36.112.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id E34DE6013F; Sat, 10 Nov 2018 13:46:14 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 10 Nov 2018 17:45:38 +0400 Message-Id: <20181110134548.14741-4-marcandre.lureau@redhat.com> In-Reply-To: <20181110134548.14741-1-marcandre.lureau@redhat.com> References: <20181110134548.14741-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sat, 10 Nov 2018 13:46:18 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-3.2 03/13] slirp: replace ex_pty with ex_chardev X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Kiszka , Jason Wang , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" do_pty =3D=3D 3 means to talk to a chardev. Signed-off-by: Marc-Andr=C3=A9 Lureau --- slirp/misc.h | 2 +- slirp/misc.c | 2 +- slirp/slirp.c | 4 ++-- slirp/tcp_subr.c | 4 +--- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/slirp/misc.h b/slirp/misc.h index 897650aea1..1f8d11def6 100644 --- a/slirp/misc.h +++ b/slirp/misc.h @@ -9,7 +9,7 @@ #define MISC_H =20 struct ex_list { - int ex_pty; /* Do we want a pty? */ + int ex_chardev; struct in_addr ex_addr; /* Server address */ int ex_fport; /* Port to telnet to */ const char *ex_exec; /* Command line of what to exec */ diff --git a/slirp/misc.c b/slirp/misc.c index ec5d5ec073..aa3c4b9771 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -53,7 +53,7 @@ int add_exec(struct ex_list **ex_ptr, int do_pty, char *e= xec, *ex_ptr =3D g_new(struct ex_list, 1); (*ex_ptr)->ex_fport =3D port; (*ex_ptr)->ex_addr =3D addr; - (*ex_ptr)->ex_pty =3D do_pty; + (*ex_ptr)->ex_chardev =3D do_pty =3D=3D 3; (*ex_ptr)->ex_exec =3D (do_pty =3D=3D 3) ? exec : g_strdup(exec); (*ex_ptr)->ex_next =3D tmp_ptr; return 0; diff --git a/slirp/slirp.c b/slirp/slirp.c index 878d6174a2..eb468facb1 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -1444,7 +1444,7 @@ static void slirp_state_save(QEMUFile *f, void *opaqu= e) struct ex_list *ex_ptr; =20 for (ex_ptr =3D slirp->exec_list; ex_ptr; ex_ptr =3D ex_ptr->ex_next) - if (ex_ptr->ex_pty =3D=3D 3) { + if (ex_ptr->ex_chardev) { struct socket *so; so =3D slirp_find_ctl_socket(slirp, ex_ptr->ex_addr, ntohs(ex_ptr->ex_fport)); @@ -1482,7 +1482,7 @@ static int slirp_state_load(QEMUFile *f, void *opaque= , int version_id) return -EINVAL; } for (ex_ptr =3D slirp->exec_list; ex_ptr; ex_ptr =3D ex_ptr->ex_ne= xt) { - if (ex_ptr->ex_pty =3D=3D 3 && + if (ex_ptr->ex_chardev && so->so_faddr.s_addr =3D=3D ex_ptr->ex_addr.s_addr && so->so_fport =3D=3D ex_ptr->ex_fport) { break; diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c index a82efe78d7..c534b0224b 100644 --- a/slirp/tcp_subr.c +++ b/slirp/tcp_subr.c @@ -956,7 +956,6 @@ int tcp_ctl(struct socket *so) Slirp *slirp =3D so->slirp; struct sbuf *sb =3D &so->so_snd; struct ex_list *ex_ptr; - int do_pty; =20 DEBUG_CALL("tcp_ctl"); DEBUG_ARG("so =3D %p", so); @@ -966,12 +965,11 @@ int tcp_ctl(struct socket *so) for (ex_ptr =3D slirp->exec_list; ex_ptr; ex_ptr =3D ex_ptr->ex_ne= xt) { if (ex_ptr->ex_fport =3D=3D so->so_fport && so->so_faddr.s_addr =3D=3D ex_ptr->ex_addr.s_addr) { - if (ex_ptr->ex_pty =3D=3D 3) { + if (ex_ptr->ex_chardev) { so->s =3D -1; so->extra =3D (void *)ex_ptr->ex_exec; return 1; } - do_pty =3D ex_ptr->ex_pty; DEBUG_MISC((dfd, " executing %s\n", ex_ptr->ex_exec)); return fork_exec(so, ex_ptr->ex_exec); } --=20 2.19.1.708.g4ede3d42df From nobody Sat Apr 27 12:08:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1541857955742765.786176579264; Sat, 10 Nov 2018 05:52:35 -0800 (PST) Received: from localhost ([::1]:38487 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLTgg-0001mG-LL for importer@patchew.org; Sat, 10 Nov 2018 08:52:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36535) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLTbC-0004dk-CF for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:46:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gLTb7-0008OX-9L for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:46:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56340) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gLTb0-0007fX-B6 for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:46:45 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 18B2C3082A25; Sat, 10 Nov 2018 13:46:26 +0000 (UTC) Received: from localhost (ovpn-112-21.ams2.redhat.com [10.36.112.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id F405610002B9; Sat, 10 Nov 2018 13:46:21 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 10 Nov 2018 17:45:39 +0400 Message-Id: <20181110134548.14741-5-marcandre.lureau@redhat.com> In-Reply-To: <20181110134548.14741-1-marcandre.lureau@redhat.com> References: <20181110134548.14741-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Sat, 10 Nov 2018 13:46:26 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-3.2 04/13] slirp: use a dedicated field for chardev pointer X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Kiszka , Jason Wang , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Let's not mix command line and chardev pointers. Signed-off-by: Marc-Andr=C3=A9 Lureau --- slirp/libslirp.h | 2 +- slirp/misc.h | 4 ++-- net/slirp.c | 8 ++++---- slirp/misc.c | 11 +++++++---- slirp/slirp.c | 5 +++-- slirp/tcp_subr.c | 2 +- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/slirp/libslirp.h b/slirp/libslirp.h index 52dbb9feb5..3e88dbaa01 100644 --- a/slirp/libslirp.h +++ b/slirp/libslirp.h @@ -35,7 +35,7 @@ int slirp_add_hostfwd(Slirp *slirp, int is_udp, struct in_addr guest_addr, int guest_port); int slirp_remove_hostfwd(Slirp *slirp, int is_udp, struct in_addr host_addr, int host_port); -int slirp_add_exec(Slirp *slirp, int do_pty, const void *args, +int slirp_add_exec(Slirp *slirp, void *chardev, const char *cmdline, struct in_addr *guest_addr, int guest_port); =20 void slirp_connection_info(Slirp *slirp, Monitor *mon); diff --git a/slirp/misc.h b/slirp/misc.h index 1f8d11def6..64ca88c3b7 100644 --- a/slirp/misc.h +++ b/slirp/misc.h @@ -9,7 +9,7 @@ #define MISC_H =20 struct ex_list { - int ex_chardev; + void *ex_chardev; struct in_addr ex_addr; /* Server address */ int ex_fport; /* Port to telnet to */ const char *ex_exec; /* Command line of what to exec */ @@ -52,7 +52,7 @@ struct slirp_quehead { =20 void slirp_insque(void *, void *); void slirp_remque(void *); -int add_exec(struct ex_list **, int, char *, struct in_addr, int); +int add_exec(struct ex_list **, void *, const char *, struct in_addr, int); int fork_exec(struct socket *so, const char *ex); =20 #endif diff --git a/net/slirp.c b/net/slirp.c index 1dbd34a9da..0bb12567fe 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -709,8 +709,8 @@ static int slirp_smb(SlirpState* s, const char *exporte= d_dir, CONFIG_SMBD_COMMAND, s->smb_dir, smb_conf); g_free(smb_conf); =20 - if (slirp_add_exec(s->slirp, 0, smb_cmdline, &vserver_addr, 139) < 0 || - slirp_add_exec(s->slirp, 0, smb_cmdline, &vserver_addr, 445) < 0) { + if (slirp_add_exec(s->slirp, NULL, smb_cmdline, &vserver_addr, 139) < = 0 || + slirp_add_exec(s->slirp, NULL, smb_cmdline, &vserver_addr, 445) < = 0) { slirp_smb_cleanup(s); g_free(smb_cmdline); error_setg(errp, "Conflicting/invalid smbserver address"); @@ -774,7 +774,7 @@ static int slirp_guestfwd(SlirpState *s, const char *co= nfig_str, Error **errp) snprintf(buf, sizeof(buf), "guestfwd.tcp.%d", port); =20 if ((strlen(p) > 4) && !strncmp(p, "cmd:", 4)) { - if (slirp_add_exec(s->slirp, 0, &p[4], &server, port) < 0) { + if (slirp_add_exec(s->slirp, NULL, &p[4], &server, port) < 0) { error_setg(errp, "Conflicting/invalid host:port in guest " "forwarding rule '%s'", config_str); return -1; @@ -801,7 +801,7 @@ static int slirp_guestfwd(SlirpState *s, const char *co= nfig_str, Error **errp) return -1; } =20 - if (slirp_add_exec(s->slirp, 3, &fwd->hd, &server, port) < 0) { + if (slirp_add_exec(s->slirp, &fwd->hd, NULL, &server, port) < 0) { error_setg(errp, "Conflicting/invalid host:port in guest " "forwarding rule '%s'", config_str); g_free(fwd); diff --git a/slirp/misc.c b/slirp/misc.c index aa3c4b9771..1e9415e729 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -37,7 +37,7 @@ remque(void *a) element->qh_rlink =3D NULL; } =20 -int add_exec(struct ex_list **ex_ptr, int do_pty, char *exec, +int add_exec(struct ex_list **ex_ptr, void *chardev, const char *cmdline, struct in_addr addr, int port) { struct ex_list *tmp_ptr; @@ -50,11 +50,14 @@ int add_exec(struct ex_list **ex_ptr, int do_pty, char = *exec, } =20 tmp_ptr =3D *ex_ptr; - *ex_ptr =3D g_new(struct ex_list, 1); + *ex_ptr =3D g_new0(struct ex_list, 1); (*ex_ptr)->ex_fport =3D port; (*ex_ptr)->ex_addr =3D addr; - (*ex_ptr)->ex_chardev =3D do_pty =3D=3D 3; - (*ex_ptr)->ex_exec =3D (do_pty =3D=3D 3) ? exec : g_strdup(exec); + if (chardev) { + (*ex_ptr)->ex_chardev =3D chardev; + } else { + (*ex_ptr)->ex_exec =3D g_strdup(cmdline); + } (*ex_ptr)->ex_next =3D tmp_ptr; return 0; } diff --git a/slirp/slirp.c b/slirp/slirp.c index eb468facb1..58d1ef64e9 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -1068,7 +1068,7 @@ int slirp_add_hostfwd(Slirp *slirp, int is_udp, struc= t in_addr host_addr, return 0; } =20 -int slirp_add_exec(Slirp *slirp, int do_pty, const void *args, +int slirp_add_exec(Slirp *slirp, void *chardev, const char *cmdline, struct in_addr *guest_addr, int guest_port) { if (!guest_addr->s_addr) { @@ -1081,7 +1081,8 @@ int slirp_add_exec(Slirp *slirp, int do_pty, const vo= id *args, guest_addr->s_addr =3D=3D slirp->vnameserver_addr.s_addr) { return -1; } - return add_exec(&slirp->exec_list, do_pty, (char *)args, *guest_addr, + + return add_exec(&slirp->exec_list, chardev, cmdline, *guest_addr, htons(guest_port)); } =20 diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c index c534b0224b..e0bf7ad070 100644 --- a/slirp/tcp_subr.c +++ b/slirp/tcp_subr.c @@ -967,7 +967,7 @@ int tcp_ctl(struct socket *so) so->so_faddr.s_addr =3D=3D ex_ptr->ex_addr.s_addr) { if (ex_ptr->ex_chardev) { so->s =3D -1; - so->extra =3D (void *)ex_ptr->ex_exec; + so->extra =3D ex_ptr->ex_chardev; return 1; } DEBUG_MISC((dfd, " executing %s\n", ex_ptr->ex_exec)); --=20 2.19.1.708.g4ede3d42df From nobody Sat Apr 27 12:08:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1541857763498830.4370494224167; Sat, 10 Nov 2018 05:49:23 -0800 (PST) Received: from localhost ([::1]:38470 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLTda-000801-AY for importer@patchew.org; Sat, 10 Nov 2018 08:49:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36543) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLTbC-0004e3-E0 for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:46:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gLTb8-0008SN-GK for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:46:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47452) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gLTb8-0007uu-3c for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:46:50 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A58722D7FF; Sat, 10 Nov 2018 13:46:33 +0000 (UTC) Received: from localhost (ovpn-112-21.ams2.redhat.com [10.36.112.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2DD305D968; Sat, 10 Nov 2018 13:46:29 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 10 Nov 2018 17:45:40 +0400 Message-Id: <20181110134548.14741-6-marcandre.lureau@redhat.com> In-Reply-To: <20181110134548.14741-1-marcandre.lureau@redhat.com> References: <20181110134548.14741-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sat, 10 Nov 2018 13:46:33 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-3.2 05/13] slirp: remove unused EMU_RSH X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Kiszka , Jason Wang , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" EMU_RSH handling was dropped in commit 0d62c4cfe21752df4c1d6e2c2398f15d5eaa794a. The assignment, and subsequent free() of ex_ptr->ex_exec to so->extra looks unsafe (double free is likely to occur). Signed-off-by: Marc-Andr=C3=A9 Lureau --- slirp/misc.h | 1 - slirp/slirp.c | 2 -- slirp/socket.c | 4 ---- slirp/tcp_subr.c | 1 - 4 files changed, 8 deletions(-) diff --git a/slirp/misc.h b/slirp/misc.h index 64ca88c3b7..94829722cd 100644 --- a/slirp/misc.h +++ b/slirp/misc.h @@ -26,7 +26,6 @@ struct ex_list { #define EMU_REALAUDIO 0x5 #define EMU_RLOGIN 0x6 #define EMU_IDENT 0x7 -#define EMU_RSH 0x8 =20 #define EMU_NOCONNECT 0x10 /* Don't connect */ =20 diff --git a/slirp/slirp.c b/slirp/slirp.c index 58d1ef64e9..daa0d5d4bd 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -1491,8 +1491,6 @@ static int slirp_state_load(QEMUFile *f, void *opaque= , int version_id) } if (!ex_ptr) return -EINVAL; - - so->extra =3D (void *)ex_ptr->ex_exec; } =20 return vmstate_load_state(f, &vmstate_slirp, slirp, version_id); diff --git a/slirp/socket.c b/slirp/socket.c index 322383a1f9..ff6ef1e334 100644 --- a/slirp/socket.c +++ b/slirp/socket.c @@ -91,10 +91,6 @@ sofree(struct socket *so) soqfree(so, &slirp->if_fastq); soqfree(so, &slirp->if_batchq); =20 - if (so->so_emu=3D=3DEMU_RSH && so->extra) { - sofree(so->extra); - so->extra=3DNULL; - } if (so =3D=3D slirp->tcp_last_so) { slirp->tcp_last_so =3D &slirp->tcb; } else if (so =3D=3D slirp->udp_last_so) { diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c index e0bf7ad070..eb894b6527 100644 --- a/slirp/tcp_subr.c +++ b/slirp/tcp_subr.c @@ -546,7 +546,6 @@ static const struct tos_t tcptos[] =3D { {0, 23, IPTOS_LOWDELAY, 0}, /* telnet */ {0, 80, IPTOS_THROUGHPUT, 0}, /* WWW */ {0, 513, IPTOS_LOWDELAY, EMU_RLOGIN|EMU_NOCONNECT}, /* rlogin */ - {0, 514, IPTOS_LOWDELAY, EMU_RSH|EMU_NOCONNECT}, /* shell */ {0, 544, IPTOS_LOWDELAY, EMU_KSH}, /* kshell */ {0, 543, IPTOS_LOWDELAY, 0}, /* klogin */ {0, 6667, IPTOS_THROUGHPUT, EMU_IRC}, /* IRC */ --=20 2.19.1.708.g4ede3d42df From nobody Sat Apr 27 12:08:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1541858129574917.6440890903009; Sat, 10 Nov 2018 05:55:29 -0800 (PST) Received: from localhost ([::1]:38499 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLTjU-0005zv-E5 for importer@patchew.org; Sat, 10 Nov 2018 08:55:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36536) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLTbC-0004dq-CL for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:46:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gLTb8-0008Sg-Iu for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:46:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47974) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gLTb8-00087D-8Q for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:46:50 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4DBAFC0587D2; Sat, 10 Nov 2018 13:46:39 +0000 (UTC) Received: from localhost (ovpn-112-21.ams2.redhat.com [10.36.112.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 09EBB5D968; Sat, 10 Nov 2018 13:46:37 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 10 Nov 2018 17:45:41 +0400 Message-Id: <20181110134548.14741-7-marcandre.lureau@redhat.com> In-Reply-To: <20181110134548.14741-1-marcandre.lureau@redhat.com> References: <20181110134548.14741-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sat, 10 Nov 2018 13:46:39 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-3.2 06/13] slirp: rename /extra/chardev X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Kiszka , Jason Wang , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Now it's only used for the chardev pointer. Signed-off-by: Marc-Andr=C3=A9 Lureau --- slirp/socket.h | 2 +- slirp/slirp.c | 4 ++-- slirp/tcp_subr.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/slirp/socket.h b/slirp/socket.h index 2f224bc34f..930ed95972 100644 --- a/slirp/socket.h +++ b/slirp/socket.h @@ -67,7 +67,7 @@ struct socket { =20 struct sbuf so_rcv; /* Receive buffer */ struct sbuf so_snd; /* Send buffer */ - void * extra; /* Extra pointer */ + void * chardev; }; =20 =20 diff --git a/slirp/slirp.c b/slirp/slirp.c index daa0d5d4bd..d6623a2bbf 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -1088,10 +1088,10 @@ int slirp_add_exec(Slirp *slirp, void *chardev, con= st char *cmdline, =20 ssize_t slirp_send(struct socket *so, const void *buf, size_t len, int fla= gs) { - if (so->s =3D=3D -1 && so->extra) { + if (so->s =3D=3D -1 && so->chardev) { /* XXX this blocks entire thread. Rewrite to use * qemu_chr_fe_write and background I/O callbacks */ - qemu_chr_fe_write_all(so->extra, buf, len); + qemu_chr_fe_write_all(so->chardev, buf, len); return len; } =20 diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c index eb894b6527..9b8a11159d 100644 --- a/slirp/tcp_subr.c +++ b/slirp/tcp_subr.c @@ -966,7 +966,7 @@ int tcp_ctl(struct socket *so) so->so_faddr.s_addr =3D=3D ex_ptr->ex_addr.s_addr) { if (ex_ptr->ex_chardev) { so->s =3D -1; - so->extra =3D ex_ptr->ex_chardev; + so->chardev =3D ex_ptr->ex_chardev; return 1; } DEBUG_MISC((dfd, " executing %s\n", ex_ptr->ex_exec)); --=20 2.19.1.708.g4ede3d42df From nobody Sat Apr 27 12:08:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 154185789078827.673961983716595; Sat, 10 Nov 2018 05:51:30 -0800 (PST) Received: from localhost ([::1]:38485 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLTfd-00015E-NY for importer@patchew.org; Sat, 10 Nov 2018 08:51:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36537) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLTbC-0004e1-Cr for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:46:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gLTb8-0008S9-Ey for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:46:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47998) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gLTb8-0008M0-2M for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:46:50 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 63185C058CAD; Sat, 10 Nov 2018 13:46:47 +0000 (UTC) Received: from localhost (ovpn-112-21.ams2.redhat.com [10.36.112.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4873960C44; Sat, 10 Nov 2018 13:46:42 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 10 Nov 2018 17:45:42 +0400 Message-Id: <20181110134548.14741-8-marcandre.lureau@redhat.com> In-Reply-To: <20181110134548.14741-1-marcandre.lureau@redhat.com> References: <20181110134548.14741-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sat, 10 Nov 2018 13:46:47 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-3.2 07/13] slirp: move internal function declarations X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Kiszka , Jason Wang , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Clarify that those functions are internal to slirp. Signed-off-by: Marc-Andr=C3=A9 Lureau --- slirp/libslirp.h | 3 --- slirp/slirp.h | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/slirp/libslirp.h b/slirp/libslirp.h index 3e88dbaa01..a4f390ee89 100644 --- a/slirp/libslirp.h +++ b/slirp/libslirp.h @@ -7,9 +7,6 @@ typedef struct Slirp Slirp; =20 typedef void (*slirp_output)(void *opaque, const uint8_t *pkt, int pkt_len= ); =20 -int get_dns_addr(struct in_addr *pdns_addr); -int get_dns6_addr(struct in6_addr *pdns6_addr, uint32_t *scope_id); - Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork, struct in_addr vnetmask, struct in_addr vhost, bool in6_enabled, diff --git a/slirp/slirp.h b/slirp/slirp.h index e3d65d68ec..de299aa36c 100644 --- a/slirp/slirp.h +++ b/slirp/slirp.h @@ -232,6 +232,9 @@ extern Slirp *slirp_instance; =20 void if_start(Slirp *); =20 +int get_dns_addr(struct in_addr *pdns_addr); +int get_dns6_addr(struct in6_addr *pdns6_addr, uint32_t *scope_id); + /* ncsi.c */ void ncsi_input(Slirp *slirp, const uint8_t *pkt, int pkt_len); =20 --=20 2.19.1.708.g4ede3d42df From nobody Sat Apr 27 12:08:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1541857967337637.753154550049; Sat, 10 Nov 2018 05:52:47 -0800 (PST) Received: from localhost ([::1]:38488 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLTgs-0001yI-4R for importer@patchew.org; Sat, 10 Nov 2018 08:52:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36625) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLTbE-0004he-VH for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:46:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gLTbD-0000EZ-Py for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:46:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50448) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gLTbD-0000CJ-EJ for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:46:55 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A26323290; Sat, 10 Nov 2018 13:46:54 +0000 (UTC) Received: from localhost (ovpn-112-21.ams2.redhat.com [10.36.112.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 45820605C5; Sat, 10 Nov 2018 13:46:50 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 10 Nov 2018 17:45:43 +0400 Message-Id: <20181110134548.14741-9-marcandre.lureau@redhat.com> In-Reply-To: <20181110134548.14741-1-marcandre.lureau@redhat.com> References: <20181110134548.14741-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sat, 10 Nov 2018 13:46:54 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-3.2 08/13] slirp: remove Monitor dependency, return a string for info X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Kiszka , Jason Wang , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" There is nothing performance-sensitive in returning an allocated string for info, and handling the monitor_printf() on the caller side. Signed-off-by: Marc-Andr=C3=A9 Lureau --- slirp/libslirp.h | 2 +- net/slirp.c | 7 ++++--- slirp/misc.c | 23 +++++++++++++---------- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/slirp/libslirp.h b/slirp/libslirp.h index a4f390ee89..04b6db9f49 100644 --- a/slirp/libslirp.h +++ b/slirp/libslirp.h @@ -35,7 +35,7 @@ int slirp_remove_hostfwd(Slirp *slirp, int is_udp, int slirp_add_exec(Slirp *slirp, void *chardev, const char *cmdline, struct in_addr *guest_addr, int guest_port); =20 -void slirp_connection_info(Slirp *slirp, Monitor *mon); +char *slirp_connection_info(Slirp *slirp); =20 void slirp_socket_recv(Slirp *slirp, struct in_addr guest_addr, int guest_port, const uint8_t *buf, int size); diff --git a/net/slirp.c b/net/slirp.c index 0bb12567fe..dfc72cfc2e 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -828,10 +828,11 @@ void hmp_info_usernet(Monitor *mon, const QDict *qdic= t) QTAILQ_FOREACH(s, &slirp_stacks, entry) { int id; bool got_hub_id =3D net_hub_id_for_client(&s->nc, &id) =3D=3D 0; - monitor_printf(mon, "Hub %d (%s):\n", + char *info =3D slirp_connection_info(s->slirp); + monitor_printf(mon, "Hub %d (%s):\n%s", got_hub_id ? id : -1, - s->nc.name); - slirp_connection_info(s->slirp, mon); + s->nc.name, info); + g_free(info); } } =20 diff --git a/slirp/misc.c b/slirp/misc.c index 1e9415e729..54edc0b0b9 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -8,7 +8,6 @@ #include "qemu/osdep.h" #include "slirp.h" #include "libslirp.h" -#include "monitor/monitor.h" #include "qemu/error-report.h" #include "qemu/main-loop.h" =20 @@ -185,8 +184,9 @@ fork_exec(struct socket *so, const char *ex) } #endif =20 -void slirp_connection_info(Slirp *slirp, Monitor *mon) +char *slirp_connection_info(Slirp *slirp) { + GString *str =3D g_string_new(NULL); const char * const tcpstates[] =3D { [TCPS_CLOSED] =3D "CLOSED", [TCPS_LISTEN] =3D "LISTEN", @@ -208,8 +208,9 @@ void slirp_connection_info(Slirp *slirp, Monitor *mon) const char *state; char buf[20]; =20 - monitor_printf(mon, " Protocol[State] FD Source Address Port " - "Dest. Address Port RecvQ SendQ\n"); + g_string_append_printf(str, + " Protocol[State] FD Source Address Port " + "Dest. Address Port RecvQ SendQ\n"); =20 for (so =3D slirp->tcb.so_next; so !=3D &slirp->tcb; so =3D so->so_nex= t) { if (so->so_state & SS_HOSTFWD) { @@ -231,10 +232,10 @@ void slirp_connection_info(Slirp *slirp, Monitor *mon) dst_port =3D so->so_fport; } snprintf(buf, sizeof(buf), " TCP[%s]", state); - monitor_printf(mon, "%-19s %3d %15s %5d ", buf, so->s, + g_string_append_printf(str, "%-19s %3d %15s %5d ", buf, so->s, src.sin_addr.s_addr ? inet_ntoa(src.sin_addr) : "*", ntohs(src.sin_port)); - monitor_printf(mon, "%15s %5d %5d %5d\n", + g_string_append_printf(str, "%15s %5d %5d %5d\n", inet_ntoa(dst_addr), ntohs(dst_port), so->so_rcv.sb_cc, so->so_snd.sb_cc); } @@ -254,10 +255,10 @@ void slirp_connection_info(Slirp *slirp, Monitor *mon) dst_addr =3D so->so_faddr; dst_port =3D so->so_fport; } - monitor_printf(mon, "%-19s %3d %15s %5d ", buf, so->s, + g_string_append_printf(str, "%-19s %3d %15s %5d ", buf, so->s, src.sin_addr.s_addr ? inet_ntoa(src.sin_addr) : "*", ntohs(src.sin_port)); - monitor_printf(mon, "%15s %5d %5d %5d\n", + g_string_append_printf(str, "%15s %5d %5d %5d\n", inet_ntoa(dst_addr), ntohs(dst_port), so->so_rcv.sb_cc, so->so_snd.sb_cc); } @@ -267,9 +268,11 @@ void slirp_connection_info(Slirp *slirp, Monitor *mon) (so->so_expire - curtime) / 1000); src.sin_addr =3D so->so_laddr; dst_addr =3D so->so_faddr; - monitor_printf(mon, "%-19s %3d %15s - ", buf, so->s, + g_string_append_printf(str, "%-19s %3d %15s - ", buf, so->s, src.sin_addr.s_addr ? inet_ntoa(src.sin_addr) : "*"= ); - monitor_printf(mon, "%15s - %5d %5d\n", inet_ntoa(dst_addr), + g_string_append_printf(str, "%15s - %5d %5d\n", inet_ntoa(dst_= addr), so->so_rcv.sb_cc, so->so_snd.sb_cc); } + + return g_string_free(str, FALSE); } --=20 2.19.1.708.g4ede3d42df From nobody Sat Apr 27 12:08:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1541858261420861.7380822583178; Sat, 10 Nov 2018 05:57:41 -0800 (PST) Received: from localhost ([::1]:38516 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLTlc-0007cB-AA for importer@patchew.org; Sat, 10 Nov 2018 08:57:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36727) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLTbR-0004od-I7 for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:47:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gLTbM-0000cF-Hy for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:47:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48018) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gLTbM-0000bn-BZ for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:47:04 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A89ECC058CAD; Sat, 10 Nov 2018 13:47:03 +0000 (UTC) Received: from localhost (ovpn-112-21.ams2.redhat.com [10.36.112.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E6DD5C20B; Sat, 10 Nov 2018 13:46:58 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 10 Nov 2018 17:45:44 +0400 Message-Id: <20181110134548.14741-10-marcandre.lureau@redhat.com> In-Reply-To: <20181110134548.14741-1-marcandre.lureau@redhat.com> References: <20181110134548.14741-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sat, 10 Nov 2018 13:47:03 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-3.2 09/13] slirp: fix slirp_add_exec() leaks X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Kiszka , Jason Wang , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Free the list elements allocated in add_exec(). Signed-off-by: Marc-Andr=C3=A9 Lureau --- slirp/misc.h | 2 +- slirp/slirp.c | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/slirp/misc.h b/slirp/misc.h index 94829722cd..0bc5e74bc5 100644 --- a/slirp/misc.h +++ b/slirp/misc.h @@ -12,7 +12,7 @@ struct ex_list { void *ex_chardev; struct in_addr ex_addr; /* Server address */ int ex_fport; /* Port to telnet to */ - const char *ex_exec; /* Command line of what to exec */ + char *ex_exec; /* Command line of what to exec */ struct ex_list *ex_next; }; =20 diff --git a/slirp/slirp.c b/slirp/slirp.c index d6623a2bbf..29fe4702cc 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -342,6 +342,14 @@ Slirp *slirp_init(int restricted, bool in_enabled, str= uct in_addr vnetwork, =20 void slirp_cleanup(Slirp *slirp) { + struct ex_list *e, *next; + + for (e =3D slirp->exec_list; e; e =3D next) { + next =3D e->ex_next; + g_free(e->ex_exec); + g_free(e); + } + QTAILQ_REMOVE(&slirp_instances, slirp, entry); =20 unregister_savevm(NULL, "slirp", slirp); --=20 2.19.1.708.g4ede3d42df From nobody Sat Apr 27 12:08:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1541858139906164.36088237893716; Sat, 10 Nov 2018 05:55:39 -0800 (PST) Received: from localhost ([::1]:38502 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLTje-0006A6-Jf for importer@patchew.org; Sat, 10 Nov 2018 08:55:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36744) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLTbY-0004uz-Ql for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:47:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gLTbW-0001CB-9R for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:47:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54106) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gLTbV-00014v-7J for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:47:13 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9105E85540; Sat, 10 Nov 2018 13:47:12 +0000 (UTC) Received: from localhost (ovpn-112-21.ams2.redhat.com [10.36.112.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC2EE19754; Sat, 10 Nov 2018 13:47:07 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 10 Nov 2018 17:45:45 +0400 Message-Id: <20181110134548.14741-11-marcandre.lureau@redhat.com> In-Reply-To: <20181110134548.14741-1-marcandre.lureau@redhat.com> References: <20181110134548.14741-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sat, 10 Nov 2018 13:47:12 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-3.2 10/13] slirp: improve subprocess socket creation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Kiszka , Jason Wang , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Fix a bunch of error handling issues by creating the "TCP socketpair" from the parent process. (the code is currently disabled on Windows: at first I thought a socketpair() could be used, but I realized that slirp calls MSG_OOB on the socket, which isn't implemented on Linux) Signed-off-by: Marc-Andr=C3=A9 Lureau --- slirp/misc.c | 133 ++++++++++++++++++++++++++++----------------------- 1 file changed, 72 insertions(+), 61 deletions(-) diff --git a/slirp/misc.c b/slirp/misc.c index 54edc0b0b9..d9804f2a6d 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -73,42 +73,75 @@ fork_exec(struct socket *so, const char *ex) =20 #else =20 -/* - * XXX This is ugly - * We create and bind a socket, then fork off to another - * process, which connects to this socket, after which we - * exec the wanted program. If something (strange) happens, - * the accept() call could block us forever. - */ +static int +slirp_socketpair_with_oob(int sv[2]) +{ + struct sockaddr_in addr =3D { + .sin_family =3D AF_INET, + .sin_port =3D 0, + .sin_addr.s_addr =3D INADDR_ANY, + }; + socklen_t addrlen =3D sizeof(addr); + int ret, s; + + sv[1] =3D -1; + s =3D qemu_socket(AF_INET, SOCK_STREAM, 0); + if (s < 0 || bind(s, (struct sockaddr *)&addr, addrlen) < 0 || + listen(s, 1) < 0 || + getsockname(s, (struct sockaddr *)&addr, &addrlen) < 0) { + goto err; + } + + sv[1] =3D qemu_socket(AF_INET, SOCK_STREAM, 0); + if (sv[1] < 0) { + goto err; + } + + qemu_set_nonblock(sv[1]); + do { + ret =3D connect(sv[1], (struct sockaddr *)&addr, addrlen); + } while (ret < 0 && errno =3D=3D EINTR); + if (ret =3D=3D -1 && errno !=3D EINPROGRESS) { + goto err; + } + qemu_set_block(sv[1]); + + do { + sv[0] =3D accept(s, (struct sockaddr *)&addr, &addrlen); + } while (sv[0] < 0 && errno =3D=3D EINTR); + if (sv[0] < 0) { + goto err; + } + + closesocket(s); + return 0; + +err: + error_report("Error: slirp_socketpair(): %s", strerror(errno)); + if (s >=3D 0) { + closesocket(s); + } + if (sv[1] >=3D 0) { + closesocket(sv[1]); + } + return -1; +} + int fork_exec(struct socket *so, const char *ex) { - int s; - struct sockaddr_in addr; - socklen_t addrlen =3D sizeof(addr); - int opt; const char *argv[256]; /* don't want to clobber the original */ char *bptr; const char *curarg; - int c, i, ret; + int opt, c, i, sp[2]; pid_t pid; =20 DEBUG_CALL("fork_exec"); DEBUG_ARG("so =3D %p", so); DEBUG_ARG("ex =3D %p", ex); =20 - addr.sin_family =3D AF_INET; - addr.sin_port =3D 0; - addr.sin_addr.s_addr =3D INADDR_ANY; - - s =3D qemu_socket(AF_INET, SOCK_STREAM, 0); - if (s < 0 || bind(s, (struct sockaddr *)&addr, addrlen) < 0 || - listen(s, 1) < 0) { - error_report("Error: inet socket: %s", strerror(errno)); - if (s >=3D 0) { - closesocket(s); - } + if (slirp_socketpair_with_oob(sp) < 0) { return 0; } =20 @@ -116,30 +149,17 @@ fork_exec(struct socket *so, const char *ex) switch(pid) { case -1: error_report("Error: fork failed: %s", strerror(errno)); - close(s); + closesocket(sp[0]); + closesocket(sp[1]); return 0; =20 case 0: - setsid(); - - /* Set the DISPLAY */ - getsockname(s, (struct sockaddr *)&addr, &addrlen); - close(s); - /* - * Connect to the socket - * XXX If any of these fail, we're in trouble! - */ - s =3D qemu_socket(AF_INET, SOCK_STREAM, 0); - addr.sin_addr =3D loopback_addr; - do { - ret =3D connect(s, (struct sockaddr *)&addr, addrlen); - } while (ret < 0 && errno =3D=3D EINTR); - - dup2(s, 0); - dup2(s, 1); - dup2(s, 2); - for (s =3D getdtablesize() - 1; s >=3D 3; s--) - close(s); + setsid(); + dup2(sp[1], 0); + dup2(sp[1], 1); + dup2(sp[1], 2); + for (c =3D getdtablesize() - 1; c >=3D 3; c--) + close(c); =20 i =3D 0; bptr =3D g_strdup(ex); /* No need to free() this */ @@ -163,23 +183,14 @@ fork_exec(struct socket *so, const char *ex) exit(1); =20 default: - qemu_add_child_watch(pid); - /* - * XXX this could block us... - * XXX Should set a timer here, and if accept() doesn't - * return after X seconds, declare it a failure - * The only reason this will block forever is if socket() - * of connect() fail in the child process - */ - do { - so->s =3D accept(s, (struct sockaddr *)&addr, &addrlen= ); - } while (so->s < 0 && errno =3D=3D EINTR); - closesocket(s); - socket_set_fast_reuse(so->s); - opt =3D 1; - qemu_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, siz= eof(int)); - qemu_set_nonblock(so->s); - return 1; + so->s =3D sp[0]; + closesocket(sp[1]); + qemu_add_child_watch(pid); + socket_set_fast_reuse(so->s); + opt =3D 1; + qemu_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int= )); + qemu_set_nonblock(so->s); + return 1; } } #endif --=20 2.19.1.708.g4ede3d42df From nobody Sat Apr 27 12:08:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1541858363016342.4991419925018; Sat, 10 Nov 2018 05:59:23 -0800 (PST) Received: from localhost ([::1]:38521 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLTnA-0002HA-UG for importer@patchew.org; Sat, 10 Nov 2018 08:59:16 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36770) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLTbe-0004wV-Nb for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:47:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gLTbd-0001a8-TM for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:47:22 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38264) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gLTbd-0001Y0-NH for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:47:21 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1433B308625A; Sat, 10 Nov 2018 13:47:21 +0000 (UTC) Received: from localhost (ovpn-112-21.ams2.redhat.com [10.36.112.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id A5DD360C44; Sat, 10 Nov 2018 13:47:16 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 10 Nov 2018 17:45:46 +0400 Message-Id: <20181110134548.14741-12-marcandre.lureau@redhat.com> In-Reply-To: <20181110134548.14741-1-marcandre.lureau@redhat.com> References: <20181110134548.14741-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Sat, 10 Nov 2018 13:47:21 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-3.2 11/13] slirp: replace the poor-man string split with g_strsplit() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Kiszka , Jason Wang , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Use the glib function for the work, fix a potential crash on >256 words. Signed-off-by: Marc-Andr=C3=A9 Lureau --- slirp/misc.c | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/slirp/misc.c b/slirp/misc.c index d9804f2a6d..dedc9bf6c3 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -130,11 +130,8 @@ err: int fork_exec(struct socket *so, const char *ex) { - const char *argv[256]; - /* don't want to clobber the original */ - char *bptr; - const char *curarg; - int opt, c, i, sp[2]; + char **argv; + int opt, c, sp[2]; pid_t pid; =20 DEBUG_CALL("fork_exec"); @@ -161,19 +158,7 @@ fork_exec(struct socket *so, const char *ex) for (c =3D getdtablesize() - 1; c >=3D 3; c--) close(c); =20 - i =3D 0; - bptr =3D g_strdup(ex); /* No need to free() this */ - do { - /* Change the string into argv[] */ - curarg =3D bptr; - while (*bptr !=3D ' ' && *bptr !=3D (char)0) - bptr++; - c =3D *bptr; - *bptr++ =3D (char)0; - argv[i++] =3D g_strdup(curarg); - } while (c); - - argv[i] =3D NULL; + argv =3D g_strsplit(ex, " ", -1); execvp(argv[0], (char **)argv); =20 /* Ooops, failed, let's tell the user why */ --=20 2.19.1.708.g4ede3d42df From nobody Sat Apr 27 12:08:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1541858086018949.617577219723; Sat, 10 Nov 2018 05:54:46 -0800 (PST) Received: from localhost ([::1]:38497 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLTii-0005TX-7s for importer@patchew.org; Sat, 10 Nov 2018 08:54:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36818) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLTbt-0005Cq-DR for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:47:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gLTbn-0001t9-Su for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:47:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54176) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gLTbn-0001ns-AW for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:47:31 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ECEED6380C; Sat, 10 Nov 2018 13:47:28 +0000 (UTC) Received: from localhost (ovpn-112-21.ams2.redhat.com [10.36.112.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id EE73D1057066; Sat, 10 Nov 2018 13:47:24 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 10 Nov 2018 17:45:47 +0400 Message-Id: <20181110134548.14741-13-marcandre.lureau@redhat.com> In-Reply-To: <20181110134548.14741-1-marcandre.lureau@redhat.com> References: <20181110134548.14741-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sat, 10 Nov 2018 13:47:29 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-3.2 12/13] glib-compat: add g_spawn_async_with_fds() fallback X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Kiszka , Jason Wang , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau --- include/glib-compat.h | 56 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/include/glib-compat.h b/include/glib-compat.h index fdf95a255d..4a10c9691f 100644 --- a/include/glib-compat.h +++ b/include/glib-compat.h @@ -83,6 +83,62 @@ static inline gboolean g_strv_contains_qemu(const gchar = *const *strv, } #define g_strv_contains(a, b) g_strv_contains_qemu(a, b) =20 +#if !GLIB_CHECK_VERSION(2, 58, 0) +typedef struct QemuGSpawnFds { + GSpawnChildSetupFunc child_setup; + gpointer user_data; + gint stdin_fd; + gint stdout_fd; + gint stderr_fd; +} QemuGSpawnFds; + +static inline void +qemu_gspawn_fds_setup(gpointer user_data) +{ + QemuGSpawnFds *q =3D user_data; + + dup2(q->stdin_fd, 0); + dup2(q->stdout_fd, 1); + dup2(q->stderr_fd, 2); + q->child_setup(q->user_data); +} +#endif + +static inline gboolean +g_spawn_async_with_fds_qemu(const gchar *working_directory, + gchar **argv, + gchar **envp, + GSpawnFlags flags, + GSpawnChildSetupFunc child_setup, + gpointer user_data, + GPid *child_pid, + gint stdin_fd, + gint stdout_fd, + gint stderr_fd, + GError **error) +{ +#if GLIB_CHECK_VERSION(2, 58, 0) + return g_spawn_async_with_fds(working_directory, argv, envp, flags, + child_setup, user_data, + child_pid, stdin_fd, stdout_fd, stderr_f= d, + error); +#else + QemuGSpawnFds setup =3D { + .child_setup =3D child_setup, + .user_data =3D user_data, + .stdin_fd =3D stdin_fd, + .stdout_fd =3D stdout_fd, + .stderr_fd =3D stderr_fd, + }; + + return g_spawn_async(working_directory, argv, envp, flags, + qemu_gspawn_fds_setup, &setup, + child_pid, error); +#endif +} + +#define g_spawn_async_with_fds(wd, argv, env, f, c, d, p, ifd, ofd, efd, e= rr) \ + g_spawn_async_with_fds_qemu(wd, argv, env, f, c, d, p, ifd, ofd, efd, = err) =20 #if defined(_WIN32) && !GLIB_CHECK_VERSION(2, 50, 0) /* --=20 2.19.1.708.g4ede3d42df From nobody Sat Apr 27 12:08:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1541858229647142.83210396366496; Sat, 10 Nov 2018 05:57:09 -0800 (PST) Received: from localhost ([::1]:38514 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLTl3-0007F8-SV for importer@patchew.org; Sat, 10 Nov 2018 08:57:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36848) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLTby-0005d6-C9 for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:47:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gLTbu-0001wp-QH for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:47:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38444) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gLTbt-0001w0-KM for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:47:38 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E908B308625A; Sat, 10 Nov 2018 13:47:36 +0000 (UTC) Received: from localhost (ovpn-112-21.ams2.redhat.com [10.36.112.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id D192F608DA; Sat, 10 Nov 2018 13:47:32 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Sat, 10 Nov 2018 17:45:48 +0400 Message-Id: <20181110134548.14741-14-marcandre.lureau@redhat.com> In-Reply-To: <20181110134548.14741-1-marcandre.lureau@redhat.com> References: <20181110134548.14741-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Sat, 10 Nov 2018 13:47:37 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-3.2 13/13] slirp: simplify fork_exec() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Kiszka , Jason Wang , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Use g_spawn_async_with_fds() to setup the child. GSpawn handles reaping the child, and closing parent file descriptors. Signed-off-by: Marc-Andr=C3=A9 Lureau --- slirp/misc.c | 77 +++++++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/slirp/misc.c b/slirp/misc.c index dedc9bf6c3..f99e3a8fcc 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -127,56 +127,53 @@ err: return -1; } =20 +static void +fork_exec_child_setup(gpointer data) +{ + setsid(); +} + int fork_exec(struct socket *so, const char *ex) { - char **argv; - int opt, c, sp[2]; - pid_t pid; + GError *err =3D NULL; + char **argv; + int opt, sp[2]; =20 - DEBUG_CALL("fork_exec"); - DEBUG_ARG("so =3D %p", so); - DEBUG_ARG("ex =3D %p", ex); + DEBUG_CALL("fork_exec"); + DEBUG_ARG("so =3D %p", so); + DEBUG_ARG("ex =3D %p", ex); =20 if (slirp_socketpair_with_oob(sp) < 0) { return 0; } =20 - pid =3D fork(); - switch(pid) { - case -1: - error_report("Error: fork failed: %s", strerror(errno)); - closesocket(sp[0]); - closesocket(sp[1]); - return 0; - - case 0: - setsid(); - dup2(sp[1], 0); - dup2(sp[1], 1); - dup2(sp[1], 2); - for (c =3D getdtablesize() - 1; c >=3D 3; c--) - close(c); - - argv =3D g_strsplit(ex, " ", -1); - execvp(argv[0], (char **)argv); - - /* Ooops, failed, let's tell the user why */ - fprintf(stderr, "Error: execvp of %s failed: %s\n", - argv[0], strerror(errno)); - close(0); close(1); close(2); /* XXX */ - exit(1); + argv =3D g_strsplit(ex, " ", -1); + g_spawn_async_with_fds(NULL /* cwd */, + argv, + NULL /* env */, + G_SPAWN_SEARCH_PATH, + fork_exec_child_setup, NULL /* data */, + NULL /* child_pid */, + sp[1], sp[1], sp[1], + &err); + g_strfreev(argv); + + if (err) { + error_report("%s", err->message); + g_error_free(err); + closesocket(sp[0]); + closesocket(sp[1]); + return 0; + } =20 - default: - so->s =3D sp[0]; - closesocket(sp[1]); - qemu_add_child_watch(pid); - socket_set_fast_reuse(so->s); - opt =3D 1; - qemu_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int= )); - qemu_set_nonblock(so->s); - return 1; - } + so->s =3D sp[0]; + closesocket(sp[1]); + socket_set_fast_reuse(so->s); + opt =3D 1; + qemu_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int)); + qemu_set_nonblock(so->s); + return 1; } #endif =20 --=20 2.19.1.708.g4ede3d42df