From f2f170ddd8d54aa95c75879e4e329feaf19ef119 Mon Sep 17 00:00:00 2001 From: ngie Date: Tue, 1 Dec 2015 18:19:23 +0000 Subject: MFC r285140: r285140 (by oshogbo): Add fdclose(3) function. This function is equivalent to fclose(3) function except that it does not close the underlying file descriptor. fdclose(3) is step forward to make FILE structure private. Reviewed by: wblock, jilles, jhb, pjd Approved by: pjd (mentor) Differential Revision: https://reviews.freebsd.org/D2697 --- include/stdio.h | 1 + lib/libc/stdio/Symbol.map | 4 +++ lib/libc/stdio/fclose.3 | 82 ++++++++++++++++++++++++++++++++++++++--------- lib/libc/stdio/fclose.c | 75 ++++++++++++++++++++++++++++++++++++------- 4 files changed, 135 insertions(+), 27 deletions(-) diff --git a/include/stdio.h b/include/stdio.h index d37ea06..5d3e5a2 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -399,6 +399,7 @@ int (dprintf)(int, const char * __restrict, ...); int asprintf(char **, const char *, ...) __printflike(2, 3); char *ctermid_r(char *); void fcloseall(void); +int fdclose(FILE *, int *); char *fgetln(FILE *, size_t *); const char *fmtcheck(const char *, const char *) __format_arg(2); int fpurge(FILE *); diff --git a/lib/libc/stdio/Symbol.map b/lib/libc/stdio/Symbol.map index d2a8c92..a332ab2 100644 --- a/lib/libc/stdio/Symbol.map +++ b/lib/libc/stdio/Symbol.map @@ -162,6 +162,10 @@ FBSD_1.3 { mkostemps; }; +FBSD_1.4 { + fdclose; +}; + FBSDprivate_1.0 { _flockfile; _flockfile_debug_stub; diff --git a/lib/libc/stdio/fclose.3 b/lib/libc/stdio/fclose.3 index 883aa10..596ee3d 100644 --- a/lib/libc/stdio/fclose.3 +++ b/lib/libc/stdio/fclose.3 @@ -1,5 +1,6 @@ -.\" Copyright (c) 1990, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. +.\" Copyright (c) 1990, 1991, 1993 The Regents of the University of California. +.\" Copyright (c) 2015 Mariusz Zaborski +.\" All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by .\" Chris Torek and the American National Standards Committee X3, @@ -32,11 +33,12 @@ .\" @(#)fclose.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd April 22, 2006 +.Dd July 4, 2015 .Dt FCLOSE 3 .Os .Sh NAME .Nm fclose , +.Nm fdclose , .Nm fcloseall .Nd close a stream .Sh LIBRARY @@ -45,6 +47,8 @@ .In stdio.h .Ft int .Fn fclose "FILE *stream" +.Ft int +.Fn fdclose "FILE *stream" "int *fdp" .Ft void .Fn fcloseall void .Sh DESCRIPTION @@ -59,36 +63,77 @@ first, using .Xr fflush 3 . .Pp The +.Fn fdclose +function is equivalent to +.Fn fclose +except that it does not close the underlying file descriptor. +If +.Fa fdp +is not +.Dv NULL , +the file descriptor will be written to it. +If the +.Fa fdp +argument will be different then NULL the file descriptor will be returned in it, +If the stream does not have an associated file descriptor, +.Fa fdp +will be set to -1. +This type of stream is created with functions such as +.Xr fmemopen 3 , +.Xr funopen 3 , +or +.Xr open_memstream 3 . +.Pp +The .Fn fcloseall function calls .Fn fclose on all open streams. .Sh RETURN VALUES -Upon successful completion 0 is returned. +.Fn fcloseall +does not return a value. +.Pp +Upon successful completion the +.Fn fclose +and +.Fn fdclose +functions return 0. Otherwise, .Dv EOF is returned and the global variable .Va errno is set to indicate the error. -In either case no further access to the stream is possible. .Sh ERRORS +.Fn fdclose +fails if: +.Bl -tag -width Er +.It Bq Er EOPNOTSUPP +The stream does not have an associated file descriptor. +.El +.Pp The .Fn fclose -function -may also fail and set +and +.Fn fdclose +functions may also fail and set .Va errno -for any of the errors specified for the routines -.Xr close 2 -or +for any of the errors specified for .Xr fflush 3 . +.Pp +The +.Fn fclose +function may also fail and set errno for any of the errors specified for +.Xr close 2 . .Sh NOTES The .Fn fclose -function -does not handle NULL arguments; they will result in a segmentation -violation. -This is intentional - it makes it easier to make sure programs written -under +and +.Fn fdclose +functions do not handle NULL arguments in the +.Fa stream +variable; this will result in a segmentation violation. +This is intentional. +It makes it easier to make sure programs written under .Fx are bug free. This behaviour is an implementation detail, and programs should not @@ -104,8 +149,13 @@ The function conforms to .St -isoC . -.Pp +.Sh HISTORY The .Fn fcloseall function first appeared in .Fx 7.0 . +.Pp +The +.Fn fdclose +function first appeared in +.Fx 11.0 . diff --git a/lib/libc/stdio/fclose.c b/lib/libc/stdio/fclose.c index 5ed8b2c..24b9b90 100644 --- a/lib/libc/stdio/fclose.c +++ b/lib/libc/stdio/fclose.c @@ -1,6 +1,7 @@ /*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. + * Copyright (c) 1990, 1993 The Regents of the University of California. + * Copyright (c) 2013 Mariusz Zaborski + * All rights reserved. * * This code is derived from software contributed to Berkeley by * Chris Torek. @@ -38,6 +39,7 @@ __FBSDID("$FreeBSD$"); #include "namespace.h" #include +#include #include #include #include "un-namespace.h" @@ -45,19 +47,17 @@ __FBSDID("$FreeBSD$"); #include "libc_private.h" #include "local.h" -int -fclose(FILE *fp) +static int +cleanfile(FILE *fp, bool c) { int r; - if (fp->_flags == 0) { /* not open! */ - errno = EBADF; - return (EOF); - } - FLOCKFILE(fp); r = fp->_flags & __SWR ? __sflush(fp) : 0; - if (fp->_close != NULL && (*fp->_close)(fp->_cookie) < 0) - r = EOF; + if (c) { + if (fp->_close != NULL && (*fp->_close)(fp->_cookie) < 0) + r = EOF; + } + if (fp->_flags & __SMBF) free((char *)fp->_bf._base); if (HASUB(fp)) @@ -80,6 +80,59 @@ fclose(FILE *fp) STDIO_THREAD_LOCK(); fp->_flags = 0; /* Release this FILE for reuse. */ STDIO_THREAD_UNLOCK(); + + return (r); +} + +int +fdclose(FILE *fp, int *fdp) +{ + int r, err; + + if (fdp != NULL) + *fdp = -1; + + if (fp->_flags == 0) { /* not open! */ + errno = EBADF; + return (EOF); + } + + FLOCKFILE(fp); + r = 0; + if (fp->_close != __sclose) { + r = EOF; + errno = EOPNOTSUPP; + } else if (fp->_file < 0) { + r = EOF; + errno = EBADF; + } + if (r == EOF) { + err = errno; + (void)cleanfile(fp, true); + errno = err; + } else { + if (fdp != NULL) + *fdp = fp->_file; + r = cleanfile(fp, false); + } FUNLOCKFILE(fp); + + return (r); +} + +int +fclose(FILE *fp) +{ + int r; + + if (fp->_flags == 0) { /* not open! */ + errno = EBADF; + return (EOF); + } + + FLOCKFILE(fp); + r = cleanfile(fp, true); + FUNLOCKFILE(fp); + return (r); } -- cgit v1.1 From 394e9d5dd4fefbd49ddc3ed8a0eafe21d7581e27 Mon Sep 17 00:00:00 2001 From: ngie Date: Tue, 1 Dec 2015 18:21:25 +0000 Subject: MFC r285118: r285118 (by jmmv): Add missing shebang Plain test programs are not preprocessed by the build system (as opposed to ATF test cases, which automatically gain a shebang pointing at atf-sh), so we must take care of providing the shebang ourselves. I'm not sure why this was not causing problems with Kyua 0.11, but the upcoming 0.12 release chokes on this particular issue. --- share/examples/tests/tests/plain/cp_test.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/share/examples/tests/tests/plain/cp_test.sh b/share/examples/tests/tests/plain/cp_test.sh index ea64705..c45d684 100644 --- a/share/examples/tests/tests/plain/cp_test.sh +++ b/share/examples/tests/tests/plain/cp_test.sh @@ -1,3 +1,4 @@ +#! /bin/sh # $FreeBSD$ # # Copyright 2013 Google Inc. -- cgit v1.1 From 90fda359a485dc948c06d33f261406352083d898 Mon Sep 17 00:00:00 2001 From: ngie Date: Tue, 1 Dec 2015 18:27:38 +0000 Subject: MFC r269902,r270101: r269902: Convert bin/sh/tests to ATF The new code uses a "test discovery mechanism" to determine what tests are available for execution The test shell can be specified via: kyua test -v test_suites.FreeBSD.bin.sh.test_shell=/path/to/test/sh Sponsored by: EMC / Isilon Storage Division Approved by: jmmv (mentor) Reviewed by: jilles (maintainer) r270101 (by jilles): sh: Don't hardcode relative paths in the tests stderr files. These paths have had to be adjusted to changes in the testsuite runner several times, so modify the tests to remove the need for such adjustment. A cp in functional_test.sh is now unneeded, but this matters little in performance. --- bin/sh/tests/Makefile | 17 +++---- bin/sh/tests/builtins/Makefile | 8 +++- bin/sh/tests/errors/Makefile | 8 ++-- bin/sh/tests/errors/bad-parm-exp2.2 | 2 +- bin/sh/tests/errors/bad-parm-exp2.2.stderr | 2 +- bin/sh/tests/errors/bad-parm-exp3.2 | 2 +- bin/sh/tests/errors/bad-parm-exp3.2.stderr | 2 +- bin/sh/tests/errors/bad-parm-exp4.2 | 2 +- bin/sh/tests/errors/bad-parm-exp4.2.stderr | 2 +- bin/sh/tests/errors/bad-parm-exp5.2 | 2 +- bin/sh/tests/errors/bad-parm-exp5.2.stderr | 2 +- bin/sh/tests/errors/bad-parm-exp6.2 | 2 +- bin/sh/tests/errors/bad-parm-exp6.2.stderr | 2 +- bin/sh/tests/execution/Makefile | 8 ++-- bin/sh/tests/expansion/Makefile | 8 ++-- bin/sh/tests/functional_test.sh | 72 ++++++++++++++++++++++++++++++ bin/sh/tests/legacy_test.sh | 46 ------------------- bin/sh/tests/parameters/Makefile | 8 ++-- bin/sh/tests/parser/Makefile | 8 ++-- bin/sh/tests/set-e/Makefile | 8 ++-- tools/build/mk/OptionalObsoleteFiles.inc | 1 + 21 files changed, 126 insertions(+), 86 deletions(-) create mode 100755 bin/sh/tests/functional_test.sh delete mode 100644 bin/sh/tests/legacy_test.sh diff --git a/bin/sh/tests/Makefile b/bin/sh/tests/Makefile index 51c6dc4..c092962 100644 --- a/bin/sh/tests/Makefile +++ b/bin/sh/tests/Makefile @@ -4,15 +4,12 @@ TESTSDIR= ${TESTSBASE}/bin/sh -TAP_TESTS_SH= legacy_test -TAP_TESTS_SH_SED_legacy_test= -e 's,__SH__,/bin/sh,g' -# Some tests in here are silently not run when the tests are executed as -# root. Explicitly tell Kyua to drop privileges. -# -# TODO(jmmv): Kyua needs to do this by default, not only when explicitly -# requested. See https://code.google.com/p/kyua/issues/detail?id=6 -TEST_METADATA.legacy_test+= required_user="unprivileged" - -SUBDIR+= builtins errors execution expansion parameters parser set-e +TESTS_SUBDIRS+= builtins +TESTS_SUBDIRS+= errors +TESTS_SUBDIRS+= execution +TESTS_SUBDIRS+= expansion +TESTS_SUBDIRS+= parameters +TESTS_SUBDIRS+= parser +TESTS_SUBDIRS+= set-e .include diff --git a/bin/sh/tests/builtins/Makefile b/bin/sh/tests/builtins/Makefile index ec4cab6..527c1b3 100644 --- a/bin/sh/tests/builtins/Makefile +++ b/bin/sh/tests/builtins/Makefile @@ -2,8 +2,12 @@ .include -FILESDIR= ${TESTSBASE}/bin/sh/builtins -KYUAFILE= no +TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T} + +.PATH: ${.CURDIR:H} +ATF_TESTS_SH= functional_test + +FILESDIR= ${TESTSDIR} FILES= alias.0 alias.0.stdout FILES+= alias.1 alias.1.stderr diff --git a/bin/sh/tests/errors/Makefile b/bin/sh/tests/errors/Makefile index ab04f14..51a766f 100644 --- a/bin/sh/tests/errors/Makefile +++ b/bin/sh/tests/errors/Makefile @@ -1,9 +1,11 @@ # $FreeBSD$ -.include +TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T} -FILESDIR= ${TESTSBASE}/bin/sh/errors -KYUAFILE= no +.PATH: ${.CURDIR:H} +ATF_TESTS_SH= functional_test + +FILESDIR= ${TESTSDIR} FILES= assignment-error1.0 FILES+= assignment-error2.0 diff --git a/bin/sh/tests/errors/bad-parm-exp2.2 b/bin/sh/tests/errors/bad-parm-exp2.2 index 7e13d2b..a0826ec 100644 --- a/bin/sh/tests/errors/bad-parm-exp2.2 +++ b/bin/sh/tests/errors/bad-parm-exp2.2 @@ -1,2 +1,2 @@ # $FreeBSD$ -${} +eval '${}' diff --git a/bin/sh/tests/errors/bad-parm-exp2.2.stderr b/bin/sh/tests/errors/bad-parm-exp2.2.stderr index d027a5a..51ea69c 100644 --- a/bin/sh/tests/errors/bad-parm-exp2.2.stderr +++ b/bin/sh/tests/errors/bad-parm-exp2.2.stderr @@ -1 +1 @@ -./errors/bad-parm-exp2.2: ${}: Bad substitution +eval: ${}: Bad substitution diff --git a/bin/sh/tests/errors/bad-parm-exp3.2 b/bin/sh/tests/errors/bad-parm-exp3.2 index a5ecba5..bb41208 100644 --- a/bin/sh/tests/errors/bad-parm-exp3.2 +++ b/bin/sh/tests/errors/bad-parm-exp3.2 @@ -1,2 +1,2 @@ # $FreeBSD$ -${foo/} +eval '${foo/}' diff --git a/bin/sh/tests/errors/bad-parm-exp3.2.stderr b/bin/sh/tests/errors/bad-parm-exp3.2.stderr index ef40251..70473f9 100644 --- a/bin/sh/tests/errors/bad-parm-exp3.2.stderr +++ b/bin/sh/tests/errors/bad-parm-exp3.2.stderr @@ -1 +1 @@ -./errors/bad-parm-exp3.2: ${foo/}: Bad substitution +eval: ${foo/}: Bad substitution diff --git a/bin/sh/tests/errors/bad-parm-exp4.2 b/bin/sh/tests/errors/bad-parm-exp4.2 index 9eec8d0..2837f9b 100644 --- a/bin/sh/tests/errors/bad-parm-exp4.2 +++ b/bin/sh/tests/errors/bad-parm-exp4.2 @@ -1,2 +1,2 @@ # $FreeBSD$ -${foo:@abc} +eval '${foo:@abc}' diff --git a/bin/sh/tests/errors/bad-parm-exp4.2.stderr b/bin/sh/tests/errors/bad-parm-exp4.2.stderr index 89bd80f..3363f51 100644 --- a/bin/sh/tests/errors/bad-parm-exp4.2.stderr +++ b/bin/sh/tests/errors/bad-parm-exp4.2.stderr @@ -1 +1 @@ -./errors/bad-parm-exp4.2: ${foo:@...}: Bad substitution +eval: ${foo:@...}: Bad substitution diff --git a/bin/sh/tests/errors/bad-parm-exp5.2 b/bin/sh/tests/errors/bad-parm-exp5.2 index 459281f..1ba343b 100644 --- a/bin/sh/tests/errors/bad-parm-exp5.2 +++ b/bin/sh/tests/errors/bad-parm-exp5.2 @@ -1,2 +1,2 @@ # $FreeBSD$ -${/} +eval '${/}' diff --git a/bin/sh/tests/errors/bad-parm-exp5.2.stderr b/bin/sh/tests/errors/bad-parm-exp5.2.stderr index 89b1997..13763f8 100644 --- a/bin/sh/tests/errors/bad-parm-exp5.2.stderr +++ b/bin/sh/tests/errors/bad-parm-exp5.2.stderr @@ -1 +1 @@ -./errors/bad-parm-exp5.2: ${/}: Bad substitution +eval: ${/}: Bad substitution diff --git a/bin/sh/tests/errors/bad-parm-exp6.2 b/bin/sh/tests/errors/bad-parm-exp6.2 index ba51442..b53a91b 100644 --- a/bin/sh/tests/errors/bad-parm-exp6.2 +++ b/bin/sh/tests/errors/bad-parm-exp6.2 @@ -1,2 +1,2 @@ # $FreeBSD$ -${#foo^} +eval '${#foo^}' diff --git a/bin/sh/tests/errors/bad-parm-exp6.2.stderr b/bin/sh/tests/errors/bad-parm-exp6.2.stderr index dbf14b5..cc56f65 100644 --- a/bin/sh/tests/errors/bad-parm-exp6.2.stderr +++ b/bin/sh/tests/errors/bad-parm-exp6.2.stderr @@ -1 +1 @@ -./errors/bad-parm-exp6.2: ${foo...}: Bad substitution +eval: ${foo...}: Bad substitution diff --git a/bin/sh/tests/execution/Makefile b/bin/sh/tests/execution/Makefile index 302d0d8..2653d5f 100644 --- a/bin/sh/tests/execution/Makefile +++ b/bin/sh/tests/execution/Makefile @@ -1,9 +1,11 @@ # $FreeBSD$ -.include +TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T} -FILESDIR= ${TESTSBASE}/bin/sh/execution -KYUAFILE= no +.PATH: ${.CURDIR:H} +ATF_TESTS_SH= functional_test + +FILESDIR= ${TESTSDIR} FILES= bg1.0 FILES+= bg2.0 diff --git a/bin/sh/tests/expansion/Makefile b/bin/sh/tests/expansion/Makefile index e62fea4..d6f3c1a 100644 --- a/bin/sh/tests/expansion/Makefile +++ b/bin/sh/tests/expansion/Makefile @@ -1,9 +1,11 @@ # $FreeBSD$ -.include +TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T} -FILESDIR= ${TESTSBASE}/bin/sh/expansion -KYUAFILE= no +.PATH: ${.CURDIR:H} +ATF_TESTS_SH= functional_test + +FILESDIR= ${TESTSDIR} FILES= arith1.0 FILES+= arith2.0 diff --git a/bin/sh/tests/functional_test.sh b/bin/sh/tests/functional_test.sh new file mode 100755 index 0000000..6980538 --- /dev/null +++ b/bin/sh/tests/functional_test.sh @@ -0,0 +1,72 @@ +# +# Copyright 2014 EMC Corp. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * 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 COPYRIGHT HOLDERS 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 COPYRIGHT +# OWNER 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. +# +# $FreeBSD$ + +SRCDIR=$(atf_get_srcdir) + +check() +{ + local tc=${1}; shift + + export SH=$(atf_config_get bin.sh.test_shell /bin/sh) + + local err_file="${SRCDIR}/${tc}.stderr" + [ -f "${err_file}" ] && err_flag="-e file:${err_file}" + local out_file="${SRCDIR}/${tc}.stdout" + [ -f "${out_file}" ] && out_flag="-o file:${out_file}" + + atf_check -s exit:${tc##*.} ${err_flag} ${out_flag} ${SH} "${SRCDIR}/${tc}" +} + +add_testcase() +{ + local tc=${1} + local tc_escaped word + + case "${tc%.*}" in + *-*) + local IFS="-" + for word in ${tc%.*}; do + tc_escaped="${tc_escaped:+${tc_escaped}_}${word}" + done + ;; + *) + tc_escaped=${tc%.*} + ;; + esac + + atf_test_case ${tc_escaped} + eval "${tc_escaped}_body() { check ${tc}; }" + atf_add_test_case ${tc_escaped} +} + +atf_init_test_cases() +{ + for path in $(find -Es "${SRCDIR}" -regex '.*\.[0-9]+$'); do + add_testcase ${path##*/} + done +} diff --git a/bin/sh/tests/legacy_test.sh b/bin/sh/tests/legacy_test.sh deleted file mode 100644 index d43f5dd..0000000 --- a/bin/sh/tests/legacy_test.sh +++ /dev/null @@ -1,46 +0,0 @@ -# $FreeBSD$ - -: ${SH:="__SH__"} -export SH - -# TODO(jmmv): The Kyua TAP interface should be passing us the value of -# "srcdir" as an environment variable, just as it does with the ATF -# interface in the form of a configuration variable. For now, just try -# to guess this. -: ${TESTS_DATA:=$(dirname ${0})} - -COUNTER=1 - -do_test() { - c=${COUNTER} - COUNTER=$((COUNTER+1)) - ${SH} $1 > tmp.stdout 2> tmp.stderr - if [ $? -ne $2 ]; then - echo "not ok ${c} - ${1} # wrong exit status" - rm tmp.stdout tmp.stderr - return - fi - sed -I '' -e "s|^${TESTS_DATA}|.|" tmp.stderr - for i in stdout stderr; do - if [ -f ${1}.${i} ]; then - if ! cmp -s tmp.${i} ${1}.${i}; then - echo "not ok ${c} - ${1} # wrong output on ${i}" - rm tmp.stdout tmp.stderr - return - fi - elif [ -s tmp.${i} ]; then - echo "not ok ${c} - ${1} # wrong output on ${i}" - rm tmp.stdout tmp.stderr - return - fi - done - echo "ok ${c} - ${1}" - rm tmp.stdout tmp.stderr -} - -TESTS=$(find -Es ${TESTS_DATA} -regex ".*\.[0-9]+") -printf "1..%d\n" $(echo ${TESTS} | wc -w) - -for i in ${TESTS} ; do - do_test ${i} ${i##*.} -done diff --git a/bin/sh/tests/parameters/Makefile b/bin/sh/tests/parameters/Makefile index e31b78f..aa1462f 100644 --- a/bin/sh/tests/parameters/Makefile +++ b/bin/sh/tests/parameters/Makefile @@ -1,9 +1,11 @@ # $FreeBSD$ -.include +TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T} -FILESDIR= ${TESTSBASE}/bin/sh/parameters -KYUAFILE= no +.PATH: ${.CURDIR:H} +ATF_TESTS_SH= functional_test + +FILESDIR= ${TESTSDIR} FILES= env1.0 FILES+= exitstatus1.0 diff --git a/bin/sh/tests/parser/Makefile b/bin/sh/tests/parser/Makefile index b769a30..63f4e8f 100644 --- a/bin/sh/tests/parser/Makefile +++ b/bin/sh/tests/parser/Makefile @@ -1,9 +1,11 @@ # $FreeBSD$ -.include +TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T} -FILESDIR= ${TESTSBASE}/bin/sh/parser -KYUAFILE= no +.PATH: ${.CURDIR:H} +ATF_TESTS_SH= functional_test + +FILESDIR= ${TESTSDIR} FILES= alias1.0 FILES+= alias2.0 diff --git a/bin/sh/tests/set-e/Makefile b/bin/sh/tests/set-e/Makefile index 55d7917..f733b60 100644 --- a/bin/sh/tests/set-e/Makefile +++ b/bin/sh/tests/set-e/Makefile @@ -1,9 +1,11 @@ # $FreeBSD$ -.include +TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T} -FILESDIR= ${TESTSBASE}/bin/sh/set-e -KYUAFILE= no +.PATH: ${.CURDIR:H} +ATF_TESTS_SH= functional_test + +FILESDIR= ${TESTSDIR} FILES= and1.0 FILES+= and2.1 diff --git a/tools/build/mk/OptionalObsoleteFiles.inc b/tools/build/mk/OptionalObsoleteFiles.inc index 549b7b6..4361d08 100644 --- a/tools/build/mk/OptionalObsoleteFiles.inc +++ b/tools/build/mk/OptionalObsoleteFiles.inc @@ -4468,6 +4468,7 @@ OLD_FILES+=usr/share/aclocal/atf-common.m4 OLD_FILES+=usr/share/aclocal/atf-sh.m4 OLD_DIRS+=usr/share/aclocal OLD_FILES+=usr/tests/bin/date/legacy_test +OLD_FILES+=usr/tests/bin/sh/legacy_test OLD_FILES+=usr/tests/lib/atf/libatf-c/test_helpers_test OLD_FILES+=usr/tests/lib/atf/test-programs/fork_test OLD_FILES+=usr/tests/lib/atf/libatf-c++/application_test -- cgit v1.1 From 28836b5874b4d176b3acc6cc8b16bccbe5fff5a6 Mon Sep 17 00:00:00 2001 From: royger Date: Wed, 2 Dec 2015 10:23:54 +0000 Subject: MFC r291022: x86/intr: allow mutex recursion in intr_remove_handler Sponsored by: Citrix Systems R&D --- sys/x86/x86/intr_machdep.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/sys/x86/x86/intr_machdep.c b/sys/x86/x86/intr_machdep.c index 9a5e463..cc50321 100644 --- a/sys/x86/x86/intr_machdep.c +++ b/sys/x86/x86/intr_machdep.c @@ -197,19 +197,28 @@ int intr_remove_handler(void *cookie) { struct intsrc *isrc; - int error; + int error, mtx_owned; isrc = intr_handler_source(cookie); error = intr_event_remove_handler(cookie); if (error == 0) { - mtx_lock(&intr_table_lock); + /* + * Recursion is needed here so PICs can remove interrupts + * while resuming. It was previously not possible due to + * intr_resume holding the intr_table_lock and + * intr_remove_handler recursing on it. + */ + mtx_owned = mtx_owned(&intr_table_lock); + if (mtx_owned == 0) + mtx_lock(&intr_table_lock); isrc->is_handlers--; if (isrc->is_handlers == 0) { isrc->is_pic->pic_disable_source(isrc, PIC_NO_EOI); isrc->is_pic->pic_disable_intr(isrc); } intrcnt_updatename(isrc); - mtx_unlock(&intr_table_lock); + if (mtx_owned == 0) + mtx_unlock(&intr_table_lock); } return (error); } -- cgit v1.1 From b1833e15625d0430c3295929d57b86e1959c9f6b Mon Sep 17 00:00:00 2001 From: royger Date: Wed, 2 Dec 2015 10:26:34 +0000 Subject: MFC r291023: xen/intr: properly dispose event channels on resume Sponsored by: Citrix Systems R&D --- sys/x86/xen/xen_intr.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sys/x86/xen/xen_intr.c b/sys/x86/xen/xen_intr.c index fd36e68..20ebad5 100644 --- a/sys/x86/xen/xen_intr.c +++ b/sys/x86/xen/xen_intr.c @@ -711,7 +711,10 @@ xen_intr_resume(struct pic *unused, bool suspend_cancelled) xen_rebind_virq(isrc); break; default: + intr_remove_handler(isrc->xi_cookie); isrc->xi_cpu = 0; + isrc->xi_type = EVTCHN_TYPE_UNBOUND; + isrc->xi_cookie = NULL; break; } } -- cgit v1.1 From 904bdb8bc249483f4b14b6df43fb361e87b438da Mon Sep 17 00:00:00 2001 From: royger Date: Wed, 2 Dec 2015 12:58:20 +0000 Subject: Revert MFC of r291023: Due to the delta between HEAD and stable/10 event channel code, this fix is not needed on stable/10 and was also causing build issues. Revert it. --- sys/x86/xen/xen_intr.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/sys/x86/xen/xen_intr.c b/sys/x86/xen/xen_intr.c index 20ebad5..fd36e68 100644 --- a/sys/x86/xen/xen_intr.c +++ b/sys/x86/xen/xen_intr.c @@ -711,10 +711,7 @@ xen_intr_resume(struct pic *unused, bool suspend_cancelled) xen_rebind_virq(isrc); break; default: - intr_remove_handler(isrc->xi_cookie); isrc->xi_cpu = 0; - isrc->xi_type = EVTCHN_TYPE_UNBOUND; - isrc->xi_cookie = NULL; break; } } -- cgit v1.1 From ccce6feaa419fbc5fc1c0f617f6ad974b07a58c4 Mon Sep 17 00:00:00 2001 From: fabient Date: Wed, 2 Dec 2015 17:26:37 +0000 Subject: MFC r291301: The r241129 description was wrong that the scenario is possible only for read locks on pcbs. The same race can happen with write lock semantics as well. The race scenario: - Two threads (1 and 2) locate pcb with writer semantics (INPLOOKUP_WLOCKPCB) and do in_pcbref() on it. - 1 and 2 both drop the inp hash lock. - Another thread (3) grabs the inp hash lock. Then it runs in_pcbfree(), which wlocks the pcb. They must happen faster than 1 or 2 come INP_WLOCK()! - 1 and 2 congest in INP_WLOCK(). - 3 does in_pcbremlists(), drops hash lock, and runs in_pcbrele_wlocked(), which doesn't free the pcb due to two references on it. Then it unlocks the pcb. - 1 (or 2) gets wlock on the pcb, runs in_pcbrele_wlocked(), which doesn't report inp as freed, due to 2 (or 1) still helding extra reference on it. The thread tries to do smth with a disconnected pcb and crashes. Submitted by: emeric.poupon@stormshield.eu Reviewed by: glebius@ Sponsored by: Stormshield Tested by: Cassiano Peixoto, Stormshield --- sys/netinet/in_pcb.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 4e75f13..0b296e0 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -1148,8 +1148,17 @@ in_pcbrele_wlocked(struct inpcb *inp) INP_WLOCK_ASSERT(inp); - if (refcount_release(&inp->inp_refcount) == 0) + if (refcount_release(&inp->inp_refcount) == 0) { + /* + * If the inpcb has been freed, let the caller know, even if + * this isn't the last reference. + */ + if (inp->inp_flags2 & INP_FREED) { + INP_WUNLOCK(inp); + return (1); + } return (0); + } KASSERT(inp->inp_socket == NULL, ("%s: inp_socket != NULL", __func__)); -- cgit v1.1 From 68e44b1d7045a500ada4760ebd096f99e1544d2e Mon Sep 17 00:00:00 2001 From: rmacklem Date: Wed, 2 Dec 2015 21:48:34 +0000 Subject: MFC: r291035 The problem report was for a crash that happened when smbfs was trying to do a mount. Given the backtrace, it appears that the crash occurred when smb_vc_create() failed and then called smb_vc_put() with vcp->vc_iod == NULL. smb_vc_put() subsequently called smb_vc_disconnect() with vcp->vc_iod == NULL, causing the crash. This patch adds a check for vcp->vc_iod != NULL in smb_vc_disconnect() to avoid the crash. It also fixes the case in smb_vc_create() where kproc_create() fails so that it destroys the mutexes and sets vcp->vc_iod == NULL before free()'ing the iod structure. --- sys/netsmb/smb_conn.c | 4 +++- sys/netsmb/smb_iod.c | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/sys/netsmb/smb_conn.c b/sys/netsmb/smb_conn.c index d58bc72..adc171c 100644 --- a/sys/netsmb/smb_conn.c +++ b/sys/netsmb/smb_conn.c @@ -683,7 +683,9 @@ int smb_vc_disconnect(struct smb_vc *vcp) { - smb_iod_request(vcp->vc_iod, SMBIOD_EV_DISCONNECT | SMBIOD_EV_SYNC, NULL); + if (vcp->vc_iod != NULL) + smb_iod_request(vcp->vc_iod, SMBIOD_EV_DISCONNECT | + SMBIOD_EV_SYNC, NULL); return 0; } diff --git a/sys/netsmb/smb_iod.c b/sys/netsmb/smb_iod.c index ae5c6f7..412f816 100644 --- a/sys/netsmb/smb_iod.c +++ b/sys/netsmb/smb_iod.c @@ -690,6 +690,9 @@ smb_iod_create(struct smb_vc *vcp) RFNOWAIT, 0, "smbiod%d", iod->iod_id); if (error) { SMBERROR("can't start smbiod: %d", error); + vcp->vc_iod = NULL; + smb_sl_destroy(&iod->iod_rqlock); + smb_sl_destroy(&iod->iod_evlock); free(iod, M_SMBIOD); return error; } -- cgit v1.1