Whamcloud - gitweb
LU-3683 libcfs: improve validity test for valid file descriptors
[fs/lustre-release.git] / libcfs / libcfs / kernel_user_comm.c
index 4cac2e5..e819be0 100644 (file)
  */
 int libcfs_ukuc_start(lustre_kernelcomm *link, int group)
 {
-        int pfd[2];
+       int pfd[2];
 
-        if (pipe(pfd) < 0)
-                return -errno;
+       link->lk_rfd = link->lk_wfd = LK_NOFD;
 
-        memset(link, 0, sizeof(*link));
-        link->lk_rfd = pfd[0];
-        link->lk_wfd = pfd[1];
-        link->lk_group = group;
-        link->lk_uid = getpid();
-        return 0;
+       if (pipe(pfd) < 0)
+               return -errno;
+
+       memset(link, 0, sizeof(*link));
+       link->lk_rfd = pfd[0];
+       link->lk_wfd = pfd[1];
+       link->lk_group = group;
+       link->lk_uid = getpid();
+       return 0;
 }
 
 int libcfs_ukuc_stop(lustre_kernelcomm *link)
 {
-        if (link->lk_wfd > 0)
-                close(link->lk_wfd);
-        return close(link->lk_rfd);
+       int rc;
+
+       if (link->lk_wfd != LK_NOFD)
+               close(link->lk_wfd);
+        rc = close(link->lk_rfd);
+       link->lk_rfd = link->lk_wfd = LK_NOFD;
+       return rc;
 }
 
 #define lhsz sizeof(*kuch)