From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1I2yhQ-0006gA-1F for qemu-devel@nongnu.org; Mon, 25 Jun 2007 20:14:28 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1I2yhO-0006dP-G9 for qemu-devel@nongnu.org; Mon, 25 Jun 2007 20:14:27 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I2yhO-0006d0-Bd for qemu-devel@nongnu.org; Mon, 25 Jun 2007 20:14:26 -0400 Received: from an-out-0708.google.com ([209.85.132.244]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1I2yhN-0002jr-TQ for qemu-devel@nongnu.org; Mon, 25 Jun 2007 20:14:26 -0400 Received: by an-out-0708.google.com with SMTP id d11so503444and for ; Mon, 25 Jun 2007 17:14:25 -0700 (PDT) Message-ID: Date: Mon, 25 Jun 2007 17:14:24 -0700 From: "Yigael Fleishman" MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_16224_1424770.1182816864947" Subject: [Qemu-devel] Missing system calls retries in case of EINTR Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: frederic.roussel@access-company.com ------=_Part_16224_1424770.1182816864947 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Running qemu on a Ubuntu Feisty host I've encountered an occasional failure-to-launch problem. I've used the "-serial /dev/ttyS0" at the command line, and qemu would often exit printing "could not open serial device". Looking in the srcs I've noticed that qemu_chr_open_tty does not retry the 'open' syscall if it fails and errno=EINTR. I've added a retry for such case and it seems to solve that specific problem (see the following patch). Furthermore, I've noticed that all open, read and some write calls in vl.care not retried in such cases. It seems to me retries should be implemented in those cases, however I might still be missing something here. --- /tmp/p4diff/vl.c#1.32670 2007-06-25 17:04:53.000000000 -0700 +++ vl.c 2007-06-25 17:04:29.000000000 -0700 @@ -1786,9 +1786,19 @@ CharDriverState *chr; int fd; - fd = open(filename, O_RDWR | O_NONBLOCK); - if (fd < 0) - return NULL; + /* The following code wraps the 'open' syscall and retries it in case it is interrupted. */ + while (1) + { + fd = open(filename, O_RDWR | O_NONBLOCK ); + + if (fd < 0) + { + if (errno != EINTR) + return NULL; + } + else + break; + } fcntl(fd, F_SETFL, O_NONBLOCK); tty_serial_init(fd, 115200, 'N', 8, 1); chr = qemu_chr_open_fd(fd, fd); ------=_Part_16224_1424770.1182816864947 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline Running qemu on a Ubuntu Feisty host I've encountered an occasional failure-to-launch problem.
I've used the "-serial /dev/ttyS0" at the command line, and qemu would often exit printing "could not open serial device".
Looking in the srcs I've noticed that  qemu_chr_open_tty does not retry the 'open' syscall if it fails and errno=EINTR.
I've added a retry for such case and it seems to solve that specific problem (see the following patch).
Furthermore, I've noticed that all open, read and some write calls in vl.c are not retried in such cases.
It seems to me retries should be implemented in those cases, however I might still be missing something here.

--- /tmp/p4diff/vl.c#1.32670    2007-06-25 17:04:53.000000000 -0700
+++ vl.c        2007-06-25 17:04:29.000000000 -0700
@@ -1786,9 +1786,19 @@
     CharDriverState *chr;
     int fd;
 
-    fd = open(filename, O_RDWR | O_NONBLOCK);
-    if (fd < 0)
-        return NULL;
+    /* The following code wraps the 'open' syscall and retries it in case it is interrupted. */
+    while (1)
+    {
+       fd = open(filename, O_RDWR | O_NONBLOCK );
+
+       if (fd < 0)
+       {
+           if (errno != EINTR)
+               return NULL;
+       }
+       else
+           break;
+    }
     fcntl(fd, F_SETFL, O_NONBLOCK);
     tty_serial_init(fd, 115200, 'N', 8, 1);
     chr = qemu_chr_open_fd(fd, fd);

------=_Part_16224_1424770.1182816864947--