Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/rpcinfo - WARNS ?= 4



details:   https://anonhg.NetBSD.org/src/rev/4424b936fd6d
branches:  trunk
changeset: 761836:4424b936fd6d
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Feb 08 22:16:58 2011 +0000

description:
- WARNS ?= 4
- fix memory leaks
- fix error printing
- pass lint
- KNF
- constify
- ansify

diffstat:

 usr.bin/rpcinfo/Makefile  |    4 +-
 usr.bin/rpcinfo/rpcinfo.c |  925 ++++++++++++++++++++++-----------------------
 2 files changed, 445 insertions(+), 484 deletions(-)

diffs (truncated from 1772 to 300 lines):

diff -r 264fb8500aaa -r 4424b936fd6d usr.bin/rpcinfo/Makefile
--- a/usr.bin/rpcinfo/Makefile  Tue Feb 08 21:59:50 2011 +0000
+++ b/usr.bin/rpcinfo/Makefile  Tue Feb 08 22:16:58 2011 +0000
@@ -1,7 +1,7 @@
-#      $NetBSD: Makefile,v 1.13 2009/04/14 22:15:25 lukem Exp $
+#      $NetBSD: Makefile,v 1.14 2011/02/08 22:16:58 christos Exp $
 #      from: @(#)Makefile      5.2 (Berkeley) 5/11/90
 
-WARNS?=        2       # XXX -Wcast-qual issues
+WARNS ?= 4
 
 .include <bsd.own.mk>
 
diff -r 264fb8500aaa -r 4424b936fd6d usr.bin/rpcinfo/rpcinfo.c
--- a/usr.bin/rpcinfo/rpcinfo.c Tue Feb 08 21:59:50 2011 +0000
+++ b/usr.bin/rpcinfo/rpcinfo.c Tue Feb 08 22:16:58 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rpcinfo.c,v 1.29 2009/11/17 18:31:13 drochner Exp $    */
+/*     $NetBSD: rpcinfo.c,v 1.30 2011/02/08 22:16:58 christos Exp $    */
 
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
@@ -73,6 +73,7 @@
 #include <unistd.h>
 #include <err.h>
 #include <ctype.h>
+#include <errno.h>
 
 #ifdef PORTMAP         /* Support for version 2 portmapper */
 #include <netinet/in.h>
@@ -82,9 +83,14 @@
 #include <rpc/pmap_clnt.h>
 #endif
 
