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

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