Blame SOURCES/0001-Repeat-pututxline-until-it-succeeds-if-it-fails-with.patch

90e381
From 7957425ef5ab365fc96ea0615f99705581c6dbd8 Mon Sep 17 00:00:00 2001
90e381
From: =?UTF-8?q?Ond=C5=99ej=20Lyson=C4=9Bk?= <olysonek@redhat.com>
90e381
Date: Mon, 12 Aug 2019 18:15:36 +0200
90e381
Subject: [PATCH] Repeat pututxline() until it succeeds if it fails with EINTR
90e381
90e381
Since the pututxline() bug rhbz#1749439 is now fixed in glibc in
90e381
Fedora and RHEL-8, we can implement a complete solution for the stale
90e381
utmp entries issue originally reported as rhbz#1688848.
90e381
90e381
This patch is a followup to commit 896b3694ca062d7.
90e381
90e381
Resolves: rhbz#1688852
90e381
Resolves: rhbz#1737433
90e381
---
90e381
 sysdeputil.c | 53 +++++++++++++---------------------------------------
90e381
 1 file changed, 13 insertions(+), 40 deletions(-)
90e381
90e381
diff --git a/sysdeputil.c b/sysdeputil.c
90e381
index 4fbcca7..75be680 100644
90e381
--- a/sysdeputil.c
90e381
+++ b/sysdeputil.c
90e381
@@ -1203,7 +1203,7 @@ void
90e381
 vsf_insert_uwtmp(const struct mystr* p_user_str,
90e381
                  const struct mystr* p_host_str)
90e381
 {
90e381
-  int attempts;
90e381
+  struct utmpx* p_res;
90e381
 
90e381
   if (sizeof(s_utent.ut_line) < 16)
90e381
   {
90e381
@@ -1233,34 +1233,21 @@ vsf_insert_uwtmp(const struct mystr* p_user_str,
90e381
   vsf_sysutil_strcpy(s_utent.ut_host, str_getbuf(p_host_str),
90e381
                      sizeof(s_utent.ut_host));
90e381
   s_utent.ut_tv.tv_sec = vsf_sysutil_get_time_sec();
90e381
-  for (attempts = 2; attempts > 0; --attempts)
90e381
+  setutxent();
90e381
+  do
90e381
   {
90e381
-    struct utmpx* p_res;
90e381
-    setutxent();
90e381
     p_res = pututxline(&s_utent);
90e381
     /* For now we'll ignore errors other than EINTR and EAGAIN */
90e381
-    if (p_res != NULL || (errno != EINTR && errno != EAGAIN))
90e381
-    {
90e381
-      break;
90e381
-    }
90e381
-  }
90e381
-  if (attempts == 0)
90e381
-  {
90e381
-    /* This makes us skip pututxline() in vsf_remove_uwtmp() */
90e381
-    s_uwtmp_inserted = -1;
90e381
-  }
90e381
-  else
90e381
-  {
90e381
-    s_uwtmp_inserted = 1;
90e381
-    endutxent();
90e381
-  }
90e381
+  } while (p_res == NULL && (errno == EINTR || errno == EAGAIN));
90e381
+  s_uwtmp_inserted = 1;
90e381
+  endutxent();
90e381
   updwtmpx(WTMPX_FILE, &s_utent);
90e381
 }
90e381
 
90e381
 void
90e381
 vsf_remove_uwtmp(void)
90e381
 {
90e381
-  int attempts;
90e381
+  struct utmpx* p_res;
90e381
 
90e381
   if (!s_uwtmp_inserted)
90e381
   {
90e381
@@ -1270,27 +1257,13 @@ vsf_remove_uwtmp(void)
90e381
   vsf_sysutil_memclr(s_utent.ut_user, sizeof(s_utent.ut_user));
90e381
   vsf_sysutil_memclr(s_utent.ut_host, sizeof(s_utent.ut_host));
90e381
   s_utent.ut_tv.tv_sec = 0;
90e381
-  if (s_uwtmp_inserted == 1)
90e381
+  setutxent();
90e381
+  do
90e381
   {
90e381
-    for (attempts = 2; attempts > 0; --attempts)
90e381
-    {
90e381
-      struct utmpx* p_res;
90e381
-      setutxent();
90e381
-      p_res = pututxline(&s_utent);
90e381
-      /* For now we'll ignore errors other than EINTR and EAGAIN */
90e381
-      if (p_res != NULL || (errno != EINTR && errno != EAGAIN))
90e381
-      {
90e381
-        break;
90e381
-      }
90e381
-    }
90e381
-    if (attempts != 0)
90e381
-    {
90e381
-      endutxent();
90e381
-    }
90e381
-  }
90e381
-  /* Set s_uwtmp_inserted to 0 regardless of the result of
90e381
-   * pututxline() to make sure we won't run this function twice.
90e381
-   */
90e381
+    p_res = pututxline(&s_utent);
90e381
+    /* For now we'll ignore errors other than EINTR and EAGAIN */
90e381
+  } while (p_res == NULL && (errno == EINTR || errno == EAGAIN));
90e381
+  endutxent();
90e381
   s_uwtmp_inserted = 0;
90e381
   s_utent.ut_tv.tv_sec = vsf_sysutil_get_time_sec();
90e381
   updwtmpx(WTMPX_FILE, &s_utent);
90e381
-- 
90e381
2.20.1
90e381