From patchwork Thu Dec 9 03:41:58 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Congyang X-Patchwork-Id: 74885 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 E8092B70A5 for ; Fri, 10 Dec 2010 00:03:39 +1100 (EST) Received: from localhost ([127.0.0.1]:43464 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQg9m-0001Ez-Nd for incoming@patchwork.ozlabs.org; Thu, 09 Dec 2010 08:03:34 -0500 Received: from [140.186.70.92] (port=39372 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQXNR-0001uU-45 for qemu-devel@nongnu.org; Wed, 08 Dec 2010 22:41:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PQXNP-0007sz-PB for qemu-devel@nongnu.org; Wed, 08 Dec 2010 22:41:04 -0500 Received: from [222.73.24.84] (port=57653 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PQXNP-0007rc-Dm for qemu-devel@nongnu.org; Wed, 08 Dec 2010 22:41:03 -0500 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 304FC170607 for ; Thu, 9 Dec 2010 11:40:49 +0800 (CST) Received: from mailserver.fnst.cn.fujitus.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id oB93a5X1026397 for ; Thu, 9 Dec 2010 11:36:06 +0800 Received: from [10.167.225.226] ([10.167.225.226]) by mailserver.fnst.cn.fujitus.com (Lotus Domino Release 8.5.1FP4) with ESMTP id 2010120911405108-193572 ; Thu, 9 Dec 2010 11:40:51 +0800 Message-ID: <4D005006.9080307@cn.fujitsu.com> Date: Thu, 09 Dec 2010 11:41:58 +0800 From: Wen Congyang User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100413 Fedora/3.0.4-2.fc13 Thunderbird/3.0.4 MIME-Version: 1.0 To: qemu-devel X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2010-12-09 11:40:51, Serialize by Router on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2010-12-09 11:40:54, Serialize complete at 2010-12-09 11:40:54 X-detected-operating-system: by eggs.gnu.org: FreeBSD 6.x (1) Subject: [Qemu-devel] [PATCH] disable sigcld handling before calling pclose() 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 When I use the command 'virsh save' to save the domain state, I receive the following error message: operation failed: Migration unexpectedly failed. I debug the qemu by adding some printf(), and find the function pclose() returns -1. I use strace to trace qemu, the log is as the following: ====== close(17) = 0 --- SIGCHLD (Child exited) @ 0 (0) --- wait4(-1, NULL, WNOHANG, NULL) = 22016 rt_sigreturn(0) = 0 wait4(22016, 0x7fff7f1034fc, 0, NULL) = -1 ECHILD (No child processes) ====== We wait the child twice: one is in signal SIGCHLD handling and the other one is in pclose(). We should disable sigcld handling before calling pclose(). Signed-off-by: Wen Congyang --- os-posix.c | 19 +++++++++++++++++++ qemu-os-posix.h | 2 ++ savevm.c | 2 ++ 3 files changed, 23 insertions(+), 0 deletions(-) diff --git a/os-posix.c b/os-posix.c index 38c29d1..b163995 100644 --- a/os-posix.c +++ b/os-posix.c @@ -86,6 +86,25 @@ void os_setup_signal_handling(void) sigaction(SIGCHLD, &act, NULL); } +void os_stop_sigchld_handling(void) +{ + struct sigaction act; + + memset(&act, 0, sizeof(act)); + act.sa_handler = SIG_DFL; + sigaction(SIGCHLD, &act, NULL); +} + +void os_resume_sigchld_handling(void) +{ + struct sigaction act; + + memset(&act, 0, sizeof(act)); + act.sa_handler = sigchld_handler; + act.sa_flags = SA_NOCLDSTOP; + sigaction(SIGCHLD, &act, NULL); +} + /* Find a likely location for support files using the location of the binary. For installed binaries this will be "$bindir/../share/qemu". When running from the build tree this will be "$bindir/../pc-bios". */ diff --git a/qemu-os-posix.h b/qemu-os-posix.h index 353f878..e819295 100644 --- a/qemu-os-posix.h +++ b/qemu-os-posix.h @@ -33,6 +33,8 @@ static inline void os_host_main_loop_wait(int *timeout) void os_set_line_buffering(void); void os_set_proc_name(const char *s); void os_setup_signal_handling(void); +void os_stop_sigchld_handling(void); +void os_resume_sigchld_handling(void); void os_daemonize(void); void os_setup_post(void); diff --git a/savevm.c b/savevm.c index d38f79e..08a5f88 100644 --- a/savevm.c +++ b/savevm.c @@ -234,7 +234,9 @@ static int stdio_pclose(void *opaque) { QEMUFileStdio *s = opaque; int ret; + os_stop_sigchld_handling(); ret = pclose(s->stdio_file); + os_resume_sigchld_handling(); qemu_free(s); return ret; }