-#define        MIN_VERS        ((u_long)0)
-#define        MAX_VERS        ((u_long)4294967295UL)
-#define        UNKNOWN         "unknown"
+#define        MIN_VERS        ((rpcvers_t)0)
+#define        MAX_VERS        ((rpcvers_t)4294967295UL)
+#define PMAP_PROG      ((rpcprog_t)PMAPPROG)
+#define PMAP_VERS      ((rpcvers_t)PMAPVERS)
+#define RPCB_VERS      ((rpcvers_t)RPCBVERS)
+#define RPCB_VERS4     ((rpcvers_t)RPCB_VERS)
+#define UL(a)          ((unsigned long)a)
+static char unknown[] = "unknown";
 
 /*
  * Functions to be performed.
@@ -113,7 +119,7 @@
 };
 
 struct rpcbdump_short {
-       u_long prog;
+       rpcprog_t prog;
        struct verslist *vlist;
        struct netidlist *nlist;
        struct rpcbdump_short *next;
@@ -124,41 +130,40 @@
 
 #ifdef PORTMAP
 static void    ip_ping(u_short, const char *, int, char **);
-static CLIENT  *clnt_com_create(struct sockaddr_in *, u_long, u_long, int *,
-                                const char *);
+static CLIENT  *clnt_com_create(struct sockaddr_in *, rpcprog_t, rpcvers_t,
+    int *, const char *);
 static void    pmapdump(int, char **);
 static void    get_inet_address(struct sockaddr_in *, const char *);
 #endif
 
 static bool_t  reply_proc(void *, struct netbuf *, struct netconfig *);
 static void    brdcst(int, char **);
-static void    addrping(char *, char *, int, char **);
-static void    progping(char *, int, char **);
-static CLIENT  *clnt_addr_create(char *, struct netconfig *, u_long, u_long);
-static CLIENT   *clnt_rpcbind_create(char *, int, struct netbuf **);
-static CLIENT   *getclnthandle(char *, struct netconfig *, u_long,
-                              struct netbuf **);
-static CLIENT  *local_rpcb(u_long, u_long);
-static int     pstatus(CLIENT *, u_long, u_long);
-static void    rpcbdump(int, char *, int, char **);
+static void    addrping(const char *, const char *, int, char **);
+static void    progping(const char *, int, char **);
+static CLIENT  *clnt_addr_create(const char *, const struct netconfig *,
+    rpcprog_t, rpcvers_t);
+static CLIENT   *clnt_rpcbind_create(const char *, rpcvers_t, struct netbuf **);
+static CLIENT   *getclnthandle(const char *, const struct netconfig *,
+    rpcvers_t, struct netbuf **);
+static CLIENT  *local_rpcb(rpcprog_t, rpcvers_t);
+static int     pstatus(CLIENT *, rpcprog_t, rpcvers_t);
+static void    rpcbdump(int, const char *, int, char **);
 static void    rpcbgetstat(int, char **);
-static void    rpcbaddrlist(char *, int, char **);
-static void    deletereg(char *, int, char **);
-static void    print_rmtcallstat(int, rpcb_stat *);
-static void    print_getaddrstat(int, rpcb_stat *);
-static void    usage(void);
-static u_long  getprognum(char *);
-static u_long  getvers(char *);
-static char    *spaces(int);
-static bool_t  add_version(struct rpcbdump_short *, u_long);
+static void    rpcbaddrlist(const char *, int, char **);
+static void    deletereg(const char *, int, char **);
+static void    print_rmtcallstat(int, const rpcb_stat *);
+static void    print_getaddrstat(int, const rpcb_stat *);
+static void    usage(void)__attribute__((__noreturn__));
+static rpcprog_t       getprognum(const char *);
+static rpcvers_t       getvers(const char *);
+static const char *spaces(size_t);
+static bool_t  add_version(struct rpcbdump_short *, rpcvers_t);
 static bool_t  add_netid(struct rpcbdump_short *, char *);
 
-int            main(int argc, char **argv);
-
 int
 main(int argc, char **argv)
 {
-       register int c;
+       int c;
        int errflg;
        int function;
        char *netid = NULL;
@@ -255,10 +260,8 @@
                }
        }
 
-       if (errflg || ((function == ADDRPING) && !netid)) {
+       if (errflg || ((function == ADDRPING) && !netid))
                usage();
-               return (1);
-       }
 
        if (function == NONE) {
                if (argc - optind > 1)
@@ -270,10 +273,8 @@
        switch (function) {
 #ifdef PORTMAP
        case PMAPDUMP:
-               if (portnum != 0) {
+               if (portnum != 0)
                        usage();
-                       return (1);
-               }
                pmapdump(argc - optind, argv + optind);
                break;
 
@@ -312,19 +313,19 @@
 }
 
 static CLIENT *
-local_rpcb(u_long prog, u_long vers)
+local_rpcb(rpcprog_t prog, rpcvers_t vers)
 {
        struct netbuf nbuf;
        struct sockaddr_un sun;
        int sock;
 
-       memset(&sun, 0, sizeof sun);
+       (void)memset(&sun, 0, sizeof sun);
        sock = socket(AF_LOCAL, SOCK_STREAM, 0);
        if (sock < 0)
                return NULL;
 
        sun.sun_family = AF_LOCAL;
-       strcpy(sun.sun_path, _PATH_RPCBINDSOCK);
+       (void)strlcpy(sun.sun_path, _PATH_RPCBINDSOCK, sizeof(sun.sun_path));
        nbuf.len = sun.sun_len = SUN_LEN(&sun);
        nbuf.maxlen = sizeof (struct sockaddr_un);
        nbuf.buf = &sun;
@@ -334,30 +335,30 @@
 
 #ifdef PORTMAP
 static CLIENT *
-clnt_com_create(struct sockaddr_in *addr, u_long prog, u_long vers,
-               int *fdp, const char *trans)
+clnt_com_create(struct sockaddr_in *addr, rpcprog_t prog, rpcvers_t vers,
+    int *fdp, const char *trans)
 {
        CLIENT *clnt;
 
        if (strcmp(trans, "tcp") == 0) {
-               clnt = clnttcp_create(addr, prog, vers, fdp, 0, 0);
+               clnt = clnttcp_create(addr, UL(prog), UL(vers), fdp, 0, 0);
        } else {
                struct timeval to;
 
                to.tv_sec = 5;
                to.tv_usec = 0;
-               clnt = clntudp_create(addr, prog, vers, to, fdp);
+               clnt = clntudp_create(addr, UL(prog), UL(vers), to, fdp);
        }
        if (clnt == NULL) {
-               clnt_pcreateerror(getprogname());
+               char *m = clnt_spcreateerror("") + 2;
                if (vers == MIN_VERS)
-                       printf("program %lu is not available\n", prog);
+                       errx(1, "Program %lu is not available (%s)",
+                           (unsigned long)prog, m);
                else
-                       printf("program %lu version %lu is not available\n",
-                                                       prog, vers);
-               exit(1);
+                       errx(1, "Program %lu version %lu is not available (%s)",
+                           (unsigned long)prog, (unsigned long)vers, m);
        }
-       return (clnt);
+       return clnt;
 }
 
 /*
@@ -375,14 +376,12 @@
        struct timeval to;
        struct sockaddr_in addr;
        enum clnt_stat rpc_stat;
-       u_long prognum, vers, minvers, maxvers;
+       rpcprog_t prognum, vers, minvers, maxvers;
        struct rpc_err rpcerr;
        int failure = 0;
 
-       if (argc < 2 || argc > 3) {
+       if (argc < 2 || argc > 3)
                usage();
-               exit(1);
-       }
        to.tv_sec = 10;
        to.tv_usec = 0;
        prognum = getprognum(argv[1]);
@@ -398,17 +397,17 @@
        }
        addr.sin_port = htons(portnum);
        client = clnt_com_create(&addr, prognum, vers, &fd, trans);
-       rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t) xdr_void,
-           NULL, (xdrproc_t) xdr_void, NULL, to);
+       rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t)xdr_void,
+           NULL, (xdrproc_t)xdr_void, NULL, to);
        if (argc != 2) {
                /* Version number was known */
                if (pstatus(client, prognum, vers) < 0)
                        exit(1);
