From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:49076) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R4U8h-0002Vh-4p for qemu-devel@nongnu.org; Fri, 16 Sep 2011 04:51:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R4U8f-0001Z3-Ud for qemu-devel@nongnu.org; Fri, 16 Sep 2011 04:51:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40573) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R4U8f-0001Yq-Jq for qemu-devel@nongnu.org; Fri, 16 Sep 2011 04:51:13 -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.14.4/8.14.4) with ESMTP id p8G8pCxh012981 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 16 Sep 2011 04:51:12 -0400 From: Laszlo Ersek Date: Fri, 16 Sep 2011 10:52:14 +0200 Message-Id: <1316163134-12222-1-git-send-email-lersek@redhat.com> In-Reply-To: <1316107350-31172-1-git-send-email-lersek@redhat.com> References: <1316107350-31172-1-git-send-email-lersek@redhat.com> Subject: [Qemu-devel] [PATCH v2] main loop: fix some accesses made in sighandler context List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, lersek@redhat.com Make variables volatile. "sig_atomic_t" should cover "int" and "pid_t", but where it doesn't, the patch should still do no harm. Also replace calls to functions that are not required to be async-signal-safe [1]. termsig_handler() -> qemu_system_killed(): shutdown_signal, shutdown_pid, no_shutdown [2] -> qemu_system_shutdown_request(): shutdown_requested -> qemu_notify_event() -> qemu_event_increment(): fprintf(), strerror(), exit() [1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04_03_03 [2] http://lists.nongnu.org/archive/html/qemu-devel/2011-09/msg01757.html Build tested only. Signed-off-by: Laszlo Ersek --- cpus.c | 7 ++++--- sysemu.h | 2 +- vl.c | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cpus.c b/cpus.c index 54c188c..b38b334 100644 --- a/cpus.c +++ b/cpus.c @@ -289,9 +289,10 @@ static void qemu_event_increment(void) /* EAGAIN is fine, a read must be pending. */ if (ret < 0 && errno != EAGAIN) { - fprintf(stderr, "qemu_event_increment: write() failed: %s\n", - strerror(errno)); - exit (1); + static const char err[] = "qemu_event_increment: write() failed\n"; + + ret = write(STDERR_FILENO, err, sizeof err - 1u); + _exit(1); } } diff --git a/sysemu.h b/sysemu.h index 9090457..52a71ef 100644 --- a/sysemu.h +++ b/sysemu.h @@ -119,7 +119,7 @@ extern int max_cpus; extern int cursor_hide; extern int graphic_rotate; extern int no_quit; -extern int no_shutdown; +extern volatile int no_shutdown; extern int semihosting_enabled; extern int old_param; extern int boot_menu; diff --git a/vl.c b/vl.c index b773d2f..21bc6b4 100644 --- a/vl.c +++ b/vl.c @@ -215,7 +215,7 @@ int acpi_enabled = 1; int no_hpet = 0; int fd_bootchk = 1; int no_reboot = 0; -int no_shutdown = 0; +volatile int no_shutdown = 0; int cursor_hide = 1; int graphic_rotate = 0; uint8_t irq0override = 1; @@ -1178,8 +1178,8 @@ typedef struct QEMUResetEntry { static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers = QTAILQ_HEAD_INITIALIZER(reset_handlers); static int reset_requested; -static int shutdown_requested, shutdown_signal = -1; -static pid_t shutdown_pid; +static volatile int shutdown_requested, shutdown_signal = -1; +static volatile pid_t shutdown_pid; static int powerdown_requested; static int debug_requested; static int vmstop_requested; -- 1.7.4.4