From patchwork Sat Oct 17 16:59:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 531799 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id DA1BE1402B9 for ; Sun, 18 Oct 2015 04:00:46 +1100 (AEDT) Received: from localhost ([::1]:59119 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZnUqa-00052q-QO for incoming@patchwork.ozlabs.org; Sat, 17 Oct 2015 13:00:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35059) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZnUpp-0003qx-U3 for qemu-devel@nongnu.org; Sat, 17 Oct 2015 12:59:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZnUpl-0006aw-Mk for qemu-devel@nongnu.org; Sat, 17 Oct 2015 12:59:57 -0400 Received: from e19.ny.us.ibm.com ([129.33.205.209]:36341) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZnUpl-0006aP-JD for qemu-devel@nongnu.org; Sat, 17 Oct 2015 12:59:53 -0400 Received: from localhost by e19.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sat, 17 Oct 2015 12:59:50 -0400 Received: from d01dlp03.pok.ibm.com (9.56.250.168) by e19.ny.us.ibm.com (146.89.104.206) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sat, 17 Oct 2015 12:59:49 -0400 X-IBM-Helo: d01dlp03.pok.ibm.com X-IBM-MailFrom: mdroth@linux.vnet.ibm.com X-IBM-RcptTo: qemu-devel@nongnu.org Received: from b01cxnp22036.gho.pok.ibm.com (b01cxnp22036.gho.pok.ibm.com [9.57.198.26]) by d01dlp03.pok.ibm.com (Postfix) with ESMTP id 295B3C90041 for ; Sat, 17 Oct 2015 12:48:00 -0400 (EDT) Received: from d01av04.pok.ibm.com (d01av04.pok.ibm.com [9.56.224.64]) by b01cxnp22036.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t9HGxmTH52035698 for ; Sat, 17 Oct 2015 16:59:48 GMT Received: from d01av04.pok.ibm.com (localhost [127.0.0.1]) by d01av04.pok.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t9HGxmnc022392 for ; Sat, 17 Oct 2015 12:59:48 -0400 Received: from localhost ([9.80.88.62]) by d01av04.pok.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t9HGxlwD022362; Sat, 17 Oct 2015 12:59:48 -0400 From: Michael Roth To: qemu-devel@nongnu.org Date: Sat, 17 Oct 2015 11:59:17 -0500 Message-Id: <1445101160-13772-11-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1445101160-13772-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1445101160-13772-1-git-send-email-mdroth@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15101716-0057-0000-0000-000001FF15D3 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 129.33.205.209 Cc: peter.maydell@linaro.org, Yuri Pudgorodskiy , Michael Roth , "Denis V. Lunev" Subject: [Qemu-devel] [PULL v3 10/13] qga: handle possible SIGPIPE in guest-file-write X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: "Denis V. Lunev" qemu-ga should not exit on guest-file-write to pipe without read end but proper error code should be returned. The behavior of the spawned process should be default thus SIGPIPE processing should be reset to default after fork() but before exec(). Signed-off-by: Denis V. Lunev Signed-off-by: Yuri Pudgorodskiy Reviewed-by: Michael Roth Signed-off-by: Denis V. Lunev Signed-off-by: Michael Roth --- qga/commands.c | 18 +++++++++++++++++- qga/main.c | 6 ++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/qga/commands.c b/qga/commands.c index ced72d5..68e8cfa 100644 --- a/qga/commands.c +++ b/qga/commands.c @@ -225,6 +225,22 @@ static void guest_exec_child_watch(GPid pid, gint status, gpointer data) g_spawn_close_pid(pid); } +/** Reset ignored signals back to default. */ +static void guest_exec_task_setup(gpointer data) +{ +#if !defined(G_OS_WIN32) + struct sigaction sigact; + + memset(&sigact, 0, sizeof(struct sigaction)); + sigact.sa_handler = SIG_DFL; + + if (sigaction(SIGPIPE, &sigact, NULL) != 0) { + slog("sigaction() failed to reset child process's SIGPIPE: %s", + strerror(errno)); + } +#endif +} + GuestExec *qmp_guest_exec(const char *path, bool has_arg, strList *arg, bool has_env, strList *env, @@ -250,7 +266,7 @@ GuestExec *qmp_guest_exec(const char *path, G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL, - NULL, NULL, &pid, NULL, NULL, NULL, &gerr); + guest_exec_task_setup, NULL, &pid, NULL, NULL, NULL, &gerr); if (!ret) { error_setg(err, QERR_QGA_COMMAND_FAILED, gerr->message); g_error_free(gerr); diff --git a/qga/main.c b/qga/main.c index aa6a063..068169f 100644 --- a/qga/main.c +++ b/qga/main.c @@ -161,6 +161,12 @@ static gboolean register_signal_handlers(void) g_error("error configuring signal handler: %s", strerror(errno)); } + sigact.sa_handler = SIG_IGN; + if (sigaction(SIGPIPE, &sigact, NULL) != 0) { + g_error("error configuring SIGPIPE signal handler: %s", + strerror(errno)); + } + return true; }