From patchwork Tue Aug 25 06:17:22 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 32022 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 bilbo.ozlabs.org (Postfix) with ESMTPS id A72A5B6F2B for ; Tue, 25 Aug 2009 16:24:45 +1000 (EST) Received: from localhost ([127.0.0.1]:42365 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MfpSO-00058R-Gh for incoming@patchwork.ozlabs.org; Tue, 25 Aug 2009 02:24:36 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MfpMa-0003L4-Td for qemu-devel@nongnu.org; Tue, 25 Aug 2009 02:18:36 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MfpMW-0003FE-5j for qemu-devel@nongnu.org; Tue, 25 Aug 2009 02:18:36 -0400 Received: from [199.232.76.173] (port=59748 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MfpMW-0003F2-0p for qemu-devel@nongnu.org; Tue, 25 Aug 2009 02:18:32 -0400 Received: from mx20.gnu.org ([199.232.41.8]:55843) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MfpMV-0002Ll-C2 for qemu-devel@nongnu.org; Tue, 25 Aug 2009 02:18:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MfpMU-0007BO-M5 for qemu-devel@nongnu.org; Tue, 25 Aug 2009 02:18:30 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n7P6Ho9A010401; Tue, 25 Aug 2009 02:17:50 -0400 Received: from localhost (vpn-12-87.rdu.redhat.com [10.11.12.87]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n7P6HlOa031463; Tue, 25 Aug 2009 02:17:49 -0400 From: Amit Shah To: qemu-devel@nongnu.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Date: Tue, 25 Aug 2009 11:47:22 +0530 Message-Id: <1251181044-3696-3-git-send-email-amit.shah@redhat.com> In-Reply-To: <1251181044-3696-2-git-send-email-amit.shah@redhat.com> References: <1251181044-3696-1-git-send-email-amit.shah@redhat.com> <1251181044-3696-2-git-send-email-amit.shah@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-Detected-Operating-System: by mx20.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Amit Shah Subject: [Qemu-devel] [PATCH 1/3] char: Emit 'CLOSED' events on char device close 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 Notify users of the char interface whenever the file / connection is closed. Signed-off-by: Amit Shah --- qemu-char.c | 10 ++++++++++ qemu-char.h | 1 + 2 files changed, 11 insertions(+), 0 deletions(-) diff --git a/qemu-char.c b/qemu-char.c index be27994..c25ed1c 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -570,6 +570,7 @@ static void fd_chr_read(void *opaque) if (size == 0) { /* FD has been closed. Remove it from the active list. */ qemu_set_fd_handler2(s->fd_in, NULL, NULL, NULL, NULL); + qemu_chr_event(chr, CHR_EVENT_CLOSED); return; } if (size > 0) { @@ -602,6 +603,7 @@ static void fd_chr_close(struct CharDriverState *chr) } qemu_free(s); + qemu_chr_event(chr, CHR_EVENT_CLOSED); } /* open a character device to a unix fd */ @@ -690,6 +692,7 @@ static void stdio_read(void *opaque) if (size == 0) { /* stdin has been closed. Remove it from the active list. */ qemu_set_fd_handler2(0, NULL, NULL, NULL, NULL); + qemu_chr_event(chr, CHR_EVENT_CLOSED); return; } if (size > 0) { @@ -943,6 +946,7 @@ static void pty_chr_close(struct CharDriverState *chr) qemu_del_timer(s->timer); qemu_free_timer(s->timer); qemu_free(s); + qemu_chr_event(chr, CHR_EVENT_CLOSED); } static CharDriverState *qemu_chr_open_pty(void) @@ -1264,6 +1268,7 @@ static void pp_close(CharDriverState *chr) ioctl(fd, PPRELEASE); close(fd); qemu_free(drv); + qemu_chr_event(chr, CHR_EVENT_CLOSED); } static CharDriverState *qemu_chr_open_pp(const char *filename) @@ -1390,6 +1395,8 @@ static void win_chr_close(CharDriverState *chr) qemu_del_polling_cb(win_chr_pipe_poll, chr); else qemu_del_polling_cb(win_chr_poll, chr); + + qemu_chr_event(chr, CHR_EVENT_CLOSED); } static int win_chr_init(CharDriverState *chr, const char *filename) @@ -1779,6 +1786,7 @@ static void udp_chr_close(CharDriverState *chr) closesocket(s->fd); } qemu_free(s); + qemu_chr_event(chr, CHR_EVENT_CLOSED); } static CharDriverState *qemu_chr_open_udp(const char *def) @@ -1999,6 +2007,7 @@ static void tcp_chr_read(void *opaque) qemu_set_fd_handler(s->fd, NULL, NULL, NULL); closesocket(s->fd); s->fd = -1; + qemu_chr_event(chr, CHR_EVENT_CLOSED); } else if (size > 0) { if (s->do_telnetopt) tcp_chr_process_IAC_bytes(chr, s, buf, &size); @@ -2095,6 +2104,7 @@ static void tcp_chr_close(CharDriverState *chr) closesocket(s->listen_fd); } qemu_free(s); + qemu_chr_event(chr, CHR_EVENT_CLOSED); } static CharDriverState *qemu_chr_open_tcp(const char *host_str, diff --git a/qemu-char.h b/qemu-char.h index 77d4eda..df620bc 100644 --- a/qemu-char.h +++ b/qemu-char.h @@ -11,6 +11,7 @@ #define CHR_EVENT_RESET 2 /* new connection established */ #define CHR_EVENT_MUX_IN 3 /* mux-focus was set to this terminal */ #define CHR_EVENT_MUX_OUT 4 /* mux-focus will move on */ +#define CHR_EVENT_CLOSED 5 /* connection closed */ #define CHR_IOCTL_SERIAL_SET_PARAMS 1