Source-Changes-HG archive

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

[src/trunk]: src/tests/usr.sbin/inetd fix warnings



details:   https://anonhg.NetBSD.org/src/rev/8f326b0a92c8
branches:  trunk
changeset: 985610:8f326b0a92c8
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Sep 01 06:12:50 2021 +0000

description:
fix warnings

diffstat:

 tests/usr.sbin/inetd/Makefile      |   3 ++-
 tests/usr.sbin/inetd/t_inetd.c     |  26 +++++++++++++-------------
 tests/usr.sbin/inetd/test_server.c |  28 +++++++++++++---------------
 3 files changed, 28 insertions(+), 29 deletions(-)

diffs (194 lines):

diff -r d3a26b441c45 -r 8f326b0a92c8 tests/usr.sbin/inetd/Makefile
--- a/tests/usr.sbin/inetd/Makefile     Wed Sep 01 06:10:06 2021 +0000
+++ b/tests/usr.sbin/inetd/Makefile     Wed Sep 01 06:12:50 2021 +0000
@@ -1,5 +1,6 @@
-# $NetBSD: Makefile,v 1.1 2021/08/29 09:54:18 christos Exp $
+# $NetBSD: Makefile,v 1.2 2021/09/01 06:12:50 christos Exp $
 
+WARNS=6
 .include <bsd.own.mk>
 
 TESTSDIR=${TESTSBASE}/usr.sbin/inetd
diff -r d3a26b441c45 -r 8f326b0a92c8 tests/usr.sbin/inetd/t_inetd.c
--- a/tests/usr.sbin/inetd/t_inetd.c    Wed Sep 01 06:10:06 2021 +0000
+++ b/tests/usr.sbin/inetd/t_inetd.c    Wed Sep 01 06:12:50 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_inetd.c,v 1.1 2021/08/29 09:54:18 christos Exp $     */
+/*     $NetBSD: t_inetd.c,v 1.2 2021/09/01 06:12:50 christos Exp $     */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_inetd.c,v 1.1 2021/08/29 09:54:18 christos Exp $");
+__RCSID("$NetBSD: t_inetd.c,v 1.2 2021/09/01 06:12:50 christos Exp $");
 
 #include <atf-c.h>
 #include <spawn.h>
@@ -51,7 +51,7 @@
 #define TCP 6
 #define UDP 17
 
-static pid_t   run(const char *, char **);
+static pid_t   run(const char *, char *const *);
 static char    *concat(const char *restrict, const char *restrict);
 static void    waitfor(pid_t, const char *);
 static bool    run_udp_client(const char *);
@@ -83,15 +83,15 @@
        );
        
        /* Run inetd in debug mode using specified config file */
