From owner-svn-src-stable@freebsd.org Wed May 31 08:36:45 2017 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 12079AFA4B0; Wed, 31 May 2017 08:36:45 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E0B046E69A; Wed, 31 May 2017 08:36:44 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v4V8ai9E019037; Wed, 31 May 2017 08:36:44 GMT (envelope-from ngie@FreeBSD.org) Received: (from ngie@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v4V8ahYW019033; Wed, 31 May 2017 08:36:43 GMT (envelope-from ngie@FreeBSD.org) Message-Id: <201705310836.v4V8ahYW019033@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ngie set sender to ngie@FreeBSD.org using -f From: Ngie Cooper Date: Wed, 31 May 2017 08:36:43 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r319300 - stable/11/tests/sys/file X-SVN-Group: stable-11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 31 May 2017 08:36:45 -0000 Author: ngie Date: Wed May 31 08:36:43 2017 New Revision: 319300 URL: https://svnweb.freebsd.org/changeset/base/319300 Log: MFC r319056,r319058,r319059,r319060,r319061,r319078: r319056: tests/sys/file/ftruncate_test: use an exit code of 1 instead of -1 with err*(3). An exit code of -1 is implementation defined -- it's best to stick with something well-defined (1). r319058: Create a deterministic file in the kyua sandbox, instead of a temporary file outside the kyua sandbox This helps ensure that the file is removed at test exit, and as a side effect, cures a warning about umasks with Coverity. r319059: Use an exit code of 1 instead of -1 for reasons noted in r319056 r319060: Use main(void) instead of main(argc __unused, argv __unused) r319061: Don't leak accept_fd on thread completion CID: 1296068 r319078: Tweak r319058 slightly - Specify an explicit mode when using O_CREAT per open(2). - Fix the error message (add missing enclosing parentheses). MFC with: r319058 Modified: stable/11/tests/sys/file/ftruncate_test.c stable/11/tests/sys/file/newfileops_on_fork_test.c Directory Properties: stable/11/ (props changed) Modified: stable/11/tests/sys/file/ftruncate_test.c ============================================================================== --- stable/11/tests/sys/file/ftruncate_test.c Wed May 31 08:32:05 2017 (r319299) +++ stable/11/tests/sys/file/ftruncate_test.c Wed May 31 08:36:43 2017 (r319300) @@ -60,14 +60,14 @@ int main(void) { int error, fd, fds[2], i, read_only_fd; - char path[PATH_MAX]; + char path[] = "ftruncate_file"; struct stat sb; ssize_t size; off_t len; char ch; /* - * Tests using a writable temporary file: grow and then shrink a file + * Tests using a writable file: grow and then shrink a file * using ftruncate and various lengths. Make sure that a negative * file length is rejected. Make sure that when we grow the file, * bytes now in the range of the file size return 0. @@ -75,37 +75,36 @@ main(void) * Save a read-only reference to the file to use later for read-only * descriptor tests. */ - snprintf(path, PATH_MAX, "/tmp/ftruncate.XXXXXXXXXXXXX"); - fd = mkstemp(path); + fd = open(path, O_RDWR|O_CREAT, 0600); if (fd < 0) - err(-1, "mkstemp"); + err(1, "open(%s, O_RDWR|O_CREAT, 0600)", path); read_only_fd = open(path, O_RDONLY); if (read_only_fd < 0) { error = errno; (void)unlink(path); errno = error; - err(-1, "open(%s, O_RDONLY)", path); + err(1, "open(%s, O_RDONLY)", path); } (void)unlink(path); if (ftruncate(fd, -1) == 0) - errx(-1, "ftruncate(fd, -1) succeeded"); + errx(1, "ftruncate(fd, -1) succeeded unexpectedly"); if (errno != EINVAL) - err(-1, "ftruncate(fd, -1) returned wrong error"); + err(1, "ftruncate(fd, -1) returned wrong error"); for (i = 0; i < lengths_count; i++) { len = lengths[i]; if (ftruncate(fd, len) < 0) - err(-1, "ftruncate(%jd) up", (intmax_t)len); + err(1, "ftruncate(%jd) up", (intmax_t)len); if (fstat(fd, &sb) < 0) - err(-1, "stat"); + err(1, "stat"); if (sb.st_size != len) errx(-1, "fstat with len=%jd returned len %jd up", (intmax_t)len, (intmax_t)sb.st_size); if (len != 0) { size = pread(fd, &ch, sizeof(ch), len - 1); if (size < 0) - err(-1, "pread on len %jd up", (intmax_t)len); + err(1, "pread on len %jd up", (intmax_t)len); if (size != sizeof(ch)) errx(-1, "pread len %jd size %jd up", (intmax_t)len, (intmax_t)size); @@ -119,9 +118,9 @@ main(void) for (i = lengths_count - 1; i >= 0; i--) { len = lengths[i]; if (ftruncate(fd, len) < 0) - err(-1, "ftruncate(%jd) down", (intmax_t)len); + err(1, "ftruncate(%jd) down", (intmax_t)len); if (fstat(fd, &sb) < 0) - err(-1, "stat"); + err(1, "stat"); if (sb.st_size != len) errx(-1, "fstat(%jd) returned %jd down", (intmax_t)len, sb.st_size); @@ -134,7 +133,7 @@ main(void) if (ftruncate(read_only_fd, 0) == 0) errx(-1, "ftruncate(read_only_fd) succeeded"); if (errno != EINVAL) - err(-1, "ftruncate(read_only_fd) returned wrong error"); + err(1, "ftruncate(read_only_fd) returned wrong error"); close(read_only_fd); /* @@ -142,22 +141,22 @@ main(void) */ fd = socket(PF_UNIX, SOCK_STREAM, 0); if (fd < 0) - err(-1, "socket(PF_UNIX, SOCK_STREAM, 0)"); + err(1, "socket(PF_UNIX, SOCK_STREAM, 0)"); if (ftruncate(fd, 0) == 0) errx(-1, "ftruncate(socket) succeeded"); if (errno != EINVAL) - err(-1, "ftruncate(socket) returned wrong error"); + err(1, "ftruncate(socket) returned wrong error"); close(fd); /* * Make sure that ftruncate on pipes doesn't work. */ if (pipe(fds) < 0) - err(-1, "pipe"); + err(1, "pipe"); if (ftruncate(fds[0], 0) == 0) errx(-1, "ftruncate(pipe) succeeded"); if (errno != EINVAL) - err(-1, "ftruncate(pipe) returned wrong error"); + err(1, "ftruncate(pipe) returned wrong error"); close(fds[0]); close(fds[1]); @@ -166,11 +165,11 @@ main(void) */ fd = kqueue(); if (fd < 0) - err(-1, "kqueue"); + err(1, "kqueue"); if (ftruncate(fds[0], 0) == 0) errx(-1, "ftruncate(kqueue) succeeded"); if (errno != EINVAL) - err(-1, "ftruncate(kqueue) returned wrong error"); + err(1, "ftruncate(kqueue) returned wrong error"); close(fd); return (0); Modified: stable/11/tests/sys/file/newfileops_on_fork_test.c ============================================================================== --- stable/11/tests/sys/file/newfileops_on_fork_test.c Wed May 31 08:32:05 2017 (r319299) +++ stable/11/tests/sys/file/newfileops_on_fork_test.c Wed May 31 08:36:43 2017 (r319300) @@ -61,8 +61,9 @@ do_accept(__unused void *arg) accept_fd = accept(listen_fd, NULL, NULL); if (accept_fd < 0) - err(-1, "accept"); + err(1, "accept"); + close(accept_fd); return (NULL); } @@ -73,7 +74,7 @@ do_fork(void) pid = fork(); if (pid < 0) - err(-1, "fork"); + err(1, "fork"); if (pid > 0) { waitpid(pid, NULL, 0); exit(0); @@ -84,37 +85,37 @@ do_fork(void) * listen_fd+1, and get back EBADF if it's not a valid descriptor, * and EINVAL if it is. This (currently) works fine in practice. */ - if (ftruncate(listen_fd + 1, 0 < 0)) { + if (ftruncate(listen_fd + 1, 0) < 0) { if (errno == EBADF) exit(0); else if (errno == EINVAL) - errx(-1, "file descriptor still open in child"); + errx(1, "file descriptor still open in child"); else - err(-1, "unexpected error"); + err(1, "unexpected error"); } else - errx(-1, "ftruncate succeeded"); + errx(1, "ftruncate succeeded"); } int -main(__unused int argc, __unused char *argv[]) +main(void) { struct sockaddr_in sin; pthread_t accept_thread; listen_fd = socket(PF_INET, SOCK_STREAM, 0); if (listen_fd < 0) - err(-1, "socket"); + err(1, "socket"); bzero(&sin, sizeof(sin)); sin.sin_family = AF_INET; sin.sin_len = sizeof(sin); sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); sin.sin_port = htons(PORT); if (bind(listen_fd, (struct sockaddr *)&sin, sizeof(sin)) < 0) - err(-1, "bind"); + err(1, "bind"); if (listen(listen_fd, -1) <0) - err(-1, "listen"); + err(1, "listen"); if (pthread_create(&accept_thread, NULL, do_accept, NULL) != 0) - err(-1, "pthread_create"); + err(1, "pthread_create"); sleep(1); /* Easier than using a CV. */ do_fork(); exit(0);