From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43375) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vfuw9-0005RP-CO for qemu-devel@nongnu.org; Mon, 11 Nov 2013 12:06:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vfuw0-0001zy-Uz for qemu-devel@nongnu.org; Mon, 11 Nov 2013 12:06:05 -0500 Received: from mail-qc0-x22d.google.com ([2607:f8b0:400d:c01::22d]:54698) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vfuw0-0001zl-Fr for qemu-devel@nongnu.org; Mon, 11 Nov 2013 12:05:56 -0500 Received: by mail-qc0-f173.google.com with SMTP id m4so1392195qcy.32 for ; Mon, 11 Nov 2013 09:05:55 -0800 (PST) Sender: Paolo Bonzini Message-ID: <52810E6F.1010505@redhat.com> Date: Mon, 11 Nov 2013 18:05:51 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <52810AEA.5020806@redhat.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] audit needed for signal handlers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: "qemu-devel@nongnu.org" Il 11/11/2013 17:56, Anthony Liguori ha scritto: > On Mon, Nov 11, 2013 at 8:50 AM, Eric Blake wrote: >> Quick - identify the bug in this code (from ui/curses.c): >> >> static void curses_winch_handler(int signum) >> { >> struct winsize { >> unsigned short ws_row; >> unsigned short ws_col; >> unsigned short ws_xpixel; /* unused */ >> unsigned short ws_ypixel; /* unused */ >> } ws; >> >> /* terminal size changed */ >> if (ioctl(1, TIOCGWINSZ, &ws) == -1) >> return; >> >> resize_term(ws.ws_row, ws.ws_col); >> curses_calc_pad(); >> invalidate = 1; >> >> /* some systems require this */ >> signal(SIGWINCH, curses_winch_handler); >> } >> >> Here's a hint: ioctl() can clobber errno. But if a signal handler is >> called in the middle of other code that is using errno, then the handler >> MUST restore the value of errno before returning, if it is to guarantee >> that the interrupted context won't be corrupted. > > Isn't this precisely why EINTR exists? No. do { rc = read(...); } while (rc == -1 && errno == EINTR); /* signal handler runs here */ if (errno == EAGAIN) { ... } That said, aren't all signals in QEMU (except SIG_IPI) caught with signalfd and the handlers run synchronously in the iothread? Paolo