Lightly tested in gnome-ostree qemu - review carefully please!

See the linked references for why we should not do this.

Signed-off-by: Colin Walters <walt...@verbum.org>
---
 src/shared/util.c |   28 +++++++++++++++++-----------
 1 files changed, 17 insertions(+), 11 deletions(-)


>From 628879d838207753f31c5f5379db5da45d36ab81 Mon Sep 17 00:00:00 2001
From: Colin Walters <walt...@verbum.org>
Date: Fri, 25 Jan 2013 11:21:20 -0500
Subject: [PATCH] util: *DO NOT* loop for EINTR handling with close_nointr()

See the linked references for why we should not do this.

Signed-off-by: Colin Walters <walt...@verbum.org>
---
 src/shared/util.c |   28 +++++++++++++++++-----------
 1 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/src/shared/util.c b/src/shared/util.c
index 490399c..220036a 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -183,17 +183,23 @@ bool first_word(const char *s, const char *word) {
 
 int close_nointr(int fd) {
         assert(fd >= 0);
+        int r;
 
-        for (;;) {
-                int r;
-
-                r = close(fd);
-                if (r >= 0)
-                        return r;
-
-                if (errno != EINTR)
-                        return -errno;
-        }
+        r = close(fd);
+        /* Just ignore EINTR; a retry loop is the wrong
+         * thing to do on Linux.
+         *
+         * http://lkml.indiana.edu/hypermail/linux/kernel/0509.1/0877.html
+         * https://bugzilla.gnome.org/show_bug.cgi?id=682819
+         * http://utcc.utoronto.ca/~cks/space/blog/unix/CloseEINTR
+         * https://sites.google.com/site/michaelsafyan/software-engineering/checkforeintrwheninvokingclosethinkagain
+         */
+        if (_unlikely_ (r == -1 && errno == EINTR))
+                return 0;
+        else if (r >= 0)
+                return r;
+        else
+                return -errno;
 }
 
 void close_nointr_nofail(int fd) {
-- 
1.7.1

_______________________________________________
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to