]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - utils/showmount/showmount.c
showmount: destroy RPC client when finished
[nfs-utils.git] / utils / showmount / showmount.c
index 213a573613c3215314e71543e9d762ad012f8f30..959229a8c90bd59a3a61ee3bac6ce3ca0e38078a 100644 (file)
@@ -83,7 +83,8 @@ static void usage(FILE *fp, int n)
  *  tout contains the timeout.  It will be modified to contain the time
  *  remaining (i.e. time provided - time elasped).
  *
- *  Returns 0 for success 
+ *  Returns zero on success; otherwise, -1 is returned and errno is set
+ *  to reflect the nature of the error.
  */
 static int connect_nb(int fd, struct sockaddr_in *addr, struct timeval *tout)
 {
@@ -107,7 +108,7 @@ static int connect_nb(int fd, struct sockaddr_in *addr, struct timeval *tout)
        len = sizeof(struct sockaddr);
        ret = connect(fd, (struct sockaddr *)addr, len);
        if (ret < 0 && errno != EINPROGRESS) {
-               ret = -errno;
+               ret = -1;
                goto done;
        }
 
@@ -121,9 +122,8 @@ static int connect_nb(int fd, struct sockaddr_in *addr, struct timeval *tout)
        ret = select(fd + 1, NULL, &rset, NULL, tout);
        if (ret <= 0) {
                if (ret == 0)
-                       ret = -ETIMEDOUT;
-               else
-                       ret = -errno;
+                       errno = ETIMEDOUT;
+               ret = -1;
                goto done;
        }
 
@@ -133,13 +133,15 @@ static int connect_nb(int fd, struct sockaddr_in *addr, struct timeval *tout)
                len = sizeof(ret);
                status = getsockopt(fd, SOL_SOCKET, SO_ERROR, &ret, &len);
                if (status < 0) {
-                       ret = -errno;
+                       ret = -1;
                        goto done;
                }
 
                /* Oops - something wrong with connect */
-               if (ret)
-                       ret = -ret;
+               if (ret != 0) {
+                       errno = ret;
+                       ret = -1;
+               }
        }
 
 done:
@@ -179,10 +181,10 @@ static unsigned short getport(struct sockaddr_in *addr,
                tout.tv_sec = TIMEOUT_TCP;
 
                ret = connect_nb(sock, &saddr, &tout);
-               if (ret < 0) {
-                       close(sock);
+               if (ret != 0) {
                        rpc_createerr.cf_stat = RPC_SYSTEMERROR;
                        rpc_createerr.cf_error.re_errno = errno;
+                       close(sock);
                        return 0;
                }
                client = clnttcp_create(&saddr,
@@ -393,6 +395,7 @@ int main(int argc, char **argv)
                        total_timeout);
                if (clnt_stat != RPC_SUCCESS) {
                        clnt_perror(mclient, "rpc mount export");
+                       clnt_destroy(mclient);
                        exit(1);
                }
                if (headers)
@@ -416,6 +419,7 @@ int main(int argc, char **argv)
                        printf("\n");
                        exportlist = exportlist->ex_next;
                }
+               clnt_destroy(mclient);
                exit(0);
        }
 
@@ -426,8 +430,10 @@ int main(int argc, char **argv)
                total_timeout);
        if (clnt_stat != RPC_SUCCESS) {
                clnt_perror(mclient, "rpc mount dump");
+               clnt_destroy(mclient);
                exit(1);
        }
+       clnt_destroy(mclient);
 
        n = 0;
        for (list = dumplist; list; list = list->ml_next)