Index: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_connect.c =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_connect.c (revision 312148) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_connect.c (revision 312149) @@ -1,137 +1,133 @@ /* $NetBSD: t_connect.c,v 1.3 2017/01/13 20:09:48 christos Exp $ */ /* * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include #include #include #include #include -#ifdef __FreeBSD__ -#include -#endif - ATF_TC(connect_low_port); ATF_TC_HEAD(connect_low_port, tc) { atf_tc_set_md_var(tc, "descr", "Checks that low-port allocation " "works"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(connect_low_port, tc) { struct sockaddr_in sin, sinlist; int sd, val, slist; socklen_t slen; slist = socket(AF_INET, SOCK_STREAM, 0); sd = socket(AF_INET, SOCK_STREAM, 0); ATF_REQUIRE(sd > 0); ATF_REQUIRE(slist > 0); /* bind listening socket */ memset(&sinlist, 0, sizeof(sinlist)); sinlist.sin_family = AF_INET; sinlist.sin_port = htons(31522); sinlist.sin_addr.s_addr = inet_addr("127.0.0.1"); ATF_REQUIRE_EQ(bind(slist, (struct sockaddr *)&sinlist, sizeof(sinlist)), 0); ATF_REQUIRE_EQ(listen(slist, 1), 0); val = IP_PORTRANGE_LOW; if (setsockopt(sd, IPPROTO_IP, IP_PORTRANGE, &val, sizeof(val)) == -1) atf_tc_fail("setsockopt failed: %s", strerror(errno)); memset(&sin, 0, sizeof(sin)); sin.sin_port = htons(31522); sin.sin_addr.s_addr = inet_addr("127.0.0.1"); sin.sin_family = AF_INET; if (connect(sd, (struct sockaddr *)&sin, sizeof(sin)) == -1) { int serrno = errno; atf_tc_fail("connect failed: %s%s", strerror(serrno), serrno != EACCES ? "" : " (see http://mail-index.netbsd.org/" "source-changes/2007/12/16/0011.html)"); } slen = sizeof(sin); ATF_REQUIRE_EQ(getsockname(sd, (struct sockaddr *)&sin, &slen), 0); ATF_REQUIRE_EQ(slen, sizeof(sin)); ATF_REQUIRE(ntohs(sin.sin_port) <= IPPORT_RESERVEDMAX); close(sd); close(slist); } ATF_TC(connect_foreign_family); ATF_TC_HEAD(connect_foreign_family, tc) { atf_tc_set_md_var(tc, "descr", "Checks that connecting a socket " "with a different address family fails"); } ATF_TC_BODY(connect_foreign_family, tc) { struct sockaddr_in addr; /* addr.sin_family = AF_UNSPEC = 0 */ memset(&addr, 0, sizeof(addr)); /* * it is not necessary to initialize sin_{addr,port} since * those structure members shall not be accessed if connect * fails correctly. */ int sock = socket(AF_LOCAL, SOCK_STREAM, 0); ATF_REQUIRE(sock != -1); ATF_REQUIRE(-1 == connect(sock, (struct sockaddr *)&addr, sizeof(addr))); ATF_REQUIRE(EAFNOSUPPORT == errno); close(sock); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, connect_low_port); ATF_TP_ADD_TC(tp, connect_foreign_family); return atf_no_error(); } Index: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_dup.c =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_dup.c (revision 312148) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_dup.c (revision 312149) @@ -1,406 +1,402 @@ /* $NetBSD: t_dup.c,v 1.9 2017/01/13 20:31:53 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Jukka Ruohonen. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include __RCSID("$NetBSD: t_dup.c,v 1.9 2017/01/13 20:31:53 christos Exp $"); #include #include #include #include #include #include #include #include #include #include #include #include #include -#ifdef __FreeBSD__ -#include -#endif - static char path[] = "dup"; #ifdef __NetBSD__ static void check_mode(bool, bool, bool); #endif static void check_mode(bool _dup, bool _dup2, bool _dup3) { int mode[3] = { O_RDONLY, O_WRONLY, O_RDWR }; int perm[5] = { 0700, 0400, 0600, 0444, 0666 }; struct stat st, st1; int fd, fd1, fd2; size_t i, j; /* * Check that a duplicated descriptor * retains the mode of the original file. */ for (i = 0; i < __arraycount(mode); i++) { for (j = 0; j < __arraycount(perm); j++) { fd1 = open(path, mode[i] | O_CREAT, perm[j]); fd2 = open("/etc/passwd", O_RDONLY); ATF_REQUIRE(fd1 >= 0); ATF_REQUIRE(fd2 >= 0); if (_dup != false) fd = dup(fd1); else if (_dup2 != false) fd = dup2(fd1, fd2); else if (_dup3 != false) fd = dup3(fd1, fd2, O_CLOEXEC); else { fd = -1; } ATF_REQUIRE(fd >= 0); (void)memset(&st, 0, sizeof(struct stat)); (void)memset(&st1, 0, sizeof(struct stat)); ATF_REQUIRE(fstat(fd, &st) == 0); ATF_REQUIRE(fstat(fd1, &st1) == 0); if (st.st_mode != st1.st_mode) atf_tc_fail("invalid mode"); (void)close(fd); (void)close(fd1); (void)close(fd2); (void)unlink(path); } } } ATF_TC(dup2_basic); ATF_TC_HEAD(dup2_basic, tc) { atf_tc_set_md_var(tc, "descr", "A basic test of dup2(2)"); } ATF_TC_BODY(dup2_basic, tc) { int fd, fd1, fd2; fd1 = open("/etc/passwd", O_RDONLY); fd2 = open("/etc/passwd", O_RDONLY); ATF_REQUIRE(fd1 >= 0); ATF_REQUIRE(fd2 >= 0); fd = dup2(fd1, fd2); ATF_REQUIRE(fd >= 0); if (fd != fd2) atf_tc_fail("invalid descriptor"); (void)close(fd); (void)close(fd1); ATF_REQUIRE(close(fd2) != 0); } ATF_TC(dup2_err); ATF_TC_HEAD(dup2_err, tc) { atf_tc_set_md_var(tc, "descr", "Test error conditions of dup2(2)"); } ATF_TC_BODY(dup2_err, tc) { int fd; fd = open("/etc/passwd", O_RDONLY); ATF_REQUIRE(fd >= 0); errno = 0; ATF_REQUIRE_ERRNO(EBADF, dup2(-1, -1) == -1); errno = 0; ATF_REQUIRE_ERRNO(EBADF, dup2(fd, -1) == -1); errno = 0; ATF_REQUIRE_ERRNO(EBADF, dup2(-1, fd) == -1); /* * Note that this should not fail with EINVAL. */ ATF_REQUIRE(dup2(fd, fd) != -1); (void)close(fd); } ATF_TC(dup2_max); ATF_TC_HEAD(dup2_max, tc) { atf_tc_set_md_var(tc, "descr", "Test dup2(2) against limits"); } ATF_TC_BODY(dup2_max, tc) { struct rlimit res; (void)memset(&res, 0, sizeof(struct rlimit)); (void)getrlimit(RLIMIT_NOFILE, &res); errno = 0; ATF_REQUIRE_ERRNO(EBADF, dup2(STDERR_FILENO, res.rlim_cur + 1) == -1); } ATF_TC_WITH_CLEANUP(dup2_mode); ATF_TC_HEAD(dup2_mode, tc) { atf_tc_set_md_var(tc, "descr", "A basic test of dup2(2)"); } ATF_TC_BODY(dup2_mode, tc) { check_mode(false, true, false); } ATF_TC_CLEANUP(dup2_mode, tc) { (void)unlink(path); } ATF_TC(dup3_err); ATF_TC_HEAD(dup3_err, tc) { atf_tc_set_md_var(tc, "descr", "Test error conditions of dup3(2) (PR lib/45148)"); } ATF_TC_BODY(dup3_err, tc) { int fd; fd = open("/etc/passwd", O_RDONLY); ATF_REQUIRE(fd >= 0); errno = 0; #if defined(__FreeBSD__) || defined(__linux__) /* * FreeBSD and linux return EINVAL, because... * * [EINVAL] The oldd argument is equal to the newd argument. */ ATF_REQUIRE(dup3(fd, fd, O_CLOEXEC) == -1); #else ATF_REQUIRE(dup3(fd, fd, O_CLOEXEC) != -1); #endif errno = 0; #if defined(__FreeBSD__) || defined(__linux__) ATF_REQUIRE_ERRNO(EINVAL, dup3(-1, -1, O_CLOEXEC) == -1); ATF_REQUIRE_ERRNO(EBADF, dup3(fd, -1, O_CLOEXEC) == -1); #else ATF_REQUIRE_ERRNO(EBADF, dup3(-1, -1, O_CLOEXEC) == -1); #endif errno = 0; ATF_REQUIRE_ERRNO(EBADF, dup3(fd, -1, O_CLOEXEC) == -1); errno = 0; ATF_REQUIRE_ERRNO(EBADF, dup3(-1, fd, O_CLOEXEC) == -1); errno = 0; ATF_REQUIRE_ERRNO(EINVAL, dup3(fd, 1, O_NOFOLLOW) == -1); (void)close(fd); } ATF_TC(dup3_max); ATF_TC_HEAD(dup3_max, tc) { atf_tc_set_md_var(tc, "descr", "Test dup3(2) against limits"); } ATF_TC_BODY(dup3_max, tc) { struct rlimit res; (void)memset(&res, 0, sizeof(struct rlimit)); (void)getrlimit(RLIMIT_NOFILE, &res); errno = 0; ATF_REQUIRE_ERRNO(EBADF, dup3(STDERR_FILENO, res.rlim_cur + 1, O_CLOEXEC) == -1); } ATF_TC_WITH_CLEANUP(dup3_mode); ATF_TC_HEAD(dup3_mode, tc) { atf_tc_set_md_var(tc, "descr", "A basic test of dup3(2)"); } ATF_TC_BODY(dup3_mode, tc) { check_mode(false, false, true); } ATF_TC_CLEANUP(dup3_mode, tc) { (void)unlink(path); } ATF_TC(dup_err); ATF_TC_HEAD(dup_err, tc) { atf_tc_set_md_var(tc, "descr", "Test error conditions of dup(2)"); } ATF_TC_BODY(dup_err, tc) { errno = 0; ATF_REQUIRE_ERRNO(EBADF, dup(-1) == -1); } ATF_TC_WITH_CLEANUP(dup_max); ATF_TC_HEAD(dup_max, tc) { atf_tc_set_md_var(tc, "descr", "Test dup(2) against limits"); } ATF_TC_BODY(dup_max, tc) { struct rlimit res; int *buf, fd, sta; size_t i, n; pid_t pid; pid = fork(); ATF_REQUIRE(pid >= 0); if (pid == 0) { /* * Open a temporary file until the * maximum number of open files is * reached. Ater that dup(2) family * should fail with EMFILE. */ (void)closefrom(0); (void)memset(&res, 0, sizeof(struct rlimit)); n = 10; res.rlim_cur = res.rlim_max = n; if (setrlimit(RLIMIT_NOFILE, &res) != 0) _exit(EX_OSERR); buf = calloc(n, sizeof(int)); if (buf == NULL) _exit(EX_OSERR); buf[0] = mkstemp(path); if (buf[0] < 0) _exit(EX_OSERR); for (i = 1; i < n; i++) { buf[i] = open(path, O_RDONLY); if (buf[i] < 0) _exit(EX_OSERR); } errno = 0; fd = dup(buf[0]); if (fd != -1 || errno != EMFILE) _exit(EX_DATAERR); _exit(EXIT_SUCCESS); } (void)wait(&sta); if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) { if (WEXITSTATUS(sta) == EX_OSERR) atf_tc_fail("system call error"); if (WEXITSTATUS(sta) == EX_DATAERR) atf_tc_fail("dup(2) dupped more than RLIMIT_NOFILE"); atf_tc_fail("unknown error"); } (void)unlink(path); } ATF_TC_CLEANUP(dup_max, tc) { (void)unlink(path); } ATF_TC_WITH_CLEANUP(dup_mode); ATF_TC_HEAD(dup_mode, tc) { atf_tc_set_md_var(tc, "descr", "A basic test of dup(2)"); } ATF_TC_BODY(dup_mode, tc) { check_mode(true, false, false); } ATF_TC_CLEANUP(dup_mode, tc) { (void)unlink(path); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, dup2_basic); ATF_TP_ADD_TC(tp, dup2_err); ATF_TP_ADD_TC(tp, dup2_max); ATF_TP_ADD_TC(tp, dup2_mode); ATF_TP_ADD_TC(tp, dup3_err); ATF_TP_ADD_TC(tp, dup3_max); ATF_TP_ADD_TC(tp, dup3_mode); ATF_TP_ADD_TC(tp, dup_err); ATF_TP_ADD_TC(tp, dup_max); ATF_TP_ADD_TC(tp, dup_mode); return atf_no_error(); } Index: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_link.c =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_link.c (revision 312148) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_link.c (revision 312149) @@ -1,234 +1,230 @@ /* $NetBSD: t_link.c,v 1.3 2017/01/13 20:42:36 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Jukka Ruohonen. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include __RCSID("$NetBSD: t_link.c,v 1.3 2017/01/13 20:42:36 christos Exp $"); #include #include #include #include #include #include #include #include #include -#ifdef __FreeBSD__ -#include -#endif - static const char *getpath(void); static char path[] = "link"; static const char *pathl; static const char * getpath(void) { static char buf[LINE_MAX]; (void)memset(buf, '\0', sizeof(buf)); if (getcwd(buf, sizeof(buf)) == NULL) return NULL; (void)strlcat(buf, path, sizeof(buf)); (void)strlcat(buf, ".link", sizeof(buf)); return buf; } ATF_TC_WITH_CLEANUP(link_count); ATF_TC_HEAD(link_count, tc) { atf_tc_set_md_var(tc, "descr", "link(2) counts are incremented?"); } ATF_TC_BODY(link_count, tc) { struct stat sa, sb; int fd; (void)memset(&sa, 0, sizeof(struct stat)); (void)memset(&sb, 0, sizeof(struct stat)); pathl = getpath(); fd = open(path, O_RDWR | O_CREAT, 0600); ATF_REQUIRE(fd >= 0); ATF_REQUIRE(pathl != NULL); ATF_REQUIRE(stat(path, &sa) == 0); ATF_REQUIRE(link(path, pathl) == 0); ATF_REQUIRE(stat(path, &sb) == 0); if (sa.st_nlink != sb.st_nlink - 1) atf_tc_fail("incorrect link(2) count"); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(unlink(path) == 0); ATF_REQUIRE(unlink(pathl) == 0); } ATF_TC_CLEANUP(link_count, tc) { (void)unlink(path); (void)unlink(pathl); } ATF_TC_WITH_CLEANUP(link_err); ATF_TC_HEAD(link_err, tc) { atf_tc_set_md_var(tc, "descr", "Test error conditions of link(2)"); } ATF_TC_BODY(link_err, tc) { char buf[MAXPATHLEN + 1]; int fd; (void)memset(buf, 'x', sizeof(buf)); pathl = getpath(); fd = open(path, O_RDWR | O_CREAT, 0600); ATF_REQUIRE(fd >= 0); ATF_REQUIRE(pathl != NULL); errno = 0; ATF_REQUIRE(link(path, pathl) == 0); ATF_REQUIRE_ERRNO(EEXIST, link(path, pathl) == -1); errno = 0; ATF_REQUIRE_ERRNO(ENAMETOOLONG, link(buf, "xxx") == -1); errno = 0; ATF_REQUIRE_ERRNO(ENOENT, link(path, "/d/c/b/a") == -1); errno = 0; ATF_REQUIRE_ERRNO(ENOENT, link("/a/b/c/d", path) == -1); errno = 0; ATF_REQUIRE_ERRNO(ENOENT, link("/a/b/c/d", "/d/c/b/a") == -1); errno = 0; ATF_REQUIRE_ERRNO(EFAULT, link(path, (const char *)-1) == -1); errno = 0; ATF_REQUIRE_ERRNO(EFAULT, link((const char *)-1, "xxx") == -1); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(unlink(path) == 0); ATF_REQUIRE(unlink(pathl) == 0); } ATF_TC_CLEANUP(link_err, tc) { (void)unlink(path); (void)unlink(pathl); } ATF_TC(link_perm); ATF_TC_HEAD(link_perm, tc) { atf_tc_set_md_var(tc, "descr", "Test permissions with link(2)"); atf_tc_set_md_var(tc, "require.user", "unprivileged"); } ATF_TC_BODY(link_perm, tc) { int rv; errno = 0; rv = link("/root", "/root.link"); ATF_REQUIRE_MSG(rv == -1 && (errno == EACCES || errno == EPERM), "link to a directory did not fail with EPERM or EACCESS; link() " "returned %d, errno %d", rv, errno); errno = 0; ATF_REQUIRE_ERRNO(EACCES, link("/root/.profile", "/root/.profile.link") == -1); } ATF_TC_WITH_CLEANUP(link_stat); ATF_TC_HEAD(link_stat, tc) { atf_tc_set_md_var(tc, "descr", "Check stat(2) of a linked file"); } ATF_TC_BODY(link_stat, tc) { struct stat sa, sb; int fd; (void)memset(&sa, 0, sizeof(struct stat)); (void)memset(&sb, 0, sizeof(struct stat)); pathl = getpath(); fd = open(path, O_RDWR | O_CREAT, 0600); ATF_REQUIRE(fd >= 0); ATF_REQUIRE(pathl != NULL); ATF_REQUIRE(link(path, pathl) == 0); ATF_REQUIRE(stat(path, &sa) == 0); ATF_REQUIRE(lstat(pathl, &sb) == 0); if (sa.st_uid != sb.st_uid) atf_tc_fail("unequal UIDs"); if (sa.st_mode != sb.st_mode) atf_tc_fail("unequal modes"); if (sa.st_ino != sb.st_ino) atf_tc_fail("unequal inodes"); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(unlink(path) == 0); ATF_REQUIRE(unlink(pathl) == 0); } ATF_TC_CLEANUP(link_stat, tc) { (void)unlink(path); (void)unlink(pathl); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, link_count); ATF_TP_ADD_TC(tp, link_err); ATF_TP_ADD_TC(tp, link_perm); ATF_TP_ADD_TC(tp, link_stat); return atf_no_error(); } Index: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_listen.c =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_listen.c (revision 312148) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_listen.c (revision 312149) @@ -1,140 +1,136 @@ /* $NetBSD: t_listen.c,v 1.5 2017/01/13 20:41:50 christos Exp $ */ /* * Copyright (c) 2007 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include #include #include #include #include #include -#ifdef __FreeBSD__ -#include -#endif - static const char *path = "listen"; ATF_TC_WITH_CLEANUP(listen_err); ATF_TC_HEAD(listen_err, tc) { atf_tc_set_md_var(tc, "descr", "Checks errors from listen(2) (PR standards/46150)"); } ATF_TC_BODY(listen_err, tc) { static const size_t siz = sizeof(struct sockaddr_in); struct sockaddr_in sina, sinb; int fda, fdb, fdc; (void)memset(&sina, 0, sizeof(struct sockaddr_in)); (void)memset(&sinb, 0, sizeof(struct sockaddr_in)); sina.sin_family = AF_INET; sina.sin_port = htons(31522); sina.sin_addr.s_addr = inet_addr("127.0.0.1"); sinb.sin_family = AF_INET; sinb.sin_port = htons(31522); sinb.sin_addr.s_addr = inet_addr("127.0.0.1"); fda = socket(AF_INET, SOCK_STREAM, 0); fdb = socket(AF_INET, SOCK_STREAM, 0); fdc = open("listen", O_RDWR | O_CREAT, 0600); ATF_REQUIRE(fda >= 0 && fdb >= 0 && fdc >= 0); ATF_REQUIRE_ERRNO(ENOTSOCK, listen(fdc, 1) == -1); (void)close(fdc); (void)unlink(path); ATF_REQUIRE(bind(fda, (struct sockaddr *)&sina, siz) == 0); ATF_REQUIRE(listen(fda, 1) == 0); /* * According to IEEE Std 1003.1-2008: if the socket is * already connected, the call should fail with EINVAL. */ ATF_REQUIRE(connect(fdb, (struct sockaddr *)&sinb, siz) == 0); ATF_REQUIRE_ERRNO(EINVAL, listen(fdb, 1) == -1); (void)close(fda); (void)close(fdb); ATF_REQUIRE_ERRNO(EBADF, connect(fdb, (struct sockaddr *)&sinb, siz) == -1); } ATF_TC_CLEANUP(listen_err, tc) { (void)unlink(path); } ATF_TC(listen_low_port); ATF_TC_HEAD(listen_low_port, tc) { atf_tc_set_md_var(tc, "descr", "Does low-port allocation work?"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(listen_low_port, tc) { int sd, val; sd = socket(AF_INET, SOCK_STREAM, 0); ATF_REQUIRE_MSG(sd != -1, "socket failed: %s", strerror(errno)); val = IP_PORTRANGE_LOW; if (setsockopt(sd, IPPROTO_IP, IP_PORTRANGE, &val, sizeof(val)) == -1) atf_tc_fail("setsockopt failed: %s", strerror(errno)); if (listen(sd, 5) == -1) { int serrno = errno; atf_tc_fail("listen failed: %s%s", strerror(serrno), serrno != EACCES ? "" : " (see http://mail-index.netbsd.org/" "source-changes/2007/12/16/0011.html)"); } close(sd); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, listen_err); ATF_TP_ADD_TC(tp, listen_low_port); return 0; } Index: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_msgctl.c =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_msgctl.c (revision 312148) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_msgctl.c (revision 312149) @@ -1,363 +1,359 @@ /* $NetBSD: t_msgctl.c,v 1.5 2017/01/13 20:44:45 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Jukka Ruohonen. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include __RCSID("$NetBSD: t_msgctl.c,v 1.5 2017/01/13 20:44:45 christos Exp $"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include -#ifdef __FreeBSD__ -#include -#endif - #define MSG_KEY 12345689 #define MSG_MTYPE_1 0x41 struct msg { long mtype; char buf[3]; }; static void clean(void); static void clean(void) { int id; if ((id = msgget(MSG_KEY, 0)) != -1) (void)msgctl(id, IPC_RMID, 0); } ATF_TC_WITH_CLEANUP(msgctl_err); ATF_TC_HEAD(msgctl_err, tc) { atf_tc_set_md_var(tc, "descr", "Test errors from msgctl(2)"); } ATF_TC_BODY(msgctl_err, tc) { const int cmd[] = { IPC_STAT, IPC_SET, IPC_RMID }; struct msqid_ds msgds; size_t i; int id; (void)memset(&msgds, 0, sizeof(struct msqid_ds)); id = msgget(MSG_KEY, IPC_CREAT | 0600); ATF_REQUIRE(id != -1); errno = 0; ATF_REQUIRE_ERRNO(EINVAL, msgctl(id, INT_MAX, &msgds) == -1); errno = 0; ATF_REQUIRE_ERRNO(EFAULT, msgctl(id, IPC_STAT, (void *)-1) == -1); for (i = 0; i < __arraycount(cmd); i++) { errno = 0; ATF_REQUIRE_ERRNO(EINVAL, msgctl(-1, cmd[i], &msgds) == -1); } ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); } ATF_TC_CLEANUP(msgctl_err, tc) { clean(); } ATF_TC_WITH_CLEANUP(msgctl_perm); ATF_TC_HEAD(msgctl_perm, tc) { atf_tc_set_md_var(tc, "descr", "Test permissions with msgctl(2)"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(msgctl_perm, tc) { struct msqid_ds msgds; struct passwd *pw; pid_t pid; int sta; int id; (void)memset(&msgds, 0, sizeof(struct msqid_ds)); pw = getpwnam("nobody"); id = msgget(MSG_KEY, IPC_CREAT | 0600); ATF_REQUIRE(id != -1); ATF_REQUIRE(pw != NULL); ATF_REQUIRE(msgctl(id, IPC_STAT, &msgds) == 0); pid = fork(); ATF_REQUIRE(pid >= 0); if (pid == 0) { if (setuid(pw->pw_uid) != 0) _exit(EX_OSERR); msgds.msg_perm.uid = getuid(); msgds.msg_perm.gid = getgid(); errno = 0; if (msgctl(id, IPC_SET, &msgds) == 0) _exit(EXIT_FAILURE); if (errno != EPERM) _exit(EXIT_FAILURE); (void)memset(&msgds, 0, sizeof(struct msqid_ds)); if (msgctl(id, IPC_STAT, &msgds) != 0) _exit(EX_OSERR); msgds.msg_qbytes = 1; if (msgctl(id, IPC_SET, &msgds) == 0) _exit(EXIT_FAILURE); if (errno != EPERM) _exit(EXIT_FAILURE); _exit(EXIT_SUCCESS); } (void)wait(&sta); if (WIFEXITED(sta) == 0) { if (WEXITSTATUS(sta) == EX_OSERR) atf_tc_fail("system call failed"); if (WEXITSTATUS(sta) == EXIT_FAILURE) atf_tc_fail("UID %u manipulated root's " "message queue", pw->pw_uid); } ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); } ATF_TC_CLEANUP(msgctl_perm, tc) { clean(); } ATF_TC_WITH_CLEANUP(msgctl_pid); ATF_TC_HEAD(msgctl_pid, tc) { atf_tc_set_md_var(tc, "descr", "Test that PIDs are updated"); } ATF_TC_BODY(msgctl_pid, tc) { struct msg msg = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; struct msqid_ds msgds; int id, sta; pid_t pid; id = msgget(MSG_KEY, IPC_CREAT | 0600); ATF_REQUIRE(id != -1); pid = fork(); ATF_REQUIRE(pid >= 0); if (pid == 0) { (void)msgsnd(id, &msg, sizeof(struct msg), IPC_NOWAIT); _exit(EXIT_SUCCESS); } (void)sleep(1); (void)wait(&sta); (void)memset(&msgds, 0, sizeof(struct msqid_ds)); ATF_REQUIRE(msgctl(id, IPC_STAT, &msgds) == 0); if (pid != msgds.msg_lspid) atf_tc_fail("the PID of last msgsnd(2) was not updated"); pid = fork(); ATF_REQUIRE(pid >= 0); if (pid == 0) { (void)msgrcv(id, &msg, sizeof(struct msg), MSG_MTYPE_1, IPC_NOWAIT); _exit(EXIT_SUCCESS); } (void)sleep(1); (void)wait(&sta); (void)memset(&msgds, 0, sizeof(struct msqid_ds)); ATF_REQUIRE(msgctl(id, IPC_STAT, &msgds) == 0); if (pid != msgds.msg_lrpid) atf_tc_fail("the PID of last msgrcv(2) was not updated"); ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); } ATF_TC_CLEANUP(msgctl_pid, tc) { clean(); } ATF_TC_WITH_CLEANUP(msgctl_set); ATF_TC_HEAD(msgctl_set, tc) { atf_tc_set_md_var(tc, "descr", "Test msgctl(2) with IPC_SET"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(msgctl_set, tc) { struct msqid_ds msgds; struct passwd *pw; int id; (void)memset(&msgds, 0, sizeof(struct msqid_ds)); pw = getpwnam("nobody"); id = msgget(MSG_KEY, IPC_CREAT | 0600); ATF_REQUIRE(id != -1); ATF_REQUIRE(pw != NULL); ATF_REQUIRE(msgctl(id, IPC_STAT, &msgds) == 0); msgds.msg_perm.uid = pw->pw_uid; if (msgctl(id, IPC_SET, &msgds) != 0) atf_tc_fail("root failed to change the UID of message queue"); msgds.msg_perm.uid = getuid(); msgds.msg_perm.gid = pw->pw_gid; if (msgctl(id, IPC_SET, &msgds) != 0) atf_tc_fail("root failed to change the GID of message queue"); /* * Note: setting the qbytes to zero fails even as root. */ msgds.msg_qbytes = 1; msgds.msg_perm.gid = getgid(); if (msgctl(id, IPC_SET, &msgds) != 0) atf_tc_fail("root failed to change qbytes of message queue"); ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); } ATF_TC_CLEANUP(msgctl_set, tc) { clean(); } ATF_TC_WITH_CLEANUP(msgctl_time); ATF_TC_HEAD(msgctl_time, tc) { atf_tc_set_md_var(tc, "descr", "Test that access times are updated"); } ATF_TC_BODY(msgctl_time, tc) { struct msg msg = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; struct msqid_ds msgds; time_t t; int id; id = msgget(MSG_KEY, IPC_CREAT | 0600); ATF_REQUIRE(id != -1); t = time(NULL); (void)memset(&msgds, 0, sizeof(struct msqid_ds)); (void)msgsnd(id, &msg, sizeof(struct msg), IPC_NOWAIT); (void)msgctl(id, IPC_STAT, &msgds); if (llabs(t - msgds.msg_stime) > 1) atf_tc_fail("time of last msgsnd(2) was not updated"); if (msgds.msg_rtime != 0) atf_tc_fail("time of last msgrcv(2) was updated incorrectly"); t = time(NULL); (void)memset(&msgds, 0, sizeof(struct msqid_ds)); (void)msgrcv(id, &msg, sizeof(struct msg), MSG_MTYPE_1, IPC_NOWAIT); (void)msgctl(id, IPC_STAT, &msgds); if (llabs(t - msgds.msg_rtime) > 1) atf_tc_fail("time of last msgrcv(2) was not updated"); /* * Note: this is non-zero even after the memset(3). */ if (msgds.msg_stime == 0) atf_tc_fail("time of last msgsnd(2) was updated incorrectly"); ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); } ATF_TC_CLEANUP(msgctl_time, tc) { clean(); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, msgctl_err); ATF_TP_ADD_TC(tp, msgctl_perm); ATF_TP_ADD_TC(tp, msgctl_pid); ATF_TP_ADD_TC(tp, msgctl_set); ATF_TP_ADD_TC(tp, msgctl_time); return atf_no_error(); } Index: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_msgrcv.c =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_msgrcv.c (revision 312148) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_msgrcv.c (revision 312149) @@ -1,347 +1,343 @@ /* $NetBSD: t_msgrcv.c,v 1.4 2017/01/13 20:44:45 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Jukka Ruohonen. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include __RCSID("$NetBSD: t_msgrcv.c,v 1.4 2017/01/13 20:44:45 christos Exp $"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include -#ifdef __FreeBSD__ -#include -#endif - #define MSG_KEY 1234 #define MSG_MTYPE_1 0x41 #define MSG_MTYPE_2 0x42 #define MSG_MTYPE_3 0x43 #define MSG_LEN 3 struct msg { long mtype; char buf[MSG_LEN]; }; static void clean(void); static void clean(void) { int id; if ((id = msgget(MSG_KEY, 0)) != -1) (void)msgctl(id, IPC_RMID, 0); } ATF_TC_WITH_CLEANUP(msgrcv_basic); ATF_TC_HEAD(msgrcv_basic, tc) { atf_tc_set_md_var(tc, "descr", "A basic test of msgrcv(2)"); } ATF_TC_BODY(msgrcv_basic, tc) { struct msg msg1 = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; struct msg msg2 = { MSG_MTYPE_1, { 'x', 'y', 'z' } }; int id; id = msgget(MSG_KEY, IPC_CREAT | 0600); ATF_REQUIRE(id != -1); (void)msgsnd(id, &msg1, MSG_LEN, IPC_NOWAIT); (void)msgrcv(id, &msg2, MSG_LEN, MSG_MTYPE_1, IPC_NOWAIT); ATF_CHECK(msg1.buf[0] == msg2.buf[0]); ATF_CHECK(msg1.buf[1] == msg2.buf[1]); ATF_CHECK(msg1.buf[2] == msg2.buf[2]); ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); } ATF_TC_CLEANUP(msgrcv_basic, tc) { clean(); } ATF_TC_WITH_CLEANUP(msgrcv_block); ATF_TC_HEAD(msgrcv_block, tc) { atf_tc_set_md_var(tc, "descr", "Test that msgrcv(2) blocks"); } ATF_TC_BODY(msgrcv_block, tc) { struct msg msg = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; int id, sta; pid_t pid; id = msgget(MSG_KEY, IPC_CREAT | 0600); ATF_REQUIRE(id != -1); pid = fork(); ATF_REQUIRE(pid >= 0); if (pid == 0) { if (msgrcv(id, &msg, MSG_LEN, MSG_MTYPE_1, 0) < 0) _exit(EXIT_FAILURE); _exit(EXIT_SUCCESS); } /* * Below msgsnd(2) should unblock the child, * and hence kill(2) should fail with ESRCH. */ (void)sleep(1); (void)msgsnd(id, &msg, MSG_LEN, IPC_NOWAIT); (void)sleep(1); (void)kill(pid, SIGKILL); (void)wait(&sta); if (WIFEXITED(sta) == 0 || WIFSIGNALED(sta) != 0) atf_tc_fail("msgrcv(2) did not block"); ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); } ATF_TC_CLEANUP(msgrcv_block, tc) { clean(); } ATF_TC_WITH_CLEANUP(msgrcv_err); ATF_TC_HEAD(msgrcv_err, tc) { atf_tc_set_md_var(tc, "descr", "Test errors from msgrcv(2)"); } ATF_TC_BODY(msgrcv_err, tc) { struct msg msg = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; int id, r = 0; id = msgget(MSG_KEY, IPC_CREAT | 0600); ATF_REQUIRE(id != -1); errno = 0; ATF_REQUIRE_ERRNO(ENOMSG, msgrcv(id, &msg, MSG_LEN, MSG_MTYPE_1, IPC_NOWAIT) == -1); ATF_REQUIRE(msgsnd(id, &msg, MSG_LEN, IPC_NOWAIT) == 0); errno = 0; ATF_REQUIRE_ERRNO(EFAULT, msgrcv(id, (void *)-1, MSG_LEN, MSG_MTYPE_1, IPC_NOWAIT) == -1); errno = 0; ATF_REQUIRE_ERRNO(EINVAL, msgrcv(-1, &msg, MSG_LEN, MSG_MTYPE_1, IPC_NOWAIT) == -1); errno = 0; ATF_REQUIRE_ERRNO(EINVAL, msgrcv(-1, &msg, SSIZE_MAX, MSG_MTYPE_1, IPC_NOWAIT) == -1); ATF_REQUIRE(msgsnd(id, &msg, MSG_LEN, IPC_NOWAIT) == 0); errno = 0; ATF_REQUIRE_ERRNO(E2BIG, msgrcv(id, &r, MSG_LEN - 1, MSG_MTYPE_1, IPC_NOWAIT) == -1); ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); } ATF_TC_CLEANUP(msgrcv_err, tc) { clean(); } ATF_TC_WITH_CLEANUP(msgrcv_mtype); ATF_TC_HEAD(msgrcv_mtype, tc) { atf_tc_set_md_var(tc, "descr", "Test message types with msgrcv(2)"); } ATF_TC_BODY(msgrcv_mtype, tc) { struct msg msg1 = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; struct msg msg2 = { MSG_MTYPE_3, { 'x', 'y', 'z' } }; int id; id = msgget(MSG_KEY, IPC_CREAT | 0600); ATF_REQUIRE(id != -1); (void)msgsnd(id, &msg1, MSG_LEN, IPC_NOWAIT); (void)msgrcv(id, &msg2, MSG_LEN, MSG_MTYPE_2, IPC_NOWAIT); ATF_CHECK(msg1.buf[0] != msg2.buf[0]); /* Different mtype. */ ATF_CHECK(msg1.buf[1] != msg2.buf[1]); ATF_CHECK(msg1.buf[2] != msg2.buf[2]); (void)msgrcv(id, &msg2, MSG_LEN, MSG_MTYPE_1, IPC_NOWAIT); ATF_CHECK(msg1.buf[0] == msg2.buf[0]); /* Same mtype. */ ATF_CHECK(msg1.buf[1] == msg2.buf[1]); ATF_CHECK(msg1.buf[2] == msg2.buf[2]); ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); } ATF_TC_CLEANUP(msgrcv_mtype, tc) { clean(); } ATF_TC_WITH_CLEANUP(msgrcv_nonblock); ATF_TC_HEAD(msgrcv_nonblock, tc) { atf_tc_set_md_var(tc, "descr", "Test msgrcv(2) with IPC_NOWAIT"); atf_tc_set_md_var(tc, "timeout", "10"); } ATF_TC_BODY(msgrcv_nonblock, tc) { struct msg msg = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; const ssize_t n = 10; int id, sta; ssize_t i; pid_t pid; id = msgget(MSG_KEY, IPC_CREAT | 0600); ATF_REQUIRE(id != -1); for (i = 0; i < n; i++) { ATF_REQUIRE(msgsnd(id, &msg, MSG_LEN, IPC_NOWAIT) == 0); } pid = fork(); ATF_REQUIRE(pid >= 0); if (pid == 0) { while (i != 0) { if (msgrcv(id, &msg, MSG_LEN, MSG_MTYPE_1, IPC_NOWAIT) == -1) _exit(EXIT_FAILURE); i--; } _exit(EXIT_SUCCESS); } (void)sleep(2); (void)kill(pid, SIGKILL); (void)wait(&sta); if (WIFSIGNALED(sta) != 0 || WTERMSIG(sta) == SIGKILL) atf_tc_fail("msgrcv(2) blocked with IPC_NOWAIT"); if (WIFEXITED(sta) == 0 && WEXITSTATUS(sta) != EXIT_SUCCESS) atf_tc_fail("msgrcv(2) failed"); ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); } ATF_TC_CLEANUP(msgrcv_nonblock, tc) { clean(); } ATF_TC_WITH_CLEANUP(msgrcv_truncate); ATF_TC_HEAD(msgrcv_truncate, tc) { atf_tc_set_md_var(tc, "descr", "Test msgrcv(2) with MSG_NOERROR"); } ATF_TC_BODY(msgrcv_truncate, tc) { #define MSG_SMALLLEN 2 struct msgsmall { long mtype; char buf[MSG_SMALLLEN]; }; struct msg msg1 = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; struct msgsmall msg2 = { MSG_MTYPE_1, { 'x', 'y' } }; int id; id = msgget(MSG_KEY, IPC_CREAT | 0600); ATF_REQUIRE(id != -1); (void)msgsnd(id, &msg1, MSG_LEN, IPC_NOWAIT); (void)msgrcv(id, &msg2, MSG_SMALLLEN, MSG_MTYPE_1, IPC_NOWAIT | MSG_NOERROR); ATF_CHECK(msg1.buf[0] == msg2.buf[0]); ATF_CHECK(msg1.buf[1] == msg2.buf[1]); ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); } ATF_TC_CLEANUP(msgrcv_truncate, tc) { clean(); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, msgrcv_basic); ATF_TP_ADD_TC(tp, msgrcv_block); ATF_TP_ADD_TC(tp, msgrcv_err); ATF_TP_ADD_TC(tp, msgrcv_mtype); ATF_TP_ADD_TC(tp, msgrcv_nonblock); ATF_TP_ADD_TC(tp, msgrcv_truncate); return atf_no_error(); } Index: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_msgsnd.c =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_msgsnd.c (revision 312148) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_msgsnd.c (revision 312149) @@ -1,343 +1,339 @@ /* $NetBSD: t_msgsnd.c,v 1.3 2017/01/13 20:44:45 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Jukka Ruohonen. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include __RCSID("$NetBSD: t_msgsnd.c,v 1.3 2017/01/13 20:44:45 christos Exp $"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include -#ifdef __FreeBSD__ -#include -#endif - #define MSG_KEY 1234 #define MSG_MTYPE_1 0x41 #define MSG_MTYPE_2 0x42 #define MSG_MTYPE_3 0x43 struct msg { long mtype; char buf[3]; }; static void clean(void); static void clean(void) { int id; if ((id = msgget(MSG_KEY, 0)) != -1) (void)msgctl(id, IPC_RMID, 0); } ATF_TC_WITH_CLEANUP(msgsnd_block); ATF_TC_HEAD(msgsnd_block, tc) { atf_tc_set_md_var(tc, "descr", "Test that msgsnd(2) blocks"); atf_tc_set_md_var(tc, "timeout", "10"); } ATF_TC_BODY(msgsnd_block, tc) { struct msg msg = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; int id, sta; pid_t pid; id = msgget(MSG_KEY, IPC_CREAT | 0600); ATF_REQUIRE(id != -1); pid = fork(); ATF_REQUIRE(pid >= 0); if (pid == 0) { /* * Enqueue messages until some limit (e.g. the maximum * number of messages in the queue or the maximum number * of bytes in the queue) is reached. After this the call * should block when the IPC_NOWAIT is not set. */ for (;;) { if (msgsnd(id, &msg, sizeof(struct msg), 0) < 0) _exit(EXIT_FAILURE); } } (void)sleep(2); (void)kill(pid, SIGKILL); (void)wait(&sta); if (WIFEXITED(sta) != 0 || WIFSIGNALED(sta) == 0) atf_tc_fail("msgsnd(2) did not block"); ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); } ATF_TC_CLEANUP(msgsnd_block, tc) { clean(); } ATF_TC_WITH_CLEANUP(msgsnd_count); ATF_TC_HEAD(msgsnd_count, tc) { atf_tc_set_md_var(tc, "descr", "Test that msgsnd(2) increments the amount of " "message in the queue, as given by msgctl(2)"); atf_tc_set_md_var(tc, "timeout", "10"); } ATF_TC_BODY(msgsnd_count, tc) { struct msg msg = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; struct msqid_ds ds; size_t i = 0; int id, rv; id = msgget(MSG_KEY, IPC_CREAT | 0600); ATF_REQUIRE(id != -1); for (;;) { errno = 0; rv = msgsnd(id, &msg, sizeof(struct msg), IPC_NOWAIT); if (rv == 0) { i++; continue; } if (rv == -1 && errno == EAGAIN) break; atf_tc_fail("failed to enqueue a message"); } (void)memset(&ds, 0, sizeof(struct msqid_ds)); (void)msgctl(id, IPC_STAT, &ds); if (ds.msg_qnum != i) atf_tc_fail("incorrect message count"); ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); } ATF_TC_CLEANUP(msgsnd_count, tc) { clean(); } ATF_TC_WITH_CLEANUP(msgsnd_err); ATF_TC_HEAD(msgsnd_err, tc) { atf_tc_set_md_var(tc, "descr", "Test errors from msgsnd(2)"); } ATF_TC_BODY(msgsnd_err, tc) { struct msg msg = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; int id; id = msgget(MSG_KEY, IPC_CREAT | 0600); ATF_REQUIRE(id != -1); errno = 0; ATF_REQUIRE_ERRNO(EFAULT, msgsnd(id, (void *)-1, sizeof(struct msg), IPC_NOWAIT) == -1); errno = 0; ATF_REQUIRE_ERRNO(EINVAL, msgsnd(-1, &msg, sizeof(struct msg), IPC_NOWAIT) == -1); errno = 0; ATF_REQUIRE_ERRNO(EINVAL, msgsnd(-1, &msg, SSIZE_MAX, IPC_NOWAIT) == -1); errno = 0; msg.mtype = 0; ATF_REQUIRE_ERRNO(EINVAL, msgsnd(id, &msg, sizeof(struct msg), IPC_NOWAIT) == -1); ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); } ATF_TC_CLEANUP(msgsnd_err, tc) { clean(); } ATF_TC_WITH_CLEANUP(msgsnd_nonblock); ATF_TC_HEAD(msgsnd_nonblock, tc) { atf_tc_set_md_var(tc, "descr", "Test msgsnd(2) with IPC_NOWAIT"); atf_tc_set_md_var(tc, "timeout", "10"); } ATF_TC_BODY(msgsnd_nonblock, tc) { struct msg msg = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; int id, rv, sta; pid_t pid; id = msgget(MSG_KEY, IPC_CREAT | 0600); ATF_REQUIRE(id != -1); pid = fork(); ATF_REQUIRE(pid >= 0); if (pid == 0) { for (;;) { errno = 0; rv = msgsnd(id, &msg, sizeof(struct msg), IPC_NOWAIT); if (rv == -1 && errno == EAGAIN) _exit(EXIT_SUCCESS); } } (void)sleep(2); (void)kill(pid, SIGKILL); (void)wait(&sta); if (WIFEXITED(sta) == 0 || WIFSIGNALED(sta) != 0) atf_tc_fail("msgsnd(2) blocked with IPC_NOWAIT"); ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); } ATF_TC_CLEANUP(msgsnd_nonblock, tc) { clean(); } ATF_TC_WITH_CLEANUP(msgsnd_perm); ATF_TC_HEAD(msgsnd_perm, tc) { atf_tc_set_md_var(tc, "descr", "Test permissions with msgsnd(2)"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(msgsnd_perm, tc) { struct msg msg = { MSG_MTYPE_1, { 'a', 'b', 'c' } }; struct passwd *pw; int id, sta; pid_t pid; uid_t uid; pw = getpwnam("nobody"); id = msgget(MSG_KEY, IPC_CREAT | 0600); ATF_REQUIRE(id != -1); ATF_REQUIRE(pw != NULL); uid = pw->pw_uid; ATF_REQUIRE(uid != 0); pid = fork(); ATF_REQUIRE(pid >= 0); if (pid == 0) { /* * Try to enqueue a message to the queue * created by root as RW for owner only. */ if (setuid(uid) != 0) _exit(EX_OSERR); id = msgget(MSG_KEY, 0); if (id == -1) _exit(EX_OSERR); errno = 0; if (msgsnd(id, &msg, sizeof(struct msg), IPC_NOWAIT) == 0) _exit(EXIT_FAILURE); if (errno != EACCES) _exit(EXIT_FAILURE); _exit(EXIT_SUCCESS); } (void)wait(&sta); if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) { if (errno == EX_OSERR) atf_tc_fail("system call failed"); atf_tc_fail("UID %u enqueued message to root's queue", uid); } ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0); } ATF_TC_CLEANUP(msgsnd_perm, tc) { clean(); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, msgsnd_block); ATF_TP_ADD_TC(tp, msgsnd_count); ATF_TP_ADD_TC(tp, msgsnd_err); ATF_TP_ADD_TC(tp, msgsnd_nonblock); ATF_TP_ADD_TC(tp, msgsnd_perm); return atf_no_error(); } Index: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_msync.c =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_msync.c (revision 312148) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_msync.c (revision 312149) @@ -1,248 +1,260 @@ /* $NetBSD: t_msync.c,v 1.2 2012/03/16 06:15:17 matt Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Jukka Ruohonen. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include __RCSID("$NetBSD: t_msync.c,v 1.2 2012/03/16 06:15:17 matt Exp $"); #include #include #include #include #include #include #include #include static long page = 0; static const off_t off = 512; static const char path[] = "msync"; static const char *msync_sync(const char *, int); static const char * msync_sync(const char *garbage, int flags) { char *buf, *map = MAP_FAILED; const char *str = NULL; size_t i, len; ssize_t tot; int fd, rv; /* * Create a temporary file, write * one page to it, and map the file. */ buf = malloc(page); if (buf == NULL) return NULL; +#ifdef __FreeBSD__ + memset(buf, 'x', page); +#else for (i = 0; i < (size_t)page; i++) buf[i] = 'x'; +#endif fd = open(path, O_RDWR | O_CREAT, 0700); if (fd < 0) { +#ifdef __FreeBSD__ + free(buf); + return "failed to open"; +#else str = "failed to open"; goto out; +#endif } +#if __FreeBSD__ + (void)write(fd, buf, page); +#else tot = 0; while (tot < page) { rv = write(fd, buf, sizeof(buf)); - if (rv < 0) { str = "failed to write"; goto out; } tot += rv; } +#endif map = mmap(NULL, page, PROT_READ | PROT_WRITE, MAP_FILE|MAP_PRIVATE, fd, 0); if (map == MAP_FAILED) { str = "failed to map"; goto out; } /* * Seek to an arbitrary offset and * write garbage to this position. */ if (lseek(fd, off, SEEK_SET) != off) { str = "failed to seek"; goto out; } len = strlen(garbage); rv = write(fd, garbage, len); if (rv != (ssize_t)len) { str = "failed to write garbage"; goto out; } /* * Synchronize the mapping and verify * that garbage is at the given offset. */ if (msync(map, page, flags) != 0) { str = "failed to msync"; goto out; } if (memcmp(map + off, garbage, len) != 0) { str = "msync did not synchronize"; goto out; } out: free(buf); (void)close(fd); (void)unlink(path); if (map != MAP_FAILED) (void)munmap(map, page); return str; } ATF_TC(msync_async); ATF_TC_HEAD(msync_async, tc) { atf_tc_set_md_var(tc, "descr", "Test of msync(2), MS_ASYNC"); } ATF_TC_BODY(msync_async, tc) { const char *str; str = msync_sync("garbage", MS_ASYNC); if (str != NULL) atf_tc_fail("%s", str); } ATF_TC(msync_err); ATF_TC_HEAD(msync_err, tc) { atf_tc_set_md_var(tc, "descr", "Test error conditions in msync(2)"); } ATF_TC_BODY(msync_err, tc) { char *map = MAP_FAILED; /* * Test that invalid flags error out. */ #ifdef __FreeBSD__ errno = 0; ATF_REQUIRE_ERRNO(EINVAL, msync_sync("error", -1) != NULL); errno = 0; ATF_REQUIRE_ERRNO(EINVAL, msync_sync("error", INT_MAX) != NULL); #else ATF_REQUIRE(msync_sync("error", -1) != NULL); ATF_REQUIRE(msync_sync("error", INT_MAX) != NULL); #endif errno = 0; /* * Map a page and then unmap to get an unmapped address. */ map = mmap(NULL, page, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); ATF_REQUIRE(map != MAP_FAILED); (void)munmap(map, page); ATF_REQUIRE(msync(map, page, MS_SYNC) != 0); #ifdef __FreeBSD__ ATF_REQUIRE(errno == ENOMEM); #else ATF_REQUIRE(errno == EFAULT); #endif } ATF_TC(msync_invalidate); ATF_TC_HEAD(msync_invalidate, tc) { atf_tc_set_md_var(tc, "descr", "Test of msync(2), MS_INVALIDATE"); } ATF_TC_BODY(msync_invalidate, tc) { const char *str; str = msync_sync("garbage", MS_INVALIDATE); if (str != NULL) atf_tc_fail("%s", str); } ATF_TC(msync_sync); ATF_TC_HEAD(msync_sync, tc) { atf_tc_set_md_var(tc, "descr", "Test of msync(2), MS_SYNC"); } ATF_TC_BODY(msync_sync, tc) { const char *str; str = msync_sync("garbage", MS_SYNC); if (str != NULL) atf_tc_fail("%s", str); } ATF_TP_ADD_TCS(tp) { page = sysconf(_SC_PAGESIZE); ATF_REQUIRE(page >= 0); ATF_REQUIRE(page > off); ATF_TP_ADD_TC(tp, msync_async); ATF_TP_ADD_TC(tp, msync_err); ATF_TP_ADD_TC(tp, msync_invalidate); ATF_TP_ADD_TC(tp, msync_sync); return atf_no_error(); } Index: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_sigqueue.c =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_sigqueue.c (revision 312148) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_sigqueue.c (revision 312149) @@ -1,247 +1,240 @@ /* $NetBSD: t_sigqueue.c,v 1.7 2017/01/13 20:44:10 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Christos Zoulas. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include __RCSID("$NetBSD: t_sigqueue.c,v 1.7 2017/01/13 20:44:10 christos Exp $"); #include #include #include #include #include #include #include #include -#ifdef __FreeBSD__ -#include -#include -#endif - static void handler(int, siginfo_t *, void *); #define VALUE (int)0xc001dad1 static int value; static void handler(int signo __unused, siginfo_t *info, void *data __unused) { value = info->si_value.sival_int; kill(0, SIGINFO); } ATF_TC(sigqueue_basic); ATF_TC_HEAD(sigqueue_basic, tc) { atf_tc_set_md_var(tc, "descr", "Checks sigqueue(3) sigval delivery"); } ATF_TC_BODY(sigqueue_basic, tc) { struct sigaction sa; union sigval sv; sa.sa_sigaction = handler; sigemptyset(&sa.sa_mask); sa.sa_flags = SA_SIGINFO; if (sigaction(SIGUSR1, &sa, NULL) != 0) atf_tc_fail("sigaction failed"); sv.sival_int = VALUE; #ifdef __FreeBSD__ /* * From kern_sig.c: * Specification says sigqueue can only send signal to single process. */ if (sigqueue(getpid(), SIGUSR1, sv) != 0) #else if (sigqueue(0, SIGUSR1, sv) != 0) #endif atf_tc_fail("sigqueue failed"); sched_yield(); ATF_REQUIRE_EQ(sv.sival_int, value); } ATF_TC(sigqueue_err); ATF_TC_HEAD(sigqueue_err, tc) { atf_tc_set_md_var(tc, "descr", "Test errors from sigqueue(3)"); } ATF_TC_BODY(sigqueue_err, tc) { static union sigval sv; errno = 0; ATF_REQUIRE_ERRNO(EINVAL, sigqueue(getpid(), -1, sv) == -1); } static int signals[] = { SIGINT, SIGRTMIN + 1, SIGINT, SIGRTMIN + 0, SIGRTMIN + 2, SIGQUIT, SIGRTMIN + 1 }; #ifdef __arraycount #define CNT __arraycount(signals) #else #define CNT (sizeof(signals) / sizeof(signals[0])) #endif static sig_atomic_t count = 0; static int delivered[CNT]; static void myhandler(int signo, siginfo_t *info, void *context __unused) { delivered[count++] = signo; printf("Signal #%zu: signo: %d\n", (size_t)count, signo); } static int asc(const void *a, const void *b) { const int *ia = a, *ib = b; return *ib - *ia; } /* * given a array of signals to be delivered in tosend of size len * place in ordered the signals to be delivered in delivery order * and return the number of signals that should be delivered */ static size_t sigorder(int *ordered, const int *tosend, size_t len) { memcpy(ordered, tosend, len * sizeof(*tosend)); qsort(ordered, len, sizeof(*ordered), asc); if (len == 1) return len; #ifdef __FreeBSD__ /* * Don't dedupe signal numbers (bug 212173) * * Per kib's comment.. * * " * OTOH, FreeBSD behaviour is to treat all signals as realtime while * there is no mem shortage and siginfo can be allocated. In * particular, signals < SIGRTMIN are not collapsed when queued more * than once. * " */ return len; #else size_t i, j; for (i = 0, j = 0; i < len - 1; i++) { if (ordered[i] >= SIGRTMIN) continue; if (j == 0) j = i + 1; while (ordered[i] == ordered[j] && j < len) j++; if (j == len) break; ordered[i + 1] = ordered[j]; } return i + 1; #endif } ATF_TC(sigqueue_rt); ATF_TC_HEAD(sigqueue_rt, tc) { atf_tc_set_md_var(tc, "descr", "Test queuing of real-time signals"); } ATF_TC_BODY(sigqueue_rt, tc) { pid_t pid; union sigval val; struct sigaction act; int ordered[CNT]; struct sigaction oact[CNT]; size_t ndelivered; ndelivered = sigorder(ordered, signals, CNT); act.sa_flags = SA_SIGINFO; act.sa_sigaction = myhandler; sigemptyset(&act.sa_mask); for (size_t i = 0; i < ndelivered; i++) ATF_REQUIRE(sigaction(ordered[i], &act, &oact[i]) != -1); val.sival_int = 0; pid = getpid(); sigset_t mask, orig; sigemptyset(&mask); for (size_t i = 0; i < CNT; i++) if (sigaddset(&mask, signals[i]) == -1) warn("sigaddset"); - ATF_REQUIRE(sigprocmask(SIG_BLOCK, &mask, &orig) != -1); for (size_t i = 0; i < CNT; i++) ATF_REQUIRE(sigqueue(pid, signals[i], val) != -1); ATF_REQUIRE(sigprocmask(SIG_UNBLOCK, &mask, &orig) != -1); sleep(1); ATF_CHECK_MSG((size_t)count == ndelivered, "count %zu != ndelivered %zu", (size_t)count, ndelivered); - for (size_t i = 0; i < ndelivered; i++) ATF_REQUIRE_MSG(ordered[i] == delivered[i], "%zu: ordered %d != delivered %d", i, ordered[i], delivered[i]); if ((size_t)count > ndelivered) for (size_t i = ndelivered; i < (size_t)count; i++) printf("Undelivered signal #%zu: %d\n", i, ordered[i]); for (size_t i = 0; i < ndelivered; i++) ATF_REQUIRE(sigaction(signals[i], &oact[i], NULL) != -1); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, sigqueue_basic); ATF_TP_ADD_TC(tp, sigqueue_err); ATF_TP_ADD_TC(tp, sigqueue_rt); return atf_no_error(); } Index: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_stat.c =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_stat.c (revision 312148) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_stat.c (revision 312149) @@ -1,426 +1,419 @@ /* $NetBSD: t_stat.c,v 1.5 2017/01/13 20:06:50 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Jukka Ruohonen. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include __RCSID("$NetBSD: t_stat.c,v 1.5 2017/01/13 20:06:50 christos Exp $"); #include #include #include #include #include #include #include #include #include #include #include #include #include -#ifdef __FreeBSD__ -#include -#endif - static const char *path = "stat"; ATF_TC_WITH_CLEANUP(stat_chflags); ATF_TC_HEAD(stat_chflags, tc) { atf_tc_set_md_var(tc, "descr", "Test chflags(2) with stat(2)"); } ATF_TC_BODY(stat_chflags, tc) { struct stat sa, sb; int fd; (void)memset(&sa, 0, sizeof(struct stat)); (void)memset(&sb, 0, sizeof(struct stat)); fd = open(path, O_RDONLY | O_CREAT); ATF_REQUIRE(fd != -1); ATF_REQUIRE(stat(path, &sa) == 0); ATF_REQUIRE(chflags(path, UF_NODUMP) == 0); ATF_REQUIRE(stat(path, &sb) == 0); if (sa.st_flags == sb.st_flags) atf_tc_fail("stat(2) did not detect chflags(2)"); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(unlink(path) == 0); } ATF_TC_CLEANUP(stat_chflags, tc) { (void)unlink(path); } ATF_TC(stat_dir); ATF_TC_HEAD(stat_dir, tc) { atf_tc_set_md_var(tc, "descr", "Test stat(2) with directories"); } ATF_TC_BODY(stat_dir, tc) { const short depth = 2; struct stat sa, sb; char *argv[2]; FTSENT *ftse; FTS *fts; int ops; argv[1] = NULL; argv[0] = __UNCONST("/"); ops = FTS_NOCHDIR; ops |= FTS_PHYSICAL; fts = fts_open(argv, ops, NULL); ATF_REQUIRE(fts != NULL); while ((ftse = fts_read(fts)) != NULL) { if (ftse->fts_level < 1) continue; if (ftse->fts_level > depth) { (void)fts_set(fts, ftse, FTS_SKIP); continue; } switch(ftse->fts_info) { case FTS_DP: (void)memset(&sa, 0, sizeof(struct stat)); (void)memset(&sb, 0, sizeof(struct stat)); ATF_REQUIRE(stat(ftse->fts_parent->fts_path,&sa) == 0); ATF_REQUIRE(chdir(ftse->fts_path) == 0); ATF_REQUIRE(stat(".", &sb) == 0); /* * The previous two stat(2) calls * should be for the same directory. */ if (sa.st_dev != sb.st_dev || sa.st_ino != sb.st_ino) atf_tc_fail("inconsistent stat(2)"); /* * Check that fts(3)'s stat(2) * call equals the manual one. */ if (sb.st_ino != ftse->fts_statp->st_ino) atf_tc_fail("stat(2) and fts(3) differ"); break; default: break; } } (void)fts_close(fts); } ATF_TC(stat_err); ATF_TC_HEAD(stat_err, tc) { atf_tc_set_md_var(tc, "descr", "Test errors from the stat(2) family"); } ATF_TC_BODY(stat_err, tc) { char buf[NAME_MAX + 1]; struct stat st; (void)memset(buf, 'x', sizeof(buf)); errno = 0; ATF_REQUIRE_ERRNO(EBADF, fstat(-1, &st) == -1); errno = 0; ATF_REQUIRE_ERRNO(ENAMETOOLONG, stat(buf, &st) == -1); errno = 0; ATF_REQUIRE_ERRNO(ENAMETOOLONG, lstat(buf, &st) == -1); errno = 0; ATF_REQUIRE_ERRNO(EFAULT, stat((void *)-1, &st) == -1); errno = 0; ATF_REQUIRE_ERRNO(EFAULT, lstat((void *)-1, &st) == -1); errno = 0; ATF_REQUIRE_ERRNO(EFAULT, stat("/etc/passwd", (void *)-1) == -1); errno = 0; ATF_REQUIRE_ERRNO(EFAULT, lstat("/etc/passwd", (void *)-1) == -1); errno = 0; ATF_REQUIRE_ERRNO(ENOENT, stat("/a/b/c/d/e/f/g/h/i/j/k", &st) == -1); errno = 0; ATF_REQUIRE_ERRNO(ENOENT, lstat("/a/b/c/d/e/f/g/h/i/j/k", &st) == -1); } ATF_TC_WITH_CLEANUP(stat_mtime); ATF_TC_HEAD(stat_mtime, tc) { atf_tc_set_md_var(tc, "descr", "Test modification times with stat(2)"); } ATF_TC_BODY(stat_mtime, tc) { struct stat sa, sb; int fd[3]; size_t i; for (i = 0; i < __arraycount(fd); i++) { (void)memset(&sa, 0, sizeof(struct stat)); (void)memset(&sb, 0, sizeof(struct stat)); fd[i] = open(path, O_WRONLY | O_CREAT); ATF_REQUIRE(fd[i] != -1); ATF_REQUIRE(write(fd[i], "X", 1) == 1); ATF_REQUIRE(stat(path, &sa) == 0); (void)sleep(1); ATF_REQUIRE(write(fd[i], "X", 1) == 1); ATF_REQUIRE(stat(path, &sb) == 0); ATF_REQUIRE(close(fd[i]) == 0); ATF_REQUIRE(unlink(path) == 0); if (sa.st_mtime == sb.st_mtime) atf_tc_fail("mtimes did not change"); } } ATF_TC_CLEANUP(stat_mtime, tc) { (void)unlink(path); } ATF_TC_WITH_CLEANUP(stat_perm); ATF_TC_HEAD(stat_perm, tc) { atf_tc_set_md_var(tc, "descr", "Test permissions with stat(2)"); atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(stat_perm, tc) { struct stat sa, sb; gid_t gid; uid_t uid; int fd; (void)memset(&sa, 0, sizeof(struct stat)); (void)memset(&sb, 0, sizeof(struct stat)); uid = getuid(); gid = getgid(); fd = open(path, O_RDONLY | O_CREAT); ATF_REQUIRE(fd != -1); ATF_REQUIRE(fstat(fd, &sa) == 0); ATF_REQUIRE(stat(path, &sb) == 0); if (gid != sa.st_gid || sa.st_gid != sb.st_gid) atf_tc_fail("invalid GID"); if (uid != sa.st_uid || sa.st_uid != sb.st_uid) atf_tc_fail("invalid UID"); ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(unlink(path) == 0); } ATF_TC_CLEANUP(stat_perm, tc) { (void)unlink(path); } ATF_TC_WITH_CLEANUP(stat_size); ATF_TC_HEAD(stat_size, tc) { atf_tc_set_md_var(tc, "descr", "Test file sizes with stat(2)"); } ATF_TC_BODY(stat_size, tc) { struct stat sa, sb, sc; const size_t n = 10; size_t i; int fd; fd = open(path, O_WRONLY | O_CREAT); ATF_REQUIRE(fd >= 0); for (i = 0; i < n; i++) { (void)memset(&sa, 0, sizeof(struct stat)); (void)memset(&sb, 0, sizeof(struct stat)); (void)memset(&sc, 0, sizeof(struct stat)); ATF_REQUIRE(fstat(fd, &sa) == 0); ATF_REQUIRE(write(fd, "X", 1) == 1); ATF_REQUIRE(fstat(fd, &sb) == 0); ATF_REQUIRE(stat(path, &sc) == 0); if (sa.st_size + 1 != sb.st_size) atf_tc_fail("invalid file size"); if (sb.st_size != sc.st_size) atf_tc_fail("stat(2) and fstat(2) mismatch"); } ATF_REQUIRE(close(fd) == 0); ATF_REQUIRE(unlink(path) == 0); } ATF_TC_CLEANUP(stat_size, tc) { (void)unlink(path); } ATF_TC(stat_socket); ATF_TC_HEAD(stat_socket, tc) { atf_tc_set_md_var(tc, "descr", "Test fstat(2) with " "a socket (PR kern/46077)"); } ATF_TC_BODY(stat_socket, tc) { struct sockaddr_in addr; struct stat st; uint32_t iaddr; int fd, flags; (void)memset(&st, 0, sizeof(struct stat)); (void)memset(&addr, 0, sizeof(struct sockaddr_in)); fd = socket(AF_INET, SOCK_STREAM, 0); ATF_REQUIRE(fd >= 0); flags = fcntl(fd, F_GETFL); ATF_REQUIRE(flags != -1); ATF_REQUIRE(fcntl(fd, F_SETFL, flags | O_NONBLOCK) != -1); ATF_REQUIRE(inet_pton(AF_INET, "127.0.0.1", &iaddr) == 1); addr.sin_port = htons(42); addr.sin_family = AF_INET; addr.sin_addr.s_addr = iaddr; errno = 0; ATF_REQUIRE_ERRNO(EINPROGRESS, connect(fd, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) == -1); errno = 0; if (fstat(fd, &st) != 0 || errno != 0) atf_tc_fail("fstat(2) failed for a EINPROGRESS socket"); (void)close(fd); } ATF_TC_WITH_CLEANUP(stat_symlink); ATF_TC_HEAD(stat_symlink, tc) { atf_tc_set_md_var(tc, "descr", "Test symbolic links with stat(2)"); } ATF_TC_BODY(stat_symlink, tc) { const char *pathlink = "pathlink"; struct stat sa, sb; int fd; (void)memset(&sa, 0, sizeof(struct stat)); (void)memset(&sb, 0, sizeof(struct stat)); fd = open(path, O_WRONLY | O_CREAT); ATF_REQUIRE(fd >= 0); ATF_REQUIRE(symlink(path, pathlink) == 0); ATF_REQUIRE(stat(pathlink, &sa) == 0); ATF_REQUIRE(lstat(pathlink, &sb) == 0); if (S_ISLNK(sa.st_mode) != 0) atf_tc_fail("stat(2) detected symbolic link"); if (S_ISLNK(sb.st_mode) == 0) atf_tc_fail("lstat(2) did not detect symbolic link"); if (sa.st_mode == sb.st_mode) atf_tc_fail("inconsistencies between stat(2) and lstat(2)"); (void)close(fd); ATF_REQUIRE(unlink(path) == 0); ATF_REQUIRE(unlink(pathlink) == 0); -#ifdef __FreeBSD__ - (void)close(fd); -#endif } ATF_TC_CLEANUP(stat_symlink, tc) { (void)unlink(path); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, stat_chflags); ATF_TP_ADD_TC(tp, stat_dir); ATF_TP_ADD_TC(tp, stat_err); ATF_TP_ADD_TC(tp, stat_mtime); ATF_TP_ADD_TC(tp, stat_perm); ATF_TP_ADD_TC(tp, stat_size); ATF_TP_ADD_TC(tp, stat_socket); ATF_TP_ADD_TC(tp, stat_symlink); return atf_no_error(); } Index: projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_truncate.c =================================================================== --- projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_truncate.c (revision 312148) +++ projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/sys/t_truncate.c (revision 312149) @@ -1,183 +1,179 @@ /* $NetBSD: t_truncate.c,v 1.3 2017/01/13 20:03:51 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Jukka Ruohonen. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include __RCSID("$NetBSD: t_truncate.c,v 1.3 2017/01/13 20:03:51 christos Exp $"); #include #include #include #include #include #include #include #include -#ifdef __FreeBSD__ -#include -#endif - static const char path[] = "truncate"; static const size_t sizes[] = { 8, 16, 512, 1024, 2048, 4094, 3000, 30 }; ATF_TC_WITH_CLEANUP(ftruncate_basic); ATF_TC_HEAD(ftruncate_basic, tc) { atf_tc_set_md_var(tc, "descr", "A basic test of ftruncate(2)"); } ATF_TC_BODY(ftruncate_basic, tc) { struct stat st; size_t i; int fd; fd = open(path, O_RDWR | O_CREAT, 0600); ATF_REQUIRE(fd >= 0); for (i = 0; i < __arraycount(sizes); i++) { (void)memset(&st, 0, sizeof(struct stat)); ATF_REQUIRE(ftruncate(fd, sizes[i]) == 0); ATF_REQUIRE(fstat(fd, &st) == 0); (void)fprintf(stderr, "truncating to %zu bytes\n", sizes[i]); if (sizes[i] != (size_t)st.st_size) atf_tc_fail("ftruncate(2) did not truncate"); } (void)close(fd); (void)unlink(path); } ATF_TC_CLEANUP(ftruncate_basic, tc) { (void)unlink(path); } ATF_TC(ftruncate_err); ATF_TC_HEAD(ftruncate_err, tc) { atf_tc_set_md_var(tc, "descr", "Test errors from ftruncate(2)"); atf_tc_set_md_var(tc, "require.user", "unprivileged"); } ATF_TC_BODY(ftruncate_err, tc) { int fd; fd = open("/etc/passwd", O_RDONLY, 0400); ATF_REQUIRE(fd >= 0); errno = 0; ATF_REQUIRE_ERRNO(EBADF, ftruncate(-1, 999) == -1); errno = 0; ATF_REQUIRE_ERRNO(EINVAL, ftruncate(fd, 999) == -1); (void)close(fd); } ATF_TC_WITH_CLEANUP(truncate_basic); ATF_TC_HEAD(truncate_basic, tc) { atf_tc_set_md_var(tc, "descr", "A basic test of truncate(2)"); } ATF_TC_BODY(truncate_basic, tc) { struct stat st; size_t i; int fd; fd = open(path, O_RDWR | O_CREAT, 0600); ATF_REQUIRE(fd >= 0); for (i = 0; i < __arraycount(sizes); i++) { (void)memset(&st, 0, sizeof(struct stat)); ATF_REQUIRE(truncate(path, sizes[i]) == 0); ATF_REQUIRE(fstat(fd, &st) == 0); (void)fprintf(stderr, "truncating to %zu bytes\n", sizes[i]); if (sizes[i] != (size_t)st.st_size) atf_tc_fail("truncate(2) did not truncate"); } (void)close(fd); (void)unlink(path); } ATF_TC_CLEANUP(truncate_basic, tc) { (void)unlink(path); } ATF_TC(truncate_err); ATF_TC_HEAD(truncate_err, tc) { atf_tc_set_md_var(tc, "descr", "Test errors from truncate(2)"); atf_tc_set_md_var(tc, "require.user", "unprivileged"); } ATF_TC_BODY(truncate_err, tc) { char buf[PATH_MAX]; errno = 0; ATF_REQUIRE_ERRNO(EFAULT, truncate((void *)-1, 999) == -1); errno = 0; ATF_REQUIRE_ERRNO(EISDIR, truncate("/etc", 999) == -1); errno = 0; ATF_REQUIRE_ERRNO(ENOENT, truncate("/a/b/c/d/e/f/g", 999) == -1); errno = 0; snprintf(buf, sizeof(buf), "%s/truncate_test.root_owned", atf_tc_get_config_var(tc, "srcdir")); ATF_REQUIRE_ERRNO(EACCES, truncate(buf, 999) == -1); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, ftruncate_basic); ATF_TP_ADD_TC(tp, ftruncate_err); ATF_TP_ADD_TC(tp, truncate_basic); ATF_TP_ADD_TC(tp, truncate_err); return atf_no_error(); }