Source-Changes-HG archive

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

[src/trunk]: src/tests/fs/nfs/nfsservice don't abuse %m in printf



details:   https://anonhg.NetBSD.org/src/rev/c1e09efbabf8
branches:  trunk
changeset: 340077:c1e09efbabf8
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Aug 21 14:19:10 2015 +0000

description:
don't abuse %m in printf
fix error messages

diffstat:

 tests/fs/nfs/nfsservice/mountd.c          |  35 ++++++-----
 tests/fs/nfs/nfsservice/nfsd.c            |  91 +++++++++++++++++-------------
 tests/fs/nfs/nfsservice/rpcbind/rpcbind.c |  10 ++-
 3 files changed, 75 insertions(+), 61 deletions(-)

diffs (truncated from 354 to 300 lines):

diff -r 797655e61160 -r c1e09efbabf8 tests/fs/nfs/nfsservice/mountd.c
--- a/tests/fs/nfs/nfsservice/mountd.c  Fri Aug 21 13:24:47 2015 +0000
+++ b/tests/fs/nfs/nfsservice/mountd.c  Fri Aug 21 14:19:10 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mountd.c,v 1.8 2013/10/19 17:45:00 christos Exp $       */
+/*     $NetBSD: mountd.c,v 1.9 2015/08/21 14:19:10 christos Exp $       */
 
 /*
  * Copyright (c) 1989, 1993
@@ -42,7 +42,7 @@
 #if 0
 static char     sccsid[] = "@(#)mountd.c  8.15 (Berkeley) 5/1/95";
 #else
-__RCSID("$NetBSD: mountd.c,v 1.8 2013/10/19 17:45:00 christos Exp $");
+__RCSID("$NetBSD: mountd.c,v 1.9 2015/08/21 14:19:10 christos Exp $");
 #endif
 #endif                         /* not lint */
 
@@ -904,14 +904,12 @@
        struct exportlist **ep;
        struct statvfs *fsp;
 {
-       int error = 0;
-
        if (!check_dirpath(line, lineno, cp))
                return 0;
 
        if (rump_sys_statvfs1(cp, fsp, ST_WAIT) == -1) {
-               syslog(LOG_ERR, "\"%s\", line %ld: statvfs for `%s' failed: %m %d",
-                   line, (unsigned long)lineno, cp, error);
+               syslog(LOG_ERR, "\"%s\", line %ld: statvfs for `%s' failed (%s)",
+                   line, (unsigned long)lineno, cp, strerror(errno));
                return 0;
        }
 
@@ -1011,8 +1009,8 @@
                mel.mel_nexports = 0;
                if (rump_sys_nfssvc(NFSSVC_SETEXPORTSLIST, &mel) == -1 &&
                    errno != EOPNOTSUPP)
-                       syslog(LOG_ERR, "Can't delete exports for %s (%m)",
-                           fsp->f_mntonname);
+                       syslog(LOG_ERR, "Can't delete exports for %s (%s)",
+                           fsp->f_mntonname, strerror(errno));
 
                fsp++;
        }
@@ -1997,13 +1995,13 @@
 
                if (rump_sys_nfssvc(NFSSVC_SETEXPORTSLIST, &mel) != 0) {
                        syslog(LOG_ERR,
-           "\"%s\", line %ld: Can't change attributes for %s to %s: %m %d",
+           "\"%s\", line %ld: Can't change attributes for %s to %s (%s)",
                            line, (unsigned long)lineno,
                            dirp, (grp->gr_type == GT_HOST) ?
                            grp->gr_ptr.gt_addrinfo->ai_canonname :
                            (grp->gr_type == GT_NET) ?
                            grp->gr_ptr.gt_net.nt_name :
-                           "Unknown", errno);
+                           "Unknown", strerror(errno));
                        return (1);
                }
 skip:
@@ -2258,7 +2256,8 @@
        FILE *mlfile;
 
        if ((mlfile = rumpfopen(_PATH_RMOUNTLIST, "r")) == NULL) {
-               syslog(LOG_ERR, "Can't open %s: %m", _PATH_RMOUNTLIST);
+               syslog(LOG_ERR, "Can't open %s (%s)", _PATH_RMOUNTLIST,
+                   strerror(errno));
                return;
        }
        mlpp = &mlhead;
@@ -2330,8 +2329,8 @@
        }
        if (fnd) {
                if ((mlfile = rumpfopen(_PATH_RMOUNTLIST, "w")) == NULL) {
-                       syslog(LOG_ERR, "Can't update %s: %m",
-                           _PATH_RMOUNTLIST);
+                       syslog(LOG_ERR, "Can't update %s (%s)",
+                           _PATH_RMOUNTLIST, strerror(errno));
                        return ret;
                }
                mlp = mlhead;
@@ -2370,7 +2369,8 @@
        mlp->ml_next = NULL;
        *mlpp = mlp;
        if ((mlfile = rumpfopen(_PATH_RMOUNTLIST, "a")) == NULL) {
-               syslog(LOG_ERR, "Can't update %s: %m", _PATH_RMOUNTLIST);
+               syslog(LOG_ERR, "Can't update %s (%s)", _PATH_RMOUNTLIST,
+                   strerror(errno));
                return;
        }
        (void)fprintf(mlfile, "%s %s\n", mlp->ml_host, mlp->ml_dirp);
@@ -2520,8 +2520,8 @@
 
 bad:
        syslog(LOG_ERR,
-           "\"%s\", line %ld: lstat for `%s' failed: %m",
-           line, (unsigned long)lineno, dirp);
+           "\"%s\", line %ld: lstat for `%s' failed (%s)",
+           line, (unsigned long)lineno, dirp, strerror(errno));
        if (cp)
                *cp = '/';
        return 0;
