From patchwork Mon Apr 26 15:47:33 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 50973 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A5DD1B7C48 for ; Tue, 27 Apr 2010 02:07:21 +1000 (EST) Received: from localhost ([127.0.0.1]:36408 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O6Qq5-0006aD-Jn for incoming@patchwork.ozlabs.org; Mon, 26 Apr 2010 12:07:17 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O6QYM-00010G-P9 for qemu-devel@nongnu.org; Mon, 26 Apr 2010 11:48:58 -0400 Received: from [140.186.70.92] (port=34829 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O6QYL-0000zN-2A for qemu-devel@nongnu.org; Mon, 26 Apr 2010 11:48:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O6QYI-0007Kh-Jg for qemu-devel@nongnu.org; Mon, 26 Apr 2010 11:48:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:26024) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O6QYI-0007KV-AX for qemu-devel@nongnu.org; Mon, 26 Apr 2010 11:48:54 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o3QFmr75001777 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 26 Apr 2010 11:48:53 -0400 Received: from localhost (vpn-8-143.rdu.redhat.com [10.11.8.143]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o3QFmp48021408; Mon, 26 Apr 2010 11:48:52 -0400 From: Luiz Capitulino To: aliguori@us.ibm.com Date: Mon, 26 Apr 2010 12:47:33 -0300 Message-Id: <1272296853-30285-10-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1272296853-30285-1-git-send-email-lcapitulino@redhat.com> References: <1272296853-30285-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Paolo Bonzini , qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 9/9] stash away SCM_RIGHTS fd until a getfd command arrives X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Paolo Bonzini If there is already a fd in s->msgfd before recvmsg it is closed by parts that this patch does not touch. So, only one descriptor can be "leaked" by attaching it to a command other than getfd. Signed-off-by: Paolo Bonzini Signed-off-by: Luiz Capitulino --- monitor.c | 9 --------- qemu-char.c | 9 +++------ 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/monitor.c b/monitor.c index 611cbe9..814b7dc 100644 --- a/monitor.c +++ b/monitor.c @@ -2414,15 +2414,6 @@ static int do_getfd(Monitor *mon, const QDict *qdict, QObject **ret_data) return -1; } - fd = dup(fd); - if (fd == -1) { - if (errno == EMFILE) - qerror_report(QERR_TOO_MANY_FILES); - else - qerror_report(QERR_UNDEFINED_ERROR); - return -1; - } - QLIST_FOREACH(monfd, &mon->fds, next) { if (strcmp(monfd->name, fdname) != 0) { continue; diff --git a/qemu-char.c b/qemu-char.c index 05df971..ac65a1c 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -2000,8 +2000,9 @@ static void tcp_chr_process_IAC_bytes(CharDriverState *chr, static int tcp_get_msgfd(CharDriverState *chr) { TCPCharDriver *s = chr->opaque; - - return s->msgfd; + int fd = s->msgfd; + s->msgfd = -1; + return fd; } #ifndef _WIN32 @@ -2089,10 +2090,6 @@ static void tcp_chr_read(void *opaque) tcp_chr_process_IAC_bytes(chr, s, buf, &size); if (size > 0) qemu_chr_read(chr, buf, size); - if (s->msgfd != -1) { - close(s->msgfd); - s->msgfd = -1; - } } }