]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - utils/showmount/showmount.c
Merge branch 'upstream'
[nfs-utils.git] / utils / showmount / showmount.c
index 9979621e3c3a26d4cbcd2e994cfb3c71b0a8ece2..213a573613c3215314e71543e9d762ad012f8f30 100644 (file)
@@ -62,16 +62,14 @@ static struct option longopts[] =
 
 #define MAXHOSTLEN 256
 
-int dump_cmp(p, q)
-char **p;
-char **q;
+static int dump_cmp(const void *pv, const void *qv)
 {
+       const char **p = (const char **)pv;
+       const char **q = (const char **)qv;
        return strcmp(*p, *q);
 }
 
-static void usage(fp, n)
-FILE *fp;
-int n;
+static void usage(FILE *fp, int n)
 {
        fprintf(fp, "Usage: %s [-adehv]\n", program_name);
        fprintf(fp, "       [--all] [--directories] [--exports]\n");
@@ -84,6 +82,8 @@ 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 
  */
 static int connect_nb(int fd, struct sockaddr_in *addr, struct timeval *tout)
 {
@@ -118,7 +118,7 @@ static int connect_nb(int fd, struct sockaddr_in *addr, struct timeval *tout)
        FD_ZERO(&rset);
        FD_SET(fd, &rset);
 
-       ret = select(fd + 1, &rset, NULL, NULL, tout);
+       ret = select(fd + 1, NULL, &rset, NULL, tout);
        if (ret <= 0) {
                if (ret == 0)
                        ret = -ETIMEDOUT;
@@ -179,12 +179,15 @@ static unsigned short getport(struct sockaddr_in *addr,
                tout.tv_sec = TIMEOUT_TCP;
 
                ret = connect_nb(sock, &saddr, &tout);
-               if (ret == -1) {
+               if (ret < 0) {
                        close(sock);
                        rpc_createerr.cf_stat = RPC_SYSTEMERROR;
                        rpc_createerr.cf_error.re_errno = errno;
                        return 0;
                }
+               client = clnttcp_create(&saddr,
+                                       PMAPPROG, PMAPVERS, &sock,
+                                       0, 0);
        } else {
                /*
                 * bind to any unused port.  If we left this up to the rpc
@@ -213,10 +216,10 @@ static unsigned short getport(struct sockaddr_in *addr,
                        sock = RPC_ANYSOCK;
                        /* FALLTHROUGH */
                }
+               client = clntudp_bufcreate(&saddr, PMAPPROG, PMAPVERS,
+                                          tout, &sock, send_sz, recv_sz);
        }
 
-       client = clntudp_bufcreate(&saddr, PMAPPROG, PMAPVERS,
-                                  tout, &sock, send_sz, recv_sz);
        if (!client) {
                close(sock);
                rpc_createerr.cf_stat = RPC_RPCBFAILURE;
@@ -239,6 +242,8 @@ static unsigned short getport(struct sockaddr_in *addr,
                rpc_createerr.cf_stat = status;
                clnt_destroy(client);
                return 0;
+       } else if (port == 0) {
+               rpc_createerr.cf_stat = RPC_PROGNOTREGISTERED;
        }
 
        clnt_destroy(client);
@@ -246,9 +251,7 @@ static unsigned short getport(struct sockaddr_in *addr,
        return htons(port);
 }
 
-int main(argc, argv)
-int argc;
-char **argv;
+int main(int argc, char **argv)
 {
        char hostname_buf[MAXHOSTLEN];
        char *hostname;
@@ -351,7 +354,7 @@ char **argv;
                                         MOUNTPROG, MOUNTVERS, IPPROTO_TCP);
                if (server_addr.sin_port) {
                        ret = connect_nb(msock, &server_addr, 0);
-                       if (ret != -1)
+                       if (ret == 0) /* success */
                                mclient = clnttcp_create(&server_addr,
                                                MOUNTPROG, MOUNTVERS, &msock,
                                                0, 0);
@@ -365,7 +368,7 @@ char **argv;
                server_addr.sin_port = getport(&server_addr,
                                         MOUNTPROG, MOUNTVERS, IPPROTO_UDP);
                if (!server_addr.sin_port) {
-                       clnt_pcreateerror("portmap getport");
+                       clnt_pcreateerror("showmount");
                        exit(1);
                }
                msock = RPC_ANYSOCK;