@@ -2563,7 +2563,8 @@
                return;
        }
        if (bindresvport_sa(sock, sa) == -1)
-               syslog(LOG_ERR, "Cannot bind to reserved port %d (%m)", port);
+               syslog(LOG_ERR, "Cannot bind to reserved port %d (%s)", port,
+                   strerror(errno));
 }
 
 /* ARGSUSED */
diff -r 797655e61160 -r c1e09efbabf8 tests/fs/nfs/nfsservice/nfsd.c
--- a/tests/fs/nfs/nfsservice/nfsd.c    Fri Aug 21 13:24:47 2015 +0000
+++ b/tests/fs/nfs/nfsservice/nfsd.c    Fri Aug 21 14:19:10 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nfsd.c,v 1.4 2013/10/19 17:45:00 christos Exp $        */
+/*     $NetBSD: nfsd.c,v 1.5 2015/08/21 14:19:10 christos Exp $        */
 
 /*
  * Copyright (c) 1989, 1993, 1994
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)nfsd.c     8.9 (Berkeley) 3/29/95";
 #else
-__RCSID("$NetBSD: nfsd.c,v 1.4 2013/10/19 17:45:00 christos Exp $");
+__RCSID("$NetBSD: nfsd.c,v 1.5 2015/08/21 14:19:10 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -94,9 +94,8 @@
 int    debug = 0;
 #endif
 
-int    main __P((int, char **));
-void   nonfs __P((int));
-void   usage __P((void));
+void   nonfs(int);
+void   usage(void);
 
 static void *
 child(void *arg)
@@ -108,7 +107,7 @@
        memset(&nsd, 0, sizeof(nsd));
        while (rump_sys_nfssvc(nfssvc_flag, &nsd) < 0) {
                if (errno != ENEEDAUTH) {
-                       syslog(LOG_ERR, "nfssvc: %m %d", errno);
+                       syslog(LOG_ERR, "nfssvc (%s)", strerror(errno));
                        exit(1);
                }
                nfssvc_flag = NFSSVC_NFSD | NFSSVC_AUTHINFAIL;
@@ -153,7 +152,6 @@
        int nfsdcnt, on = 1, reregister, sock, tcpflag, tcpsock;
        int tcp6sock, ip6flag;
        int tp4cnt, tp4flag, tpipcnt, udpflag, ecode, s;
-       int error = 0;
 
 #define        DEFNFSDCNT       4
        nfsdcnt = DEFNFSDCNT;
@@ -377,11 +375,12 @@
                if (rump_sys_setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY,
                    &on, sizeof on) < 0) {
                        syslog(LOG_ERR, "can't set v6-only binding for udp6 "
-                                       "socket: %m");
+                           "socket (%s)", strerror(errno));
                        exit(1);
                }
                if (rump_sys_bind(sock, ai_udp6->ai_addr, ai_udp6->ai_addrlen) < 0) {
-                       syslog(LOG_ERR, "can't bind udp addr");
+                       syslog(LOG_ERR, "can't bind udp addr (%s)",
+                           strerror(errno));
                        exit(1);
                }
                if (!rpcb_set(RPCPROG_NFS, 2, nconf_udp6, &nb_udp6) ||
@@ -393,7 +392,8 @@
                nfsdargs.name = NULL;
                nfsdargs.namelen = 0;
                if (rump_sys_nfssvc(NFSSVC_ADDSOCK, &nfsdargs) < 0) {
-                       syslog(LOG_ERR, "can't add UDP6 socket");
+                       syslog(LOG_ERR, "can't add UDP6 socket (%s)",
+                           strerror(errno));
                        exit(1);
                }
                (void)rump_sys_close(sock);
@@ -410,7 +410,8 @@
                }
                if (setsockopt(tcpsock,
                    SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0)
-                       syslog(LOG_ERR, "setsockopt SO_REUSEADDR: %m");
+                       syslog(LOG_ERR, "setsockopt SO_REUSEADDR (%s)",
+                           strerror(errno));
                if (bind(tcpsock, ai_tcp->ai_addr, ai_tcp->ai_addrlen) < 0) {
                        syslog(LOG_ERR, "can't bind tcp addr");
                        exit(1);
@@ -433,24 +434,27 @@
        if (tcpflag && ip6flag) {
                if ((tcp6sock = socket(ai_tcp6->ai_family, ai_tcp6->ai_socktype,
                    ai_tcp6->ai_protocol)) < 0) {
-                       syslog(LOG_ERR, "can't create tcp socket");
+                       syslog(LOG_ERR, "can't create tcp socket (%s)",
+                           strerror(errno));
                        exit(1);
                }
                if (setsockopt(tcp6sock,
                    SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0)
-                       syslog(LOG_ERR, "setsockopt SO_REUSEADDR: %m");
+                       syslog(LOG_ERR, "setsockopt SO_REUSEADDR (%s)",
+                           strerror(errno));
                if (setsockopt(tcp6sock, IPPROTO_IPV6, IPV6_V6ONLY,
                    &on, sizeof on) < 0) {
                        syslog(LOG_ERR, "can't set v6-only binding for tcp6 "
-                                       "socket: %m");
+                           "socket (%s)", strerror(errno));
                        exit(1);
                }
                if (bind(tcp6sock, ai_tcp6->ai_addr, ai_tcp6->ai_addrlen) < 0) {
-                       syslog(LOG_ERR, "can't bind tcp6 addr");
+                       syslog(LOG_ERR, "can't bind tcp6 addr (%s)",
+                           strerror(errno));
                        exit(1);
                }
                if (listen(tcp6sock, 5) < 0) {
-                       syslog(LOG_ERR, "listen failed");
+                       syslog(LOG_ERR, "listen failed (%s)", strerror(errno));
                        exit(1);
                }
                if (!rpcb_set(RPCPROG_NFS, 2, nconf_tcp6, &nb_tcp6) ||
@@ -478,39 +482,43 @@
         */
        for (;;) {
                if (rump_sys_poll(set, 4, INFTIM) < 1) {
-                       syslog(LOG_ERR, "poll failed: %m");
+                       syslog(LOG_ERR, "poll failed (%s)", strerror(errno));
                        exit(1);
                }
 
-                       len = sizeof(inetpeer);
-                       if ((msgsock = accept(tcpsock,
-                           (struct sockaddr *)&inetpeer, &len)) < 0) {
-                               syslog(LOG_ERR, "accept failed: %d", error);
-                               exit(1);
-                       }
-                       memset(inetpeer.sin_zero, 0, sizeof(inetpeer.sin_zero));
-                       if (setsockopt(msgsock, SOL_SOCKET,
-                           SO_KEEPALIVE, (char *)&on, sizeof(on)) < 0)
-                               syslog(LOG_ERR,
-                                   "setsockopt SO_KEEPALIVE: %m");
-                       nfsdargs.sock = msgsock;
-                       nfsdargs.name = (caddr_t)&inetpeer;
-                       nfsdargs.namelen = sizeof(inetpeer);
-                       rump_sys_nfssvc(NFSSVC_ADDSOCK, &nfsdargs);
-                       (void)rump_sys_close(msgsock);
+               len = sizeof(inetpeer);
+               if ((msgsock = accept(tcpsock,
+                   (struct sockaddr *)&inetpeer, &len)) < 0) {
+                       syslog(LOG_ERR, "accept failed (%s)",
+                           strerror(errno));
+                       exit(1);
+               }
+               memset(inetpeer.sin_zero, 0, sizeof(inetpeer.sin_zero));
+               if (setsockopt(msgsock, SOL_SOCKET,
+                   SO_KEEPALIVE, (char *)&on, sizeof(on)) < 0)
+                       syslog(LOG_ERR, "setsockopt SO_KEEPALIVE (%s)",
+                           strerror(errno));
+               nfsdargs.sock = msgsock;
+               nfsdargs.name = (caddr_t)&inetpeer;
+               nfsdargs.namelen = sizeof(inetpeer);
+               rump_sys_nfssvc(NFSSVC_ADDSOCK, &nfsdargs);
+               (void)rump_sys_close(msgsock);
 
 #ifdef notyet
+               int error = 0;
                if (set[1].revents & POLLIN) {
                        len = sizeof(inet6peer);
                        if ((msgsock = rump_sys_accept(tcp6sock,
                            (struct sockaddr *)&inet6peer, &len, &error)) < 0) {
-                               syslog(LOG_ERR, "accept failed: %m");
+                               syslog(LOG_ERR, "accept failed (%s)",
+                                       strerror(error));
                                exit(1);
                        }
                        if (rump_sys_setsockopt(msgsock, SOL_SOCKET,
                            SO_KEEPALIVE, (char *)&on, sizeof(on), &error) < 0)
                                syslog(LOG_ERR,
-                                   "setsockopt SO_KEEPALIVE: %m");
+                                   "setsockopt SO_KEEPALIVE (%s)",
+                                       strerror(error));
                        nfsdargs.sock = msgsock;
                        nfsdargs.name = (caddr_t)&inet6peer;
                        nfsdargs.namelen = sizeof(inet6peer);
@@ -522,13 +530,14 @@
                        len = sizeof(isopeer);
                        if ((msgsock = rump_sys_accept(tp4sock,
                            (struct sockaddr *)&isopeer, &len, &error)) < 0) {
-                               syslog(LOG_ERR, "accept failed: %m");
+                               syslog(LOG_ERR, "accept failed (%s)",
+                                   strerror(error));
                                exit(1);



Home | Main Index | Thread Index | Old Index