chiark / gitweb /
efi: efi_get_boot_options() should already sort the entries, the random order in...
[elogind.git] / src / shared / util.c
index aa0532a2be71e1f27888b4da94fe1240187c7069..4f0b652f4f7aa18ad184af36bd365260ca5c726c 100644 (file)
@@ -183,18 +183,25 @@ bool first_word(const char *s, const char *word) {
 }
 
 int close_nointr(int fd) {
-        assert(fd >= 0);
-
-        for (;;) {
-                int r;
+        int r;
 
-                r = close(fd);
-                if (r >= 0)
-                        return r;
+        assert(fd >= 0);
+        r = close(fd);
 
-                if (errno != EINTR)
-                        return -errno;
-        }
+        /* 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 < 0 && errno == EINTR))
+                return 0;
+        else if (r >= 0)
+                return r;
+        else
+                return -errno;
 }
 
 void close_nointr_nofail(int fd) {
@@ -1070,6 +1077,7 @@ int get_process_exe(pid_t pid, char **name) {
 static int get_process_id(pid_t pid, const char *field, uid_t *uid) {
         _cleanup_fclose_ FILE *f = NULL;
         _cleanup_free_ char *p = NULL;
+        char line[LINE_MAX];
 
         assert(field);
         assert(uid);
@@ -1084,7 +1092,7 @@ static int get_process_id(pid_t pid, const char *field, uid_t *uid) {
         if (!f)
                 return -errno;
 
-        FOREACH_LINE(f, line, return -errno) {
+        FOREACH_LINE(line, f, return -errno) {
                 char *l;
 
                 l = strstrip(line);