From 5c363bfbfb6aee507e4d966df4f45b39e5f00b91 Mon Sep 17 00:00:00 2001
From: answer9030 <jiangjixiang@kylinos.cn>
Date: Thu, 16 Mar 2023 14:49:51 +0800
Subject: [PATCH] Fixed the problem of calling getpid() and lstat() twice in
 sss_cli_check_socket()

the second call to getpid() and lstat() is redundant.

Reviewed-by: Alexey Tikhonov <atikhono@redhat.com>
Reviewed-by: Sumit Bose <sbose@redhat.com>

Reference:https://github.com/SSSD/sssd/commit/5c363bfbfb6aee507e4d966df4f45b39e5f00b91
Conflict:NA

---
 src/sss_client/common.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/src/sss_client/common.c b/src/sss_client/common.c
index 39b107527..53ff6e8e9 100644
--- a/src/sss_client/common.c
+++ b/src/sss_client/common.c
@@ -683,15 +683,16 @@ static enum sss_status sss_cli_check_socket(int *errnop,
                                             const char *socket_name,
                                             int timeout)
 {
-    static pid_t mypid;
-    static struct stat selfsb;
+    static pid_t mypid_s;
+    static ino_t myself_ino;
     struct stat mypid_sb, myself_sb;
+    pid_t mypid_d;
     int mysd;
     int ret;
 
     ret = lstat("/proc/self/", &myself_sb);
-
-    if (getpid() != mypid || (ret == 0 && myself_sb.st_ino != selfsb.st_ino)) {
+    mypid_d = getpid();
+    if (mypid_d != mypid_s || (ret == 0 && myself_sb.st_ino != myself_ino)) {
         ret = fstat(sss_cli_sd, &mypid_sb);
         if (ret == 0) {
             if (S_ISSOCK(mypid_sb.st_mode) &&
@@ -701,11 +702,8 @@ static enum sss_status sss_cli_check_socket(int *errnop,
             }
         }
         sss_cli_sd = -1;
-        mypid = getpid();
-        ret = lstat("/proc/self/", &selfsb);
-        if (ret) {
-            memset(&selfsb, 0, sizeof(selfsb));
-        }
+        mypid_s = mypid_d;
+        myself_ino = myself_sb.st_ino;
     }
 
     /* check if the socket has been closed on the other side */
-- 
2.33.0

