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

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