-       proc = run("inetd", (char*[]) {
-           "inetd", "-d",
+       proc = run("inetd", (char* const []) {
+           __UNCONST("inetd"), __UNCONST("-d"),
            concat(atf_tc_get_config_var(tc, "srcdir"),
            "/inetd_ratelimit.conf"),
            NULL
        });
 
        /* Wait for inetd to load services */
-       CHECK_ERROR(sleep(1));
+       sleep(1);
 
        /*
         * TODO test dgram/nowait? Specified in manpage but doesn't seem to
@@ -151,6 +151,8 @@
 ATF_TP_ADD_TCS(tp)
 {
        ATF_TP_ADD_TC(tp, test_ratelimit);
+
+       return atf_no_error();
 }
 
 /* Return true if successfully received message, false if timeout */
@@ -177,10 +179,6 @@
                .msg_iovlen = 1
        };
 
-       struct mmsghdr msglist = {
-               .msg_hdr = &msg
-       };
-       
        ssize_t count = recvmsg(udp, &msg, 0);
        if (count == -1) {
                if (errno == EAGAIN) {
@@ -254,7 +252,7 @@
        ATF_REQUIRE_MSG(res->ai_next == NULL, "Ambiguous create_socket args");
        CHECK_ERROR(fd = socket(res->ai_family, 
            res->ai_socktype, res->ai_protocol));
-       struct timeval timeout = { timeout_sec };
+       struct timeval timeout = { timeout_sec, 0 };
        CHECK_ERROR(setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, 
            sizeof(timeout)));
        memcpy(dst, res->ai_addr, res->ai_addrlen);
@@ -264,7 +262,7 @@
 
 /* Run program with args */
 static pid_t
-run(const char *prog, char **args)
+run(const char *prog, char *const *args)
 {
        pid_t proc;
        extern char **environ;
@@ -278,7 +276,9 @@
 waitfor(pid_t pid, const char *taskname)
 {
        int status;
-       CHECK_ERROR(waitpid(pid, &status, WALLSIG) == pid);
+       int rpid = waitpid(pid, &status, WALLSIG);
+       ATF_REQUIRE_MSG(rpid == pid, "wait %d != %d %s",
+           rpid, pid, strerror(errno));
 
        ATF_REQUIRE_EQ_MSG(WEXITSTATUS(status), EXIT_SUCCESS, 
            "%s failed with "
diff -r d3a26b441c45 -r 8f326b0a92c8 tests/usr.sbin/inetd/test_server.c
--- a/tests/usr.sbin/inetd/test_server.c        Wed Sep 01 06:10:06 2021 +0000
+++ b/tests/usr.sbin/inetd/test_server.c        Wed Sep 01 06:12:50 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: test_server.c,v 1.1 2021/08/29 09:54:18 christos Exp $ */
+/*     $NetBSD: test_server.c,v 1.2 2021/09/01 06:12:50 christos Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: test_server.c,v 1.1 2021/08/29 09:54:18 christos Exp $");
+__RCSID("$NetBSD: test_server.c,v 1.2 2021/09/01 06:12:50 christos Exp $");
 
 #include <sys/socket.h>
 #include <unistd.h>
@@ -91,18 +91,18 @@
 }
 
 static void
-stream_nowait_service()
+stream_nowait_service(void)
 {
        ssize_t count;
        char buffer[10];
        CHECK(count = recv(0, buffer, sizeof(buffer), 0));
        syslog(LOG_WARNING, "Received stream/nowait message \"%.*s\"\n",
-           count, buffer);
-       CHECK(send(1, buffer, count, 0));
+           (int)count, buffer);
+       CHECK(send(1, buffer, (size_t)count, 0));
 }
 
 static void
-stream_wait_service()
+stream_wait_service(void)
 {
        struct sockaddr_storage addr;
        ssize_t count;
@@ -113,18 +113,17 @@
        CHECK(fd = accept(0, (struct sockaddr*)&addr, &addr_len));
        CHECK(count = recv(fd, buffer, sizeof(buffer), 0));
        syslog(LOG_WARNING, "Received stream/wait message \"%.*s\"\n",
-           count, buffer);
-       CHECK(send(fd, buffer, count, 0));
+           (int)count, buffer);
+       CHECK(send(fd, buffer, (size_t)count, 0));
        CHECK(shutdown(fd, SHUT_RDWR));
        CHECK(close(fd));
 }
 
 static void
-dgram_wait_service()
+dgram_wait_service(void)
 {
        char buffer[256];
        char name[NI_MAXHOST];
-       socklen_t source_size;
        struct sockaddr_storage addr;
 
        struct iovec store = {
@@ -138,14 +137,13 @@
                .msg_iovlen = 1
                /* scatter/gather and control info is null */
        };
-       int count;
+       ssize_t count;
 
        /* Peek so service can still get the packet */
        CHECK(count = recvmsg(0, &header, 0));
 
-       CHECK(sendto(1, buffer, count, 0, 
-           (struct sockaddr*)(&addr), 
-           addr.ss_len));
+       CHECK(sendto(1, buffer, (size_t)count, 0, 
+           (struct sockaddr*)(&addr), addr.ss_len));
        
        int error = getnameinfo((struct sockaddr*)&addr, 
            addr.ss_len, name, NI_MAXHOST,
@@ -156,5 +154,5 @@
                exit(EXIT_FAILURE);
        }
        syslog(LOG_WARNING, "Received dgram/wait message \"%.*s\" from %s\n", 
-           count, buffer, name);
+           (int)count, buffer, name);
 }



Home | Main Index | Thread Index | Old Index