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

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