Blame SOURCES/0002-Repeat-pututxline-if-it-fails-with-EINTR.patch

d83721
From 896b3694ca062d747cd67e9e9ba246adb3fc706b Mon Sep 17 00:00:00 2001
d83721
From: =?UTF-8?q?Ond=C5=99ej=20Lyson=C4=9Bk?= <olysonek@redhat.com>
d83721
Date: Mon, 5 Aug 2019 13:55:37 +0200
d83721
Subject: [PATCH 2/2] Repeat pututxline() if it fails with EINTR
d83721
d83721
This is a partial fix for rhbz#1688848. We cannot resolve it
d83721
completely until glibc bug rhbz#1734791 is fixed. See
d83721
https://bugzilla.redhat.com/show_bug.cgi?id=1688848#c13.
d83721
d83721
The maximum number of attempts is currently 2, which might seem
d83721
low. However setting it to 2 was a decision based on data - see
d83721
https://bugzilla.redhat.com/show_bug.cgi?id=1688848#c16.
d83721
d83721
Resolves: rhbz#1688848
d83721
---
d83721
 sysdeputil.c | 53 +++++++++++++++++++++++++++++++++++++++++++++-------
d83721
 1 file changed, 46 insertions(+), 7 deletions(-)
d83721
d83721
diff --git a/sysdeputil.c b/sysdeputil.c
d83721
index bd1e8c9..4fbcca7 100644
d83721
--- a/sysdeputil.c
d83721
+++ b/sysdeputil.c
d83721
@@ -1203,6 +1203,8 @@ void
d83721
 vsf_insert_uwtmp(const struct mystr* p_user_str,
d83721
                  const struct mystr* p_host_str)
d83721
 {
d83721
+  int attempts;
d83721
+
d83721
   if (sizeof(s_utent.ut_line) < 16)
d83721
   {
d83721
     return;
d83721
@@ -1231,16 +1233,35 @@ vsf_insert_uwtmp(const struct mystr* p_user_str,
d83721
   vsf_sysutil_strcpy(s_utent.ut_host, str_getbuf(p_host_str),
d83721
                      sizeof(s_utent.ut_host));
d83721
   s_utent.ut_tv.tv_sec = vsf_sysutil_get_time_sec();
d83721
-  setutxent();
d83721
-  (void) pututxline(&s_utent);
d83721
-  endutxent();
d83721
-  s_uwtmp_inserted = 1;
d83721
+  for (attempts = 2; attempts > 0; --attempts)
d83721
+  {
d83721
+    struct utmpx* p_res;
d83721
+    setutxent();
d83721
+    p_res = pututxline(&s_utent);
d83721
+    /* For now we'll ignore errors other than EINTR and EAGAIN */
d83721
+    if (p_res != NULL || (errno != EINTR && errno != EAGAIN))
d83721
+    {
d83721
+      break;
d83721
+    }
d83721
+  }
d83721
+  if (attempts == 0)
d83721
+  {
d83721
+    /* This makes us skip pututxline() in vsf_remove_uwtmp() */
d83721
+    s_uwtmp_inserted = -1;
d83721
+  }
d83721
+  else
d83721
+  {
d83721
+    s_uwtmp_inserted = 1;
d83721
+    endutxent();
d83721
+  }
d83721
   updwtmpx(WTMPX_FILE, &s_utent);
d83721
 }
d83721
 
d83721
 void
d83721
 vsf_remove_uwtmp(void)
d83721
 {
d83721
+  int attempts;
d83721
+
d83721
   if (!s_uwtmp_inserted)
d83721
   {
d83721
     return;
d83721
@@ -1249,9 +1270,27 @@ vsf_remove_uwtmp(void)
d83721
   vsf_sysutil_memclr(s_utent.ut_user, sizeof(s_utent.ut_user));
d83721
   vsf_sysutil_memclr(s_utent.ut_host, sizeof(s_utent.ut_host));
d83721
   s_utent.ut_tv.tv_sec = 0;
d83721
-  setutxent();
d83721
-  (void) pututxline(&s_utent);
d83721
-  endutxent();
d83721
+  if (s_uwtmp_inserted == 1)
d83721
+  {
d83721
+    for (attempts = 2; attempts > 0; --attempts)
d83721
+    {
d83721
+      struct utmpx* p_res;
d83721
+      setutxent();
d83721
+      p_res = pututxline(&s_utent);
d83721
+      /* For now we'll ignore errors other than EINTR and EAGAIN */
d83721
+      if (p_res != NULL || (errno != EINTR && errno != EAGAIN))
d83721
+      {
d83721
+        break;
d83721
+      }
d83721
+    }
d83721
+    if (attempts != 0)
d83721
+    {
d83721
+      endutxent();
d83721
+    }
d83721
+  }
d83721
+  /* Set s_uwtmp_inserted to 0 regardless of the result of
d83721
+   * pututxline() to make sure we won't run this function twice.
d83721
+   */
d83721
   s_uwtmp_inserted = 0;
d83721
   s_utent.ut_tv.tv_sec = vsf_sysutil_get_time_sec();
d83721
   updwtmpx(WTMPX_FILE, &s_utent);
d83721
-- 
d83721
2.20.1
d83721