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

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