-               (void) CLNT_DESTROY(client);
+               (void)CLNT_DESTROY(client);
                return;
        }
        /* Version number not known */
-       (void) CLNT_CONTROL(client, CLSET_FD_NCLOSE, NULL);
+       (void)CLNT_CONTROL(client, CLSET_FD_NCLOSE, NULL);
        if (rpc_stat == RPC_PROGVERSMISMATCH) {
                clnt_geterr(client, &rpcerr);
                minvers = rpcerr.re_vers.low;
@@ -418,11 +417,12 @@
                 * Oh dear, it DOES support version 0.
                 * Let's try version MAX_VERS.
                 */
-               (void) CLNT_DESTROY(client);
+               (void)CLNT_DESTROY(client);
                addr.sin_port = htons(portnum);
-               client = clnt_com_create(&addr, prognum, MAX_VERS, &fd, trans);
-               rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t) xdr_void,
-                   NULL, (xdrproc_t) xdr_void, NULL, to);
+               client = clnt_com_create(&addr, (unsigned int)prognum,
+                   MAX_VERS, &fd, trans);
+               rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t)xdr_void,
+                   NULL, (xdrproc_t)xdr_void, NULL, to);
                if (rpc_stat == RPC_PROGVERSMISMATCH) {
                        clnt_geterr(client, &rpcerr);
                        minvers = rpcerr.re_vers.low;
@@ -437,26 +437,26 @@
                        minvers = 0;
                        maxvers = MAX_VERS;
                } else {
-                       (void) pstatus(client, prognum, MAX_VERS);
+                       (void)pstatus(client, prognum, MAX_VERS);
                        exit(1);
                }
        } else {
-               (void) pstatus(client, prognum, (u_long)0);
+               (void)pstatus(client, prognum, MIN_VERS);
                exit(1);
        }
-       (void) CLNT_DESTROY(client);
+       (void)CLNT_DESTROY(client);
        for (vers = minvers; vers <= maxvers; vers++) {
                addr.sin_port = htons(portnum);
                client = clnt_com_create(&addr, prognum, vers, &fd, trans);
-               rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t) xdr_void,
-                   NULL, (xdrproc_t) xdr_void, NULL, to);
+               rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t)xdr_void,
+                   NULL, (xdrproc_t)xdr_void, NULL, to);
                if (pstatus(client, prognum, vers) < 0)
-                               failure = 1;
-               (void) CLNT_DESTROY(client);
+                   failure = 1;
+               (void)CLNT_DESTROY(client);
        }
        if (failure)
                exit(1);
-       (void) close(fd);
+       (void)close(fd);
        return;
 }
 



Home | Main Index | Thread Index | Old Index