From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48298) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b88sc-0003l1-TD for qemu-devel@nongnu.org; Wed, 01 Jun 2016 12:20:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b88sa-00049I-JK for qemu-devel@nongnu.org; Wed, 01 Jun 2016 12:20:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60962) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b88sa-00049D-Db for qemu-devel@nongnu.org; Wed, 01 Jun 2016 12:20:24 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 15DACC05B1F2 for ; Wed, 1 Jun 2016 16:20:24 +0000 (UTC) References: <1464712247-11655-1-git-send-email-wexu@redhat.com> <1464712247-11655-3-git-send-email-wexu@redhat.com> <574DC93E.4000700@redhat.com> From: Wei Xu Message-ID: <574F0B42.2010306@redhat.com> Date: Thu, 2 Jun 2016 00:20:18 +0800 MIME-Version: 1.0 In-Reply-To: <574DC93E.4000700@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [RFC Patch 2/3] chardev: save the passed in 'fd' parameter during parsing List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: armbru@redhat.com, amit.shah@redhat.com, berrange@redhat.com, jasowang@redhat.com, mprivozn@redhat.com, qemu-devel@nongnu.org On 2016=E5=B9=B406=E6=9C=8801=E6=97=A5 01:26, Eric Blake wrote: > On 05/31/2016 10:30 AM, wexu@redhat.com wrote: >> From: Wei Xu >> >> Save the 'fd' paramter as unix socket 'sockfd' member. >> >> Signed-off-by: Wei Xu >> --- >> qemu-char.c | 7 +++++++ >> 1 file changed, 7 insertions(+) >> >> diff --git a/qemu-char.c b/qemu-char.c >> index ea9c02e..8d20494 100644 >> --- a/qemu-char.c >> +++ b/qemu-char.c >> @@ -3664,6 +3664,7 @@ static void qemu_chr_parse_socket(QemuOpts *opts= , ChardevBackend *backend, >> bool is_telnet =3D qemu_opt_get_bool(opts, "telnet", false)= ; >> bool do_nodelay =3D !qemu_opt_get_bool(opts, "delay", true); >> int64_t reconnect =3D qemu_opt_get_number(opts, "reconnect", 0= ); >> + const int32_t fd =3D (int32_t)qemu_opt_get_number(opts, "sockfd",= 0); >> const char *path =3D qemu_opt_get(opts, "path"); >> const char *host =3D qemu_opt_get(opts, "host"); >> const char *port =3D qemu_opt_get(opts, "port"); >> @@ -3708,6 +3709,12 @@ static void qemu_chr_parse_socket(QemuOpts *opt= s, ChardevBackend *backend, >> addr->type =3D SOCKET_ADDRESS_KIND_UNIX; >> q_unix =3D addr->u.q_unix.data =3D g_new0(UnixSocketAddress,= 1); >> q_unix->path =3D g_strdup(path); >> + >> + if (fd) { >> + q_unix->sockfd =3D fd; >> + } else { >> + q_unix->sockfd =3D 0; > > 0 is a valid fd number; this risks accidentally closing stdin later on. > Please use -1 for unset, if you must store an fd number. But given m= y > comments on patch 1, I'm not sure that you need this addition. Thanks for your comment, i just wonder what's the motivation of=20 qemu_open(), seems it's more like an regular file consideration, is it? can it be easily expended to socket file? >