CVS commit: src/sys/net

2016-03-27 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon Mar 28 04:38:04 UTC 2016

Modified Files:
src/sys/net: if_bridge.c

Log Message:
Remove unused global bridge list

Pointed out by riastradh@


To generate a diff of this commit:
cvs rdiff -u -r1.110 -r1.111 src/sys/net/if_bridge.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/if_bridge.c
diff -u src/sys/net/if_bridge.c:1.110 src/sys/net/if_bridge.c:1.111
--- src/sys/net/if_bridge.c:1.110	Wed Mar 23 05:44:01 2016
+++ src/sys/net/if_bridge.c	Mon Mar 28 04:38:04 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_bridge.c,v 1.110 2016/03/23 05:44:01 ozaki-r Exp $	*/
+/*	$NetBSD: if_bridge.c,v 1.111 2016/03/28 04:38:04 ozaki-r Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -80,7 +80,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.110 2016/03/23 05:44:01 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.111 2016/03/28 04:38:04 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_bridge_ipf.h"
@@ -341,9 +341,6 @@ static const struct bridge_control bridg
 
 static const int bridge_control_table_size = __arraycount(bridge_control_table);
 
-static LIST_HEAD(, bridge_softc) bridge_list;
-static kmutex_t bridge_list_lock;
-
 static struct if_clone bridge_cloner =
 IF_CLONE_INITIALIZER("bridge", bridge_clone_create, bridge_clone_destroy);
 
@@ -359,8 +356,6 @@ bridgeattach(int n)
 	pool_init(_rtnode_pool, sizeof(struct bridge_rtnode),
 	0, 0, 0, "brtpl", NULL, IPL_NET);
 
-	LIST_INIT(_list);
-	mutex_init(_list_lock, MUTEX_DEFAULT, IPL_NET);
 	if_clone_attach(_cloner);
 }
 
@@ -432,10 +427,6 @@ bridge_clone_create(struct if_clone *ifc
 
 	if_alloc_sadl(ifp);
 
-	mutex_enter(_list_lock);
-	LIST_INSERT_HEAD(_list, sc, sc_list);
-	mutex_exit(_list_lock);
-
 	return (0);
 }
 
@@ -460,10 +451,6 @@ bridge_clone_destroy(struct ifnet *ifp)
 		bridge_delete_member(sc, bif);
 	BRIDGE_UNLOCK(sc);
 
-	mutex_enter(_list_lock);
-	LIST_REMOVE(sc, sc_list);
-	mutex_exit(_list_lock);
-
 	splx(s);
 
 	if_detach(ifp);



CVS commit: src/sys/net

2016-03-27 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon Mar 28 04:38:04 UTC 2016

Modified Files:
src/sys/net: if_bridge.c

Log Message:
Remove unused global bridge list

Pointed out by riastradh@


To generate a diff of this commit:
cvs rdiff -u -r1.110 -r1.111 src/sys/net/if_bridge.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/net/route

2016-03-27 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon Mar 28 02:35:43 UTC 2016

Modified Files:
src/tests/net/route: t_route.sh

Log Message:
Make outputs informative on failure


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/net/route/t_route.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/net/route/t_route.sh
diff -u src/tests/net/route/t_route.sh:1.2 src/tests/net/route/t_route.sh:1.3
--- src/tests/net/route/t_route.sh:1.2	Mon Mar 28 01:53:07 2016
+++ src/tests/net/route/t_route.sh	Mon Mar 28 02:35:43 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: t_route.sh,v 1.2 2016/03/28 01:53:07 ozaki-r Exp $
+#	$NetBSD: t_route.sh,v 1.3 2016/03/28 02:35:43 ozaki-r Exp $
 #
 # Copyright (c) 2016 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -247,7 +247,7 @@ destination: 10.0.1.2
 	EOF
 	rump.route -n get $IP4SRC > ./output
 	$DEBUG && cat ./expect ./output
-	atf_check -s exit:0 diff -q ./expect ./output
+	atf_check -s exit:0 diff ./expect ./output
 
 	# Neighbor
 	cat >./expect <<-EOF
@@ -262,7 +262,7 @@ destination: 10.0.1.0
 	EOF
 	rump.route -n get $IP4SRCGW > ./output
 	$DEBUG && cat ./expect ./output
-	atf_check -s exit:0 diff -q ./expect ./output
+	atf_check -s exit:0 diff ./expect ./output
 
 	# Remote host
 	cat >./expect <<-EOF
@@ -278,7 +278,7 @@ destination: default
 	EOF
 	rump.route -n get $IP4DST > ./output
 	$DEBUG && cat ./expect ./output
-	atf_check -s exit:0 diff -q ./expect ./output
+	atf_check -s exit:0 diff ./expect ./output
 
 	# Create a ARP cache
 	atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP4SRCGW
@@ -296,7 +296,7 @@ destination: 10.0.1.1
 	$DEBUG && cat ./expect ./output
 	# Trim the last line including unfixed expire time
 	head -6 ./output > ./trimed
-	atf_check -s exit:0 diff -q ./expect ./trimed
+	atf_check -s exit:0 diff ./expect ./trimed
 }
 
 test_route_get6()
@@ -321,7 +321,7 @@ destination: fc00:0:0:1::2
 	EOF
 	rump.route -n get -inet6 $IP6SRC > ./output
 	$DEBUG && cat ./expect ./output
-	atf_check -s exit:0 diff -q ./expect ./output
+	atf_check -s exit:0 diff ./expect ./output
 
 	# Neighbor
 	cat >./expect <<-EOF
@@ -336,7 +336,7 @@ destination: fc00:0:0:1::
 	EOF
 	rump.route -n get -inet6 $IP6SRCGW > ./output
 	$DEBUG && cat ./expect ./output
-	atf_check -s exit:0 diff -q ./expect ./output
+	atf_check -s exit:0 diff ./expect ./output
 
 	# Remote host
 	cat >./expect <<-EOF
@@ -352,7 +352,7 @@ destination: ::
 	EOF
 	rump.route -n get -inet6 $IP6DST > ./output
 	$DEBUG && cat ./expect ./output
-	atf_check -s exit:0 diff -q ./expect ./output
+	atf_check -s exit:0 diff ./expect ./output
 
 	# Create a NDP cache
 	atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT $IP6SRCGW
@@ -370,7 +370,7 @@ destination: fc00:0:0:1::1
 	rump.route -n get -inet6 $IP6SRCGW > ./output
 	$DEBUG && cat ./expect ./output
 	# No need to trim, because a NDP cache doesn't set an expire time
-	atf_check -s exit:0 diff -q ./expect ./output
+	atf_check -s exit:0 diff ./expect ./output
 }
 
 command_get_body()



CVS commit: src/tests/net/route

2016-03-27 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon Mar 28 02:35:43 UTC 2016

Modified Files:
src/tests/net/route: t_route.sh

Log Message:
Make outputs informative on failure


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/net/route/t_route.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/net/route

2016-03-27 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon Mar 28 01:53:07 UTC 2016

Modified Files:
src/tests/net/route: t_route.sh

Log Message:
Add tests for "route get"


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/net/route/t_route.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/net/route/t_route.sh
diff -u src/tests/net/route/t_route.sh:1.1 src/tests/net/route/t_route.sh:1.2
--- src/tests/net/route/t_route.sh:1.1	Fri Jan 29 04:15:46 2016
+++ src/tests/net/route/t_route.sh	Mon Mar 28 01:53:07 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: t_route.sh,v 1.1 2016/01/29 04:15:46 ozaki-r Exp $
+#	$NetBSD: t_route.sh,v 1.2 2016/03/28 01:53:07 ozaki-r Exp $
 #
 # Copyright (c) 2016 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -26,10 +26,29 @@
 #
 
 RUMP_LIBS="-lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif"
+RUMP_LIBS_IPV6="$RUMP_LIBS -lrumpnet_netinet6"
+
+# non_subnet_gateway
 SOCK_CLIENT=unix://commsock1
 SOCK_GW=unix://commsock2
 BUS=bus1
 
+# command_get
+SOCKSRC=unix://commsock1
+SOCKFWD=unix://commsock2
+SOCKDST=unix://commsock3
+IP4SRC=10.0.1.2
+IP4SRCGW=10.0.1.1
+IP4DSTGW=10.0.2.1
+IP4DST=10.0.2.2
+IP4DST_BCAST=10.0.2.255
+IP6SRC=fc00:0:0:1::2
+IP6SRCGW=fc00:0:0:1::1
+IP6DSTGW=fc00:0:0:2::1
+IP6DST=fc00:0:0:2::2
+BUS_SRCGW=bus1
+BUS_DSTGW=bus2
+
 DEBUG=false
 TIMEOUT=1
 PING_OPTS="-n -c 1 -w $TIMEOUT"
@@ -96,8 +115,315 @@ non_subnet_gateway_cleanup()
 	env RUMP_SERVER=$SOCK_GW rump.halt
 }
 
+atf_test_case command_get cleanup
+atf_test_case command_get6 cleanup
+command_get_head()
+{
+
+	atf_set "descr" "tests of route get command"
+	atf_set "require.progs" "rump_server"
+}
+
+command_get6_head()
+{
+
+	atf_set "descr" "tests of route get command (IPv6)"
+	atf_set "require.progs" "rump_server"
+}
+
+setup_endpoint()
+{
+	local sock=${1}
+	local addr=${2}
+	local bus=${3}
+	local mode=${4}
+	local gw=${5}
+
+	export RUMP_SERVER=${sock}
+	atf_check -s exit:0 rump.ifconfig shmif0 create
+	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ${bus}
+	if [ $mode = "ipv6" ]; then
+		atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${addr}
+		atf_check -s exit:0 -o ignore rump.route add -inet6 default ${gw}
+	else
+		atf_check -s exit:0 rump.ifconfig shmif0 inet ${addr} netmask 0xff00
+		atf_check -s exit:0 -o ignore rump.route add default ${gw}
+	fi
+	atf_check -s exit:0 rump.ifconfig shmif0 up
+
+	if $DEBUG; then
+		rump.ifconfig shmif0
+		rump.netstat -nr
+	fi
+}
+
+setup_forwarder()
+{
+	mode=${1}
+
+	export RUMP_SERVER=$SOCKFWD
+	atf_check -s exit:0 rump.ifconfig shmif0 create
+	atf_check -s exit:0 rump.ifconfig shmif0 linkstr $BUS_SRCGW
+
+	atf_check -s exit:0 rump.ifconfig shmif1 create
+	atf_check -s exit:0 rump.ifconfig shmif1 linkstr $BUS_DSTGW
+
+	if [ $mode = "ipv6" ]; then
+		atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6SRCGW}
+		atf_check -s exit:0 rump.ifconfig shmif1 inet6 ${IP6DSTGW}
+	else
+		atf_check -s exit:0 rump.ifconfig shmif0 inet ${IP4SRCGW} netmask 0xff00
+		atf_check -s exit:0 rump.ifconfig shmif1 inet ${IP4DSTGW} netmask 0xff00
+	fi
+
+	atf_check -s exit:0 rump.ifconfig shmif0 up
+	atf_check -s exit:0 rump.ifconfig shmif1 up
+
+	if $DEBUG; then
+		rump.netstat -nr
+		if [ $mode = "ipv6" ]; then
+			rump.sysctl net.inet6.ip6.forwarding
+		else
+			rump.sysctl net.inet.ip.forwarding
+		fi
+	fi
+}
+
+setup_forwarding()
+{
+	export RUMP_SERVER=$SOCKFWD
+	atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.forwarding=1
+}
+
+setup_forwarding6()
+{
+	export RUMP_SERVER=$SOCKFWD
+	atf_check -s exit:0 -o ignore rump.sysctl -w net.inet6.ip6.forwarding=1
+}
+
+setup()
+{
+
+	atf_check -s exit:0 rump_server $RUMP_LIBS $SOCKSRC
+	atf_check -s exit:0 rump_server $RUMP_LIBS $SOCKFWD
+	atf_check -s exit:0 rump_server $RUMP_LIBS $SOCKDST
+
+	setup_endpoint $SOCKSRC $IP4SRC $BUS_SRCGW ipv4 $IP4SRCGW
+	setup_endpoint $SOCKDST $IP4DST $BUS_DSTGW ipv4 $IP4DSTGW
+	setup_forwarder ipv4
+}
+
+setup6()
+{
+
+	atf_check -s exit:0 rump_server $RUMP_LIBS_IPV6 $SOCKSRC
+	atf_check -s exit:0 rump_server $RUMP_LIBS_IPV6 $SOCKFWD
+	atf_check -s exit:0 rump_server $RUMP_LIBS_IPV6 $SOCKDST
+
+	setup_endpoint $SOCKSRC $IP6SRC $BUS_SRCGW ipv6 $IP6SRCGW
+	setup_endpoint $SOCKDST $IP6DST $BUS_DSTGW ipv6 $IP6DSTGW
+	setup_forwarder ipv6
+}
+
+test_route_get()
+{
+
+	export RUMP_SERVER=$SOCKSRC
+	$DEBUG && rump.netstat -nr -f inet
+	$DEBUG && rump.arp -n -a
+
+	# Make sure an ARP cache to the gateway doesn't exist
+	rump.arp -d $IP4SRCGW
+
+	# Local
+	cat >./expect <<-EOF
+   route to: 10.0.1.2
+destination: 10.0.1.2
+ local addr: 10.0.1.2
+  interface: lo0
+  flags: 
+ recvpipe  sendpipe  ssthresh  rtt,msecrttvar  hopcount  mtu expire
+   0 0 0 0 0 0 0 0 
+	EOF
+	rump.route -n get $IP4SRC > ./output
+	$DEBUG && cat ./expect ./output
+	atf_check -s 

CVS commit: src/tests/net/route

2016-03-27 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon Mar 28 01:53:07 UTC 2016

Modified Files:
src/tests/net/route: t_route.sh

Log Message:
Add tests for "route get"


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/net/route/t_route.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/kdump

2016-03-27 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Sun Mar 27 21:51:20 UTC 2016

Modified Files:
src/usr.bin/kdump: kdump.c

Log Message:
Don't enter infinite loop on big ktr_len values.

Fixes PR 49460.


To generate a diff of this commit:
cvs rdiff -u -r1.122 -r1.123 src/usr.bin/kdump/kdump.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/kdump/kdump.c
diff -u src/usr.bin/kdump/kdump.c:1.122 src/usr.bin/kdump/kdump.c:1.123
--- src/usr.bin/kdump/kdump.c:1.122	Mon Jan  4 08:24:42 2016
+++ src/usr.bin/kdump/kdump.c	Sun Mar 27 21:51:20 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: kdump.c,v 1.122 2016/01/04 08:24:42 martin Exp $	*/
+/*	$NetBSD: kdump.c,v 1.123 2016/03/27 21:51:20 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 1988, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19
 #if 0
 static char sccsid[] = "@(#)kdump.c	8.4 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: kdump.c,v 1.122 2016/01/04 08:24:42 martin Exp $");
+__RCSID("$NetBSD: kdump.c,v 1.123 2016/03/27 21:51:20 alnsn Exp $");
 #endif
 #endif /* not lint */
 
@@ -109,7 +109,7 @@ static void	ioctldecode(u_long);
 static void	ktrsyscall(struct ktr_syscall *);
 static void	ktrsysret(struct ktr_sysret *, int);
 static void	ktrnamei(char *, int);
-static void	ktremul(char *, int, int);
+static void	ktremul(char *, size_t, size_t);
 static void	ktrgenio(struct ktr_genio *, int);
 static void	ktrpsig(void *, int);
 static void	ktrcsw(struct ktr_csw *);
@@ -126,7 +126,8 @@ static void visdump_buf(const void *, in
 int
 main(int argc, char **argv)
 {
-	int ch, ktrlen, size;
+	unsigned int ktrlen, size;
+	int ch;
 	void *m;
 	int trpoints = 0;
 	int trset = 0;
@@ -249,7 +250,7 @@ main(int argc, char **argv)
 			col = dumpheader(_header);
 		else
 			col = -1;
-		if ((ktrlen = ktr_header.ktr_len) < 0)
+		if ((ktrlen = ktr_header.ktr_len) > INT_MAX)
 			errx(1, "bogus length 0x%x", ktrlen);
 		if (ktrlen > size) {
 			while (ktrlen > size)
@@ -751,7 +752,7 @@ ktrnamei(char *cp, int len)
 }
 
 static void
-ktremul(char *name, int len, int bufsize)
+ktremul(char *name, size_t len, size_t bufsize)
 {
 
 	if (len >= bufsize)



CVS commit: src/usr.bin/kdump

2016-03-27 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Sun Mar 27 21:51:20 UTC 2016

Modified Files:
src/usr.bin/kdump: kdump.c

Log Message:
Don't enter infinite loop on big ktr_len values.

Fixes PR 49460.


To generate a diff of this commit:
cvs rdiff -u -r1.122 -r1.123 src/usr.bin/kdump/kdump.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/external/gpl3/gcc/dist/gcc/config/i386

2016-03-27 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Mar 27 17:17:59 UTC 2016

Modified Files:
src/external/gpl3/gcc/dist/gcc/config/i386: netbsd64.h

Log Message:
revert most of the previous and re-do it to be valid, re-fixing i386 psABI
support with -m32.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 \
src/external/gpl3/gcc/dist/gcc/config/i386/netbsd64.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/gpl3/gcc/dist/gcc/config/i386/netbsd64.h
diff -u src/external/gpl3/gcc/dist/gcc/config/i386/netbsd64.h:1.5 src/external/gpl3/gcc/dist/gcc/config/i386/netbsd64.h:1.6
--- src/external/gpl3/gcc/dist/gcc/config/i386/netbsd64.h:1.5	Sun Mar 27 04:18:09 2016
+++ src/external/gpl3/gcc/dist/gcc/config/i386/netbsd64.h	Sun Mar 27 17:17:59 2016
@@ -66,6 +66,11 @@ along with GCC; see the file COPYING3.  
 fprintf (FILE, "\tcall __mcount\n");\
 }
 
+/* Preserve i386 psABI  */
+#undef PREFERRED_STACK_BOUNDARY_DEFAULT
+#define PREFERRED_STACK_BOUNDARY_DEFAULT \
+  ((TARGET_64BIT || TARGET_SSE) ? 128 : 32)
+
 #define HAVE_ENABLE_EXECUTE_STACK
 
 #define IX86_MAYBE_NO_LIBGCC_TFMODE



CVS commit: src/external/gpl3/gcc/dist/gcc/config/i386

2016-03-27 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Mar 27 17:17:59 UTC 2016

Modified Files:
src/external/gpl3/gcc/dist/gcc/config/i386: netbsd64.h

Log Message:
revert most of the previous and re-do it to be valid, re-fixing i386 psABI
support with -m32.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 \
src/external/gpl3/gcc/dist/gcc/config/i386/netbsd64.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/bin/sh/dotcmd

2016-03-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar 27 14:57:50 UTC 2016

Modified Files:
src/tests/bin/sh/dotcmd: Makefile scoped_command t_dotcmd.sh

Log Message:
Allow for testing other than /bin/sh using TEST_SH (from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/bin/sh/dotcmd/Makefile
cvs rdiff -u -r1.1 -r1.2 src/tests/bin/sh/dotcmd/scoped_command \
src/tests/bin/sh/dotcmd/t_dotcmd.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/dotcmd/Makefile
diff -u src/tests/bin/sh/dotcmd/Makefile:1.2 src/tests/bin/sh/dotcmd/Makefile:1.3
--- src/tests/bin/sh/dotcmd/Makefile:1.2	Sun Jul 27 10:24:17 2014
+++ src/tests/bin/sh/dotcmd/Makefile	Sun Mar 27 10:57:50 2016
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.2 2014/07/27 14:24:17 apb Exp $
+# $NetBSD: Makefile,v 1.3 2016/03/27 14:57:50 christos Exp $
 #
 
 .include 
@@ -7,6 +7,10 @@ TESTSDIR = ${TESTSBASE}/bin/sh/dotcmd
 
 TESTS_SH = t_dotcmd
 
+.if !defined(TEST_SH)
+TEST_SH = ${HOST_SH}
+.endif
+
 FILESDIR = ${TESTSDIR}/out
 
 # Testing scripts: dotcmd in various scopes includes a file with
@@ -19,7 +23,7 @@ FILESDIR_${cmd}_${cmd_scope} = ${TESTSDI
 FILESBUILD_${cmd}_${cmd_scope} = yes
 
 ${cmd}_${cmd_scope}: scoped_command
-	${HOST_SH} ${.CURDIR}/scoped_command '${cmd_scope}' '${cmd}' '${cmd}' \
+	${TEST_SH} ${.CURDIR}/scoped_command '${cmd_scope}' '${cmd}' '${cmd}' \
 		>'${.TARGET}'
 
 .  for dot_scope in case compound file for func subshell until while
@@ -31,7 +35,7 @@ FILESBUILD_${dot_scope}_${cmd}_${cmd_sco
 FILESMODE_${dot_scope}_${cmd}_${cmd_scope} = ${BINMODE}
 
 ${dot_scope}_${cmd}_${cmd_scope}: scoped_command
-	${HOST_SH} ${.CURDIR}/scoped_command '${dot_scope}' \
+	${TEST_SH} ${.CURDIR}/scoped_command '${dot_scope}' \
 		'. "${cmd}_${cmd_scope}"' 'dotcmd' 'dotcmd' >'${.TARGET}'
 .  endfor
 . endfor

Index: src/tests/bin/sh/dotcmd/scoped_command
diff -u src/tests/bin/sh/dotcmd/scoped_command:1.1 src/tests/bin/sh/dotcmd/scoped_command:1.2
--- src/tests/bin/sh/dotcmd/scoped_command:1.1	Sat May 31 10:29:06 2014
+++ src/tests/bin/sh/dotcmd/scoped_command	Sun Mar 27 10:57:50 2016
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# $NetBSD: scoped_command,v 1.1 2014/05/31 14:29:06 christos Exp $
+# $NetBSD: scoped_command,v 1.2 2016/03/27 14:57:50 christos Exp $
 #
 # Copyright (c) 2014 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -30,6 +30,27 @@
 # POSSIBILITY OF SUCH DAMAGE.
 #
 
+: ${TEST_SH:=/bin/sh}
+
+sane_sh()
+{
+	set -- ${TEST_SH}
+	case "$#" in
+	(0)   set /bin/sh;;
+	(1|2) ;;
+	(*)   set "$1";;   # Just ignore options if we cannot make them work
+	esac
+
+	case "$1" in
+	/*)	TEST_SH="$1${2+ }$2";;
+	./*)	TEST_SH="${PWD}${1#.}${2+ }$2";;
+	*/*)	TEST_SH="${PWD}/$1${2+ }$2";;
+	*)	TEST_SH="$( command -v "$1" )${2+ }$2";;
+	esac
+}
+
+sane_sh
+
 set -e
 
 # USAGE:
@@ -52,7 +73,7 @@ cmd="echo 'before ${3}'
 ${2}
 echo 'after ${3}, return value:' ${?}"
 
-echo "#!/bin/sh"
+echo "#!${TEST_SH}"
 
 [ 'func' = "${1}" ] && cat <

CVS commit: src/tests/bin/sh/dotcmd

2016-03-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar 27 14:57:50 UTC 2016

Modified Files:
src/tests/bin/sh/dotcmd: Makefile scoped_command t_dotcmd.sh

Log Message:
Allow for testing other than /bin/sh using TEST_SH (from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/bin/sh/dotcmd/Makefile
cvs rdiff -u -r1.1 -r1.2 src/tests/bin/sh/dotcmd/scoped_command \
src/tests/bin/sh/dotcmd/t_dotcmd.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/bin/sh

2016-03-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar 27 14:53:17 UTC 2016

Modified Files:
src/tests/bin/sh: t_cmdsub.sh

Log Message:
Finish these tests (or at least, fill in the place holder tests
with actual code ... tests are never really finished.)  One of these
new tests was how the bug in PR bin/50993 was discovered. (from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/bin/sh/t_cmdsub.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_cmdsub.sh
diff -u src/tests/bin/sh/t_cmdsub.sh:1.1 src/tests/bin/sh/t_cmdsub.sh:1.2
--- src/tests/bin/sh/t_cmdsub.sh:1.1	Sun Mar 20 18:57:04 2016
+++ src/tests/bin/sh/t_cmdsub.sh	Sun Mar 27 10:53:17 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_cmdsub.sh,v 1.1 2016/03/20 22:57:04 christos Exp $
+# $NetBSD: t_cmdsub.sh,v 1.2 2016/03/27 14:53:17 christos Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -181,6 +181,9 @@ f_redirect_in_cmdsub_head() {
 	atf_set "descr" "Checks that redirects work in command substitutions"
 }
 f_redirect_in_cmdsub_body() {
+	atf_require_prog cat
+	atf_require_prog rm
+
 	rm -f file 2>/dev/null || :
 	atf_check -s exit:0 -o match:'_aa_' -e empty \
 	${TEST_SH} -c 'echo _$( echo a$( echo b > file )a)_'
@@ -199,6 +202,9 @@ g_redirect_in_backticks_head() {
 	atf_set "descr" "Checks that redirects work in old style cmd sub"
 }
 g_redirect_in_backticks_body() {
+	atf_require_prog cat
+	atf_require_prog rm
+
 	rm -f file 2>/dev/null || :
 	atf_check -s exit:0 -o match:'_aa_' -e empty \
 	${TEST_SH} -c 'echo _` echo a\` echo b > file \`a`_'
@@ -371,6 +377,8 @@ p_cmdsub_in_heredoc_head() {
 	atf_set "descr" "Checks that cmdsubs work inside a here document"
 }
 p_cmdsub_in_heredoc_body() {
+	atf_require_prog cat
+
 	atf_check -s exit:0 -o inline:'line 1+1\nline 2\nline 3\n' -e empty \
 	${TEST_SH} -c \
 		'cat <<- EOF
@@ -384,6 +392,8 @@ q_backticks_in_heredoc_head() {
 	atf_set "descr" "Checks that old style cmdsubs work in here docs"
 }
 q_backticks_in_heredoc_body() {
+	atf_require_prog cat
+
 	atf_check -s exit:0 -o inline:'Mary had a\nlittle\nlamb\n' -e empty \
 	${TEST_SH} -c \
 		'cat <<- EOF
@@ -397,6 +407,8 @@ r_heredoc_in_cmdsub_head() {
 	atf_set "descr" "Checks that here docs work inside cmd subs"
 }
 r_heredoc_in_cmdsub_body() {
+	atf_require_prog cat
+
 	atf_check -s exit:0 -o inline:'Mary had a\nlittle\nlamb\n' -e empty \
 	${TEST_SH} -c 'echo "$( cat <<- \EOF
 Mary had a
@@ -422,8 +434,6 @@ r_heredoc_in_cmdsub_body() {
 			EOF
 			)"'
 
-	# not all shells permit this syntax ...
-	# But I see nothing in the standard to prohibit it.
 	atf_check -s exit:0 -o inline:'Line 1\nLine 2\n' -e empty \
 	${TEST_SH} -c 'echo "$( cat <<- "EOF" )"
 Line 1
@@ -437,6 +447,8 @@ s_heredoc_in_backticks_head() {
 	atf_set "descr" "Checks that here docs work inside old style cmd subs"
 }
 s_heredoc_in_backticks_body() {
+	atf_require_prog cat
+
 	atf_check -s exit:0 -o inline:'Mary had a little lamb\n' -e empty \
 	${TEST_SH} -c 'echo ` cat <<- \EOF
 Mary had a
@@ -458,6 +470,26 @@ t_nested_cmdsubs_in_heredoc_head() {
 	atf_set "descr" "Checks nested command substitutions in here docs"
 }
 t_nested_cmdsubs_in_heredoc_body() {
+	atf_require_prog cat
+	atf_require_prog rm
+
+	rm -f * 2>/dev/null || :
+	echo "Hello" > File
+
+	atf_check -s exit:0 -o inline:'Hello U\nHelp me!\n' -e empty \
+	${TEST_SH} -c 'cat <<- EOF
+		$(cat File) U
+		$( V=$(cat File); echo "${V%lo}p" ) me!
+		EOF'
+
+	rm -f * 2>/dev/null || :
+	echo V>V ; echo A>A; echo R>R
+	echo Value>VAR
+
+	atf_check -s exit:0 -o inline:'$2.50\n' -e empty \
+	${TEST_SH} -c 'cat <<- EOF
+	$(Value='\''$2.50'\'';eval echo $(eval $(cat V)$(cat A)$(cat R)=\'\''\$$(cat $(cat V)$(cat A)$(cat R))\'\''; eval echo \$$(set -- *;echo ${3}${1}${2})))
+		EOF'
 }
 
 atf_test_case u_nested_backticks_in_heredoc
@@ -465,6 +497,26 @@ u_nested_backticks_in_heredoc_head() {
 	atf_set "descr" "Checks nested old style cmd subs in here docs"
 }
 u_nested_backticks_in_heredoc_body() {
+	atf_require_prog cat
+	atf_require_prog rm
+
+	rm -f * 2>/dev/null || :
+	echo "Hello" > File
+
+	atf_check -s exit:0 -o inline:'Hello U\nHelp me!\n' -e empty \
+	${TEST_SH} -c 'cat <<- EOF
+		`cat File` U
+		`V=\`cat File\`; echo "${V%lo}p" ` me!
+		EOF'
+
+	rm -f * 2>/dev/null || :
+	echo V>V ; echo A>A; echo R>R
+	echo Value>VAR
+
+	atf_check -s exit:0 -o inline:'$5.20\n' -e empty \
+	${TEST_SH} -c 'cat <<- EOF
+	`Value='\''$5.20'\'';eval echo \`eval \\\`cat V\\\`\\\`cat A\\\`\\\`cat R\\\`=\\\'\''\\\$\\\`cat \\\`cat V\\\`\\\`cat A\\\`\\\`cat R\\\`\\\`\\\'\''; eval echo \\\$\\\`set -- *;echo \${3}\${1}\${2}\\\`\``
+		EOF'
 }
 
 atf_test_case z_absurd_heredoc_cmdsub_combos
@@ -472,6 +524,48 @@ z_absurd_heredoc_cmdsub_combos_head() {
 	atf_set "descr" "perverse and 

CVS commit: src/tests/bin/sh

2016-03-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar 27 14:53:17 UTC 2016

Modified Files:
src/tests/bin/sh: t_cmdsub.sh

Log Message:
Finish these tests (or at least, fill in the place holder tests
with actual code ... tests are never really finished.)  One of these
new tests was how the bug in PR bin/50993 was discovered. (from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/bin/sh/t_cmdsub.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/bin/sh

2016-03-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar 27 14:52:40 UTC 2016

Modified Files:
src/tests/bin/sh: t_here.sh

Log Message:
PR bin/50993 - lots of new here document tests to validate all of
the changes made to fix that PR.   LOTS more tests...  A few general
improvements to the way the tests work and results are reported
as well. (from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/bin/sh/t_here.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_here.sh
diff -u src/tests/bin/sh/t_here.sh:1.4 src/tests/bin/sh/t_here.sh:1.5
--- src/tests/bin/sh/t_here.sh:1.4	Tue Mar  8 09:21:02 2016
+++ src/tests/bin/sh/t_here.sh	Sun Mar 27 10:52:40 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_here.sh,v 1.4 2016/03/08 14:21:02 christos Exp $
+# $NetBSD: t_here.sh,v 1.5 2016/03/27 14:52:40 christos Exp $
 #
 # Copyright (c) 2007 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -30,21 +30,29 @@
 nl='
 '
 
+reset()
+{
+	TEST_NUM=0
+	TEST_FAILURES=''
+	TEST_FAIL_COUNT=0
+	TEST_ID="$1"
+}
+
 check()
 {
 	fail=false
 	TEMP_FILE=$( mktemp OUT.XX )
+	TEST_NUM=$(( $TEST_NUM + 1 ))
 
 	# our local shell (ATF_SHELL) better do quoting correctly...
 	# some of the tests expect us to expand $nl internally...
 	CMD="nl='${nl}'; $1"
 
-	rm -f trace.*
 	result="$( ${TEST_SH} -c "${CMD}" 2>"${TEMP_FILE}" )"
 	STATUS=$?
 
 	if [ "${STATUS}" -ne "$3" ]; then
-		echo >&2 "expected exit code $3, got ${STATUS}"
+		echo >&2 "[$TEST_NUM] expected exit code $3, got ${STATUS}"
 
 		# don't actually fail just because of wrong exit code
 		# unless we either expected, or received "good"
@@ -55,13 +63,15 @@ check()
 
 	if [ "$3" -eq 0 ]; then
 		if [ -s "${TEMP_FILE}" ]; then
-			echo >&2 "Messages produced on stderr unexpected..."
+			echo >&2 \
+			 "[$TEST_NUM] Messages produced on stderr unexpected..."
 			cat "${TEMP_FILE}" >&2
 			fail=true
 		fi
 	else
 		if ! [ -s "${TEMP_FILE}" ]; then
-			echo >&2 "Expected messages on stderr, nothing produced"
+			echo >&2 \
+		"[$TEST_NUM] Expected messages on stderr, nothing produced"
 			fail=true
 		fi
 	fi
@@ -74,14 +84,33 @@ check()
 	IFS="$oifs"
 	if [ "$2" != "$result" ]
 	then
-		echo >&2 "Expected output '$2', received '$result'"
+		echo >&2 "[$TEST_NUM] Expected output '$2', received '$result'"
 		fail=true
 	fi
 
-	$fail && atf_fail "test of '$1' failed"
+	$fail && test -n "$TEST_ID" && {
+		TEST_FAILURES="${TEST_FAILURES}${TEST_FAILURES:+
+}${TEST_ID}[$TEST_NUM]: test of '$1' failed";
+		TEST_FAIL_COUNT=$(( $TEST_FAIL_COUNT + 1 ))
+		return 0
+	}
+	$fail && atf_fail "Test[$TEST_NUM] of '$1' failed"
 	return 0
 }
 
+results()
+{
+	test -z "${TEST_ID}" && return 0
+	test -z "${TEST_FAILURES}" && return 0
+
+	echo >&2 "=="
+	echo >&2 "While testing '${TEST_ID}'"
+	echo >&2 " - - - - - - - - - - - - - - - - -"
+	echo >&2 "${TEST_FAILURES}"
+	atf_fail \
+ "Test ${TEST_ID}: $TEST_FAIL_COUNT subtests (of $TEST_NUM) failed - see stderr"
+}
+
 atf_test_case do_simple
 do_simple_head() {
 	atf_set "descr" "Basic tests for here documents"
@@ -89,7 +118,8 @@ do_simple_head() {
 do_simple_body() {
 	y=x
 
-	IFS=
+	reset 'simple'
+	IFS=' 	'
 	check 'x=`cat <

CVS commit: src/tests/bin/sh

2016-03-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar 27 14:52:40 UTC 2016

Modified Files:
src/tests/bin/sh: t_here.sh

Log Message:
PR bin/50993 - lots of new here document tests to validate all of
the changes made to fix that PR.   LOTS more tests...  A few general
improvements to the way the tests work and results are reported
as well. (from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/bin/sh/t_here.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/bin/sh

2016-03-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar 27 14:50:40 UTC 2016

Modified Files:
src/tests/bin/sh: t_wait.sh

Log Message:
More tests, add protection against shells that allow wait N
to wait for the same process over and over again (forever) (???)
This test now takes slightly over 20 seconds to complete (elapsed
time) caused by all the waiting on sleep commands being run in
the background. (from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/bin/sh/t_wait.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/bin/sh

2016-03-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar 27 14:50:40 UTC 2016

Modified Files:
src/tests/bin/sh: t_wait.sh

Log Message:
More tests, add protection against shells that allow wait N
to wait for the same process over and over again (forever) (???)
This test now takes slightly over 20 seconds to complete (elapsed
time) caused by all the waiting on sleep commands being run in
the background. (from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/bin/sh/t_wait.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_wait.sh
diff -u src/tests/bin/sh/t_wait.sh:1.6 src/tests/bin/sh/t_wait.sh:1.7
--- src/tests/bin/sh/t_wait.sh:1.6	Tue Mar  8 09:24:06 2016
+++ src/tests/bin/sh/t_wait.sh	Sun Mar 27 10:50:40 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_wait.sh,v 1.6 2016/03/08 14:24:06 christos Exp $
+# $NetBSD: t_wait.sh,v 1.7 2016/03/27 14:50:40 christos Exp $
 #
 # Copyright (c) 2008, 2009, 2010 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -27,34 +27,115 @@
 # the implementation of "sh" to test
 : ${TEST_SH:="/bin/sh"}
 
+atf_test_case basic_wait
+basic_wait_head() {
+	atf_set "descr" "Tests simple uses of wait"
+}
+basic_wait_body() {
+	atf_require_prog sleep
+
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+		'(echo nothing >/dev/null) & wait'
+
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+		'(exit 3) & wait $!; S=$?; test $S -eq 3 || {
+			echo "status: $S"; exit 1; }'
+
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+		'sleep 3 & sleep 2 & sleep 1 & wait'
+
+	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+		'sleep 3 & (exit 2) & sleep 1 & wait'
+}
+
 atf_test_case individual
 individual_head() {
-	atf_set "descr" "Tests that waiting for individual jobs works"
+	atf_set "descr" "Tests that waiting for individual processes works"
 }
 individual_body() {
+	atf_require_prog sleep
+
+	cat >individualhelper.sh <<\EOF
+sleep 3 & P1=$!
+sleep 1 & P2=$!
+
+wait ${P1}
+S=$?
+if [ $S -ne 0 ]; then
+echo "Waiting for first process failed: $S"
+exit 1
+fi
+
+wait ${P2}
+S=$?
+if [ $? -ne 0 ]; then
+echo "Waiting for second process failed"
+exit 1
+fi
+
+exit 0
+EOF
+	output=$(${TEST_SH} individualhelper.sh 2>&1)
+	[ $? -eq 0 ] || atf_fail "${output}"
+}
+
+atf_test_case jobs
+jobs_head() {
+	atf_set "descr" "Tests that waiting for individual jobs works"
+}
+jobs_body() {
 	# atf-sh confuses wait for some reason; work it around by creating
 	# a helper script that executes /bin/sh directly.
+
+	if ! ${TEST_SH} -c 'sleep 1 & wait %1' 2>/dev/null
+	then
+		atf_skip "No job control support in this shell"
+	fi
+
 	cat >individualhelper.sh <<\EOF
 sleep 3 &
 sleep 1 &
 
 wait %1
 if [ $? -ne 0 ]; then
-echo "Waiting of first job failed"
+echo "Waiting for first job failed"
 exit 1
 fi
 
 wait %2
 if [ $? -ne 0 ]; then
-echo "Waiting of second job failed"
+echo "Waiting for second job failed"
 exit 1
 fi
 
 exit 0
 EOF
-	output=$("${TEST_SH}" individualhelper.sh)
+	output=$(${TEST_SH} individualhelper.sh 2>&1)
+	[ $? -eq 0 ] || atf_fail "${output}"
+
+	cat >individualhelper.sh <<\EOF
+{ sleep 3; exit 3; } &
+{ sleep 1; exit 7; } &
+
+wait %1
+S=$?
+if [ $S -ne 3 ]; then
+echo "Waiting for first job failed - status: $S != 3 (expected)"
+exit 1
+fi
+
+wait %2
+S=$?
+if [ $S -ne 7 ]; then
+echo "Waiting for second job failed - status: $S != 7 (expected)"
+exit 1
+fi
+
+exit 0
+EOF
+
+	output=$(${TEST_SH} individualhelper.sh 2>&1)
 	[ $? -eq 0 ] || atf_fail "${output}"
-	rm -f individualhelper.sh
 }
 
 atf_test_case kill
@@ -62,39 +143,53 @@ kill_head() {
 	atf_set "descr" "Tests that killing the shell while in wait calls trap"
 }
 kill_body() {
-	# atf-sh confuses wait for some reason; work it around by creating
-	# a helper script that executes /bin/sh directly.
-	local s=$PWD/killhelper.sh
-	local z=/tmp/killhelper.$$ 
-	local pid=
+	atf_require_prog sleep
+	atf_require_prog kill
+
+	s=killhelper.sh
+	z=/tmp/killhelper.$$ 
+	pid=
+
+	# waiting for a specific process that is not a child
+	# should return exit status of 127 according to the spec
+	# This test is here before the next, to avoid that one
+	# entering an infinite loop should the shell have a bug here.
+
+	atf_check -s exit:127 -o empty -e ignore ${TEST_SH} -c 'wait 1'
+
+	cat > "${s}" <<'EOF'
 
-	sed 's!${SH}!'"${TEST_SH}!"  >$s <<\EOF
-#! ${SH}
 trap "echo SIGHUP" 1
 (sleep 5; exit 3) &
 sl=$!
 wait
 S=$?
 echo $S
-while [ $S -ne 0 ] && [ $S != 127 ]; do wait $sl; S=$?; echo $S; done
+LS=
+while [ $S -ne 0 ] && [ $S != 127 ]; do
+	wait $sl; S=$?; echo $S
+	test $S = $LS && { echo "wait repeats..."; exit 2; }
+	LS=$S
+	done
 EOF
-	chmod +x $s
 
-	$s > $z &
+	${TEST_SH} $s > $z &
 	pid=$!
 	sleep 1
 
-	kill -HUP $pid
+	kill -HUP "${pid}"
 	wait
 
 	output="$(cat $z | tr '\n' ' ')"
-	rm -f $s $z
+
 	if [ 

CVS commit: src/tests/bin/sh

2016-03-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar 27 14:50:01 UTC 2016

Modified Files:
src/tests/bin/sh: t_evaltested.sh t_fsplit.sh t_set_e.sh t_ulimit.sh
t_varquote.sh

Log Message:
Finish TEST_SH - all tests should support it now.
Misc other KNF changes, minor bug fixes, and a few minor
extra tests added. (from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/bin/sh/t_evaltested.sh
cvs rdiff -u -r1.3 -r1.4 src/tests/bin/sh/t_fsplit.sh
cvs rdiff -u -r1.2 -r1.3 src/tests/bin/sh/t_set_e.sh \
src/tests/bin/sh/t_ulimit.sh
cvs rdiff -u -r1.4 -r1.5 src/tests/bin/sh/t_varquote.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_evaltested.sh
diff -u src/tests/bin/sh/t_evaltested.sh:1.1 src/tests/bin/sh/t_evaltested.sh:1.2
--- src/tests/bin/sh/t_evaltested.sh:1.1	Sat Mar 17 12:33:11 2012
+++ src/tests/bin/sh/t_evaltested.sh	Sun Mar 27 10:50:01 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_evaltested.sh,v 1.1 2012/03/17 16:33:11 jruoho Exp $
+# $NetBSD: t_evaltested.sh,v 1.2 2016/03/27 14:50:01 christos Exp $
 #
 # Copyright (c) 2011 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -24,6 +24,8 @@
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 # POSSIBILITY OF SUCH DAMAGE.
 #
+# the implementation of "sh" to test
+: ${TEST_SH:="/bin/sh"}
 
 atf_test_case evaltested
 
@@ -43,7 +45,7 @@ fi
 echo "passed"
 exit 0
 EOF
-	output="$(/bin/sh helper.sh)"
+	output="$($TEST_SH helper.sh)"
 	[ $? = 0 ] && return
 
 	if [ -n "$output" ]

Index: src/tests/bin/sh/t_fsplit.sh
diff -u src/tests/bin/sh/t_fsplit.sh:1.3 src/tests/bin/sh/t_fsplit.sh:1.4
--- src/tests/bin/sh/t_fsplit.sh:1.3	Thu Mar 10 17:30:57 2016
+++ src/tests/bin/sh/t_fsplit.sh	Sun Mar 27 10:50:01 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_fsplit.sh,v 1.3 2016/03/10 22:30:57 christos Exp $
+# $NetBSD: t_fsplit.sh,v 1.4 2016/03/27 14:50:01 christos Exp $
 #
 # Copyright (c) 2007-2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -294,6 +294,11 @@ dollar_at_body() {
 		'zaz zbz zcz'
 	check 'set " a b " c; for i in "$@";do echo "z${i}z"; done' \
 		'z a b z zcz'
+
+	check 'set a b c; for i in "$@$@";  do echo "z${i}z"; done' \
+		'zaz zbz zcaz zbz zcz'
+	check 'set a b c; for i in "$@""$@";do echo "z${i}z"; done' \
+		'zaz zbz zcaz zbz zcz'
 }
 
 atf_test_case ifs

Index: src/tests/bin/sh/t_set_e.sh
diff -u src/tests/bin/sh/t_set_e.sh:1.2 src/tests/bin/sh/t_set_e.sh:1.3
--- src/tests/bin/sh/t_set_e.sh:1.2	Tue Mar  8 09:20:22 2016
+++ src/tests/bin/sh/t_set_e.sh	Sun Mar 27 10:50:01 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_set_e.sh,v 1.2 2016/03/08 14:20:22 christos Exp $
+# $NetBSD: t_set_e.sh,v 1.3 2016/03/27 14:50:01 christos Exp $
 #
 # Copyright (c) 2007 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -81,8 +81,8 @@ all_body() {
 	# first, check basic functioning.
 	# The ERR shouldn't print; the result of the () should be 1.
 	# Henceforth we'll assume that we don't need to check $?.
-	dcheck '(set -e; false; echo ERR$?); echo -n OK$?' 'OK1'
-	echeck '(set -e; false; echo ERR$?); echo -n OK$?' 'OK1'
+	dcheck '(set -e; false; echo ERR$?); echo OK$?' 'OK1'
+	echeck '(set -e; false; echo ERR$?); echo OK$?' 'OK1'
 
 	# these cases should be equivalent to the preceding.
 	dcheck '(set -e; /nonexistent; echo ERR); echo OK' 'OK'
Index: src/tests/bin/sh/t_ulimit.sh
diff -u src/tests/bin/sh/t_ulimit.sh:1.2 src/tests/bin/sh/t_ulimit.sh:1.3
--- src/tests/bin/sh/t_ulimit.sh:1.2	Wed Dec 30 17:24:44 2015
+++ src/tests/bin/sh/t_ulimit.sh	Sun Mar 27 10:50:01 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_ulimit.sh,v 1.2 2015/12/30 22:24:44 christos Exp $
+# $NetBSD: t_ulimit.sh,v 1.3 2016/03/27 14:50:01 christos Exp $
 #
 # Copyright (c) 2012 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -24,6 +24,8 @@
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 # POSSIBILITY OF SUCH DAMAGE.
 #
+# the implementation of "sh" to test
+: ${TEST_SH:="/bin/sh"}
 
 # ulimit builtin test.
 
@@ -33,7 +35,7 @@ limits_head() {
 }
 
 get_ulimits() {
-	local limits=$(ulimit -a |
+	local limits=$(${TEST_SH} -c 'ulimit -a' |
 	sed -e 's/.*\(-[A-Za-z0-9]\)[^A-Za-z0-9].*/\1/' | sort -u)
 	if [ -z "$limits" ]; then
 		# grr ksh
@@ -43,12 +45,10 @@ get_ulimits() {
 }
 
 limits_body() {
-	atf_check -s eq:0 -o ignore -e empty \
-	/bin/sh -c "ulimit -a"
+	atf_check -s eq:0 -o ignore -e empty ${TEST_SH} -c "ulimit -a"
 	for l in $(get_ulimits)
 	do
-	atf_check -s eq:0 -o ignore -e empty \
-	/bin/sh -c "ulimit $l"
+	atf_check -s eq:0 -o ignore -e empty ${TEST_SH} -c "ulimit $l"
 	done
 }
 

Index: src/tests/bin/sh/t_varquote.sh
diff -u src/tests/bin/sh/t_varquote.sh:1.4 src/tests/bin/sh/t_varquote.sh:1.5
--- src/tests/bin/sh/t_varquote.sh:1.4	Sat Mar 12 09:58:03 2016
+++ src/tests/bin/sh/t_varquote.sh	Sun Mar 27 10:50:01 2016
@@ -1,4 +1,4 @@
-# 

CVS commit: src/tests/bin/sh

2016-03-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar 27 14:50:01 UTC 2016

Modified Files:
src/tests/bin/sh: t_evaltested.sh t_fsplit.sh t_set_e.sh t_ulimit.sh
t_varquote.sh

Log Message:
Finish TEST_SH - all tests should support it now.
Misc other KNF changes, minor bug fixes, and a few minor
extra tests added. (from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/bin/sh/t_evaltested.sh
cvs rdiff -u -r1.3 -r1.4 src/tests/bin/sh/t_fsplit.sh
cvs rdiff -u -r1.2 -r1.3 src/tests/bin/sh/t_set_e.sh \
src/tests/bin/sh/t_ulimit.sh
cvs rdiff -u -r1.4 -r1.5 src/tests/bin/sh/t_varquote.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/bin/sh

2016-03-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar 27 14:49:07 UTC 2016

Modified Files:
src/tests/bin/sh: t_redir.sh

Log Message:
Avoid relying on the test shell correctly implementing $(( ))
in order for some of the redirect tests to terminate. (from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/bin/sh/t_redir.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/bin/sh

2016-03-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar 27 14:49:07 UTC 2016

Modified Files:
src/tests/bin/sh: t_redir.sh

Log Message:
Avoid relying on the test shell correctly implementing $(( ))
in order for some of the redirect tests to terminate. (from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/bin/sh/t_redir.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/sh/t_redir.sh
diff -u src/tests/bin/sh/t_redir.sh:1.4 src/tests/bin/sh/t_redir.sh:1.5
--- src/tests/bin/sh/t_redir.sh:1.4	Tue Mar  8 09:26:54 2016
+++ src/tests/bin/sh/t_redir.sh	Sun Mar 27 10:49:07 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_redir.sh,v 1.4 2016/03/08 14:26:54 christos Exp $
+# $NetBSD: t_redir.sh,v 1.5 2016/03/27 14:49:07 christos Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -122,9 +122,7 @@ do_input_redirections_body()
 
 
 	cat <<- 'EOF' |
-		i=0
-		while [ "$i" -lt 3 ]; do
-			i=$((i + 1))
+		for l in 1 2 3; do
 			read line < File
 			echo "$line"
 		done
@@ -134,9 +132,7 @@ do_input_redirections_body()
 		${TEST_SH}
 
 	cat <<- 'EOF' |
-		i=0
-		while [ "$i" -lt 3 ]; do
-			i=$((i + 1))
+		for l in 1 2 3; do
 			read line
 			echo "$line"
 		done /dev/null || :
 	test -f Output && atf_fail "Unable to remove Output file"



CVS commit: src/bin/sh

2016-03-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar 27 14:40:20 UTC 2016

Modified Files:
src/bin/sh: parser.c

Log Message:
Move the parseredir internal subroutine out of readtoken1() into being
a real function of its own (also inspired by FreeBSD - though for
this one other sh differences require slightly different code.) (from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 src/bin/sh/parser.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/sh/parser.c
diff -u src/bin/sh/parser.c:1.111 src/bin/sh/parser.c:1.112
--- src/bin/sh/parser.c:1.111	Sun Mar 27 10:39:33 2016
+++ src/bin/sh/parser.c	Sun Mar 27 10:40:20 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: parser.c,v 1.111 2016/03/27 14:39:33 christos Exp $	*/
+/*	$NetBSD: parser.c,v 1.112 2016/03/27 14:40:20 christos Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)parser.c	8.7 (Berkeley) 5/16/95";
 #else
-__RCSID("$NetBSD: parser.c,v 1.111 2016/03/27 14:39:33 christos Exp $");
+__RCSID("$NetBSD: parser.c,v 1.112 2016/03/27 14:40:20 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -1179,7 +1179,6 @@ cleanup_state_stack(VSS *stack)
 	}
 }
 
-#define	PARSEREDIR()	{goto parseredir; parseredir_return:;}
 #define	PARSESUB()	{goto parsesub; parsesub_return:;}
 #define	PARSEARITH()	{goto parsearith; parsearith_return:;}
 
@@ -1370,6 +1369,94 @@ done:
 	return out;
 }
 
+/*
+ * Parse a redirection operator.  The parameter "out" points to a string
+ * specifying the fd to be redirected.  It is guaranteed to be either ""
+ * or a numeric string (for now anyway).  The parameter "c" contains the
+ * first character of the redirection operator.
+ *
+ * Note the string "out" is on the stack, which we are about to clobber,
+ * so process it first...
+ */
+
+static void
+parseredir(const char *out,  int c)
+{
+	union node *np;
+	int fd;
+
+	fd = (*out == '\0') ? -1 : atoi(out);
+
+	np = stalloc(sizeof(struct nfile));
+	if (c == '>') {
+		if (fd < 0)
+			fd = 1;
+		c = pgetc();
+		if (c == '>')
+			np->type = NAPPEND;
+		else if (c == '|')
+			np->type = NCLOBBER;
+		else if (c == '&')
+			np->type = NTOFD;
+		else {
+			np->type = NTO;
+			pungetc();
+		}
+	} else {	/* c == '<' */
+		if (fd < 0)
+			fd = 0;
+		switch (c = pgetc()) {
+		case '<':
+			if (sizeof (struct nfile) != sizeof (struct nhere)) {
+np = stalloc(sizeof(struct nhere));
+np->nfile.fd = 0;
+			}
+			np->type = NHERE;
+			heredoc = stalloc(sizeof(struct heredoc));
+			heredoc->here = np;
+			if ((c = pgetc()) == '-') {
+heredoc->striptabs = 1;
+			} else {
+heredoc->striptabs = 0;
+pungetc();
+			}
+			break;
+
+		case '&':
+			np->type = NFROMFD;
+			break;
+
+		case '>':
+			np->type = NFROMTO;
+			break;
+
+		default:
+			np->type = NFROM;
+			pungetc();
+			break;
+		}
+	}
+	np->nfile.fd = fd;
+
+	redirnode = np;		/* this is the "value" of TRENODE */
+}
+
+
+/*
+ * The lowest level basic tokenizer.
+ *
+ * The next input byte (character) is in firstc, syn says which
+ * syntax tables we are to use (basic, single or double quoted, or arith)
+ * and magicq (used with sqsyntax and dqsyntax only) indicates that the
+ * quote character itself is not special (used parsing here docs and similar)
+ *
+ * The result is the type of the next token (its value, when there is one,
+ * is saved in the relevant global var - must fix that someday!) which is
+ * also saved for re-reading ("lasttoken").
+ *
+ * Overall, this routine does far more parsing than it is supposed to.
+ * That will also need fixing, someday...
+ */
 STATIC int
 readtoken1(int firstc, char const *syn, int magicq)
 {
@@ -1573,7 +1660,7 @@ endword:
 		if ((c == '<' || c == '>')
 		 && quotef == 0
 		 && (*out == '\0' || is_number(out))) {
-			PARSEREDIR();
+			parseredir(out, c);
 			cleanup_state_stack(stack);
 			return lasttoken = TREDIR;
 		} else {
@@ -1590,71 +1677,6 @@ endword:
 
 
 /*
- * Parse a redirection operator.  The variable "out" points to a string
- * specifying the fd to be redirected.  The variable "c" contains the
- * first character of the redirection operator.
- */
-
-parseredir: {
-	char fd[64];
-	union node *np;
-	strlcpy(fd, out, sizeof(fd));
-
-	np = stalloc(sizeof(struct nfile));
-	if (c == '>') {
-		np->nfile.fd = 1;
-		c = pgetc();
-		if (c == '>')
-			np->type = NAPPEND;
-		else if (c == '|')
-			np->type = NCLOBBER;
-		else if (c == '&')
-			np->type = NTOFD;
-		else {
-			np->type = NTO;
-			pungetc();
-		}
-	} else {	/* c == '<' */
-		np->nfile.fd = 0;
-		switch (c = pgetc()) {
-		case '<':
-			if (sizeof (struct nfile) != sizeof (struct nhere)) {
-np = stalloc(sizeof(struct nhere));
-np->nfile.fd = 0;
-			}
-			np->type = NHERE;
-			heredoc = stalloc(sizeof(struct heredoc));
-			heredoc->here = np;
-			if ((c = pgetc()) == '-') {
-heredoc->striptabs = 1;
-			} else {
-heredoc->striptabs = 

CVS commit: src/bin/sh

2016-03-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar 27 14:40:20 UTC 2016

Modified Files:
src/bin/sh: parser.c

Log Message:
Move the parseredir internal subroutine out of readtoken1() into being
a real function of its own (also inspired by FreeBSD - though for
this one other sh differences require slightly different code.) (from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 src/bin/sh/parser.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/bin/sh

2016-03-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar 27 14:39:33 UTC 2016

Modified Files:
src/bin/sh: expand.c parser.c parser.h

Log Message:
PR bin/50993 - this is a significant rewrite of the way that here
documents are processed.  Now, when first detected, they are
simply read (the only change made to the text is to join lines
ended with a \ to the subsequent line, otherwise end marker detection
does not work correctly (for here docs with an unquoted endmarker
only of course.)  This patch also moves the "internal subroutine"
for looking for the end marker out of readtoken1() (which had to
happen as readtoken1 is no longer reading the here doc when it is
needed) - that uses code mostly taken from FreeBSD's sh (thanks!)
and along the way results in some restrictions on what the end
marker can be being removed.   We still do not allow all we should.
(from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/bin/sh/expand.c
cvs rdiff -u -r1.110 -r1.111 src/bin/sh/parser.c
cvs rdiff -u -r1.19 -r1.20 src/bin/sh/parser.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/sh/expand.c
diff -u src/bin/sh/expand.c:1.98 src/bin/sh/expand.c:1.99
--- src/bin/sh/expand.c:1.98	Sun Mar 27 10:34:46 2016
+++ src/bin/sh/expand.c	Sun Mar 27 10:39:33 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: expand.c,v 1.98 2016/03/27 14:34:46 christos Exp $	*/
+/*	$NetBSD: expand.c,v 1.99 2016/03/27 14:39:33 christos Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)expand.c	8.5 (Berkeley) 5/15/95";
 #else
-__RCSID("$NetBSD: expand.c,v 1.98 2016/03/27 14:34:46 christos Exp $");
+__RCSID("$NetBSD: expand.c,v 1.99 2016/03/27 14:39:33 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -121,6 +121,12 @@ STATIC char *cvtnum(int, char *);
 void
 expandhere(union node *arg, int fd)
 {
+	/*
+	 * First, parse the content of the here doc (to internal form)
+	 * It was initially saved as (almost) unmodified text.
+	 */
+	parse_heredoc(arg);
+
 	herefd = fd;
 	expandarg(arg, NULL, 0);
 	xwrite(fd, stackblock(), expdest - stackblock());

Index: src/bin/sh/parser.c
diff -u src/bin/sh/parser.c:1.110 src/bin/sh/parser.c:1.111
--- src/bin/sh/parser.c:1.110	Sun Mar 27 10:36:29 2016
+++ src/bin/sh/parser.c	Sun Mar 27 10:39:33 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: parser.c,v 1.110 2016/03/27 14:36:29 christos Exp $	*/
+/*	$NetBSD: parser.c,v 1.111 2016/03/27 14:39:33 christos Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)parser.c	8.7 (Berkeley) 5/16/95";
 #else
-__RCSID("$NetBSD: parser.c,v 1.110 2016/03/27 14:36:29 christos Exp $");
+__RCSID("$NetBSD: parser.c,v 1.111 2016/03/27 14:39:33 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -69,8 +69,6 @@ __RCSID("$NetBSD: parser.c,v 1.110 2016/
  * Shell command parser.
  */
 
-#define EOFMARKLEN 79
-
 /* values returned by readtoken */
 #include "token.h"
 
@@ -111,11 +109,12 @@ STATIC union node *command(void);
 STATIC union node *simplecmd(union node **, union node *);
 STATIC union node *makename(void);
 STATIC void parsefname(void);
-STATIC void parseheredoc(void);
+STATIC void slurp_heredoc(char *const, int, int);
+STATIC void readheredocs(void);
 STATIC int peektoken(void);
 STATIC int readtoken(void);
 STATIC int xxreadtoken(void);
-STATIC int readtoken1(int, char const *, char *, int);
+STATIC int readtoken1(int, char const *, int);
 STATIC int noexpand(char *);
 STATIC void synexpect(int, const char *) __dead;
 STATIC void synerror(const char *) __dead;
@@ -196,7 +195,7 @@ list(int nlflag, int erflag)
 			/* FALLTHROUGH */
 		case TNL:
 			if (tok == TNL) {
-parseheredoc();
+readheredocs();
 if (nlflag)
 	return n1;
 			} else {
@@ -208,7 +207,7 @@ list(int nlflag, int erflag)
 			break;
 		case TEOF:
 			if (heredoclist)
-parseheredoc();
+readheredocs();
 			else
 pungetc();	/* push back EOF on input */
 			return n1;
@@ -671,7 +670,6 @@ parsefname(void)
 	if (n->type == NHERE) {
 		struct heredoc *here = heredoc;
 		struct heredoc *p;
-		int i;
 
 		if (quoteflag == 0)
 			n->type = NXHERE;
@@ -680,8 +678,21 @@ parsefname(void)
 			while (*wordtext == '\t')
 wordtext++;
 		}
-		if (! noexpand(wordtext) || (i = strlen(wordtext)) == 0 || i > EOFMARKLEN)
+
+		/*
+		 * this test is not really necessary, we are not
+		 * required to expand wordtext, but there's no reason
+		 * it cannot be $$ or something like that - that would
+		 * not mean the pid, but literally two '$' characters.
+		 * There is no need for limits on what the word can be.
+		 * However, it needs to stay literal as entered, not
+		 * have $ converted to CTLVAR or something, which as
+		 * the parser is, at the minute, is impossible to prevent.
+		 * So, leave it like this until the rest of the parser is fixed.
+		 */
+		if (! noexpand(wordtext))
 			synerror("Illegal 

CVS commit: src/bin/sh

2016-03-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar 27 14:39:33 UTC 2016

Modified Files:
src/bin/sh: expand.c parser.c parser.h

Log Message:
PR bin/50993 - this is a significant rewrite of the way that here
documents are processed.  Now, when first detected, they are
simply read (the only change made to the text is to join lines
ended with a \ to the subsequent line, otherwise end marker detection
does not work correctly (for here docs with an unquoted endmarker
only of course.)  This patch also moves the "internal subroutine"
for looking for the end marker out of readtoken1() (which had to
happen as readtoken1 is no longer reading the here doc when it is
needed) - that uses code mostly taken from FreeBSD's sh (thanks!)
and along the way results in some restrictions on what the end
marker can be being removed.   We still do not allow all we should.
(from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/bin/sh/expand.c
cvs rdiff -u -r1.110 -r1.111 src/bin/sh/parser.c
cvs rdiff -u -r1.19 -r1.20 src/bin/sh/parser.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/bin/sh

2016-03-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar 27 14:36:29 UTC 2016

Modified Files:
src/bin/sh: parser.c

Log Message:
Cease "support" for  fn() { ...
Any redirect (or redirects) before a function definition were
allowed by the parser, but otherwise totally ignored.  The standard
syntax does not permit redirects there, now, neither do we. (from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.109 -r1.110 src/bin/sh/parser.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/sh/parser.c
diff -u src/bin/sh/parser.c:1.109 src/bin/sh/parser.c:1.110
--- src/bin/sh/parser.c:1.109	Sun Mar 27 10:35:30 2016
+++ src/bin/sh/parser.c	Sun Mar 27 10:36:29 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: parser.c,v 1.109 2016/03/27 14:35:30 christos Exp $	*/
+/*	$NetBSD: parser.c,v 1.110 2016/03/27 14:36:29 christos Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)parser.c	8.7 (Berkeley) 5/16/95";
 #else
-__RCSID("$NetBSD: parser.c,v 1.109 2016/03/27 14:35:30 christos Exp $");
+__RCSID("$NetBSD: parser.c,v 1.110 2016/03/27 14:36:29 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -560,7 +560,6 @@ STATIC union node *
 simplecmd(union node **rpp, union node *redir)
 {
 	union node *args, **app;
-	union node **orig_rpp = rpp;
 	union node *n = NULL, *n2;
 	int negate = 0;
 
@@ -571,12 +570,6 @@ simplecmd(union node **rpp, union node *
 
 	args = NULL;
 	app = 
-	/*
-	 * We save the incoming value, because we need this for shell
-	 * functions.  There can not be a redirect or an argument between
-	 * the function name and the open parenthesis.
-	 */
-	orig_rpp = rpp;
 
 	while (readtoken() == TNOT) {
 		TRACE(("simplcmd: TNOT recognized\n"));
@@ -597,7 +590,7 @@ simplecmd(union node **rpp, union node *
 			rpp = >nfile.next;
 			parsefname();	/* read name of redirection file */
 		} else if (lasttoken == TLP && app == >narg.next
-	&& rpp == orig_rpp) {
+	&& redir == 0) {
 			/* We have a function */
 			if (readtoken() != TRP)
 synexpect(TRP, 0);



CVS commit: src/bin/sh

2016-03-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar 27 14:36:29 UTC 2016

Modified Files:
src/bin/sh: parser.c

Log Message:
Cease "support" for  fn() { ...
Any redirect (or redirects) before a function definition were
allowed by the parser, but otherwise totally ignored.  The standard
syntax does not permit redirects there, now, neither do we. (from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.109 -r1.110 src/bin/sh/parser.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/bin/sh

2016-03-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar 27 14:35:30 UTC 2016

Modified Files:
src/bin/sh: parser.c

Log Message:
Finish constifying the new parsebackquote() function.  Save a
variable or two...   Should change nothing. (from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.108 -r1.109 src/bin/sh/parser.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/sh/parser.c
diff -u src/bin/sh/parser.c:1.108 src/bin/sh/parser.c:1.109
--- src/bin/sh/parser.c:1.108	Sun Mar 27 10:34:46 2016
+++ src/bin/sh/parser.c	Sun Mar 27 10:35:30 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: parser.c,v 1.108 2016/03/27 14:34:46 christos Exp $	*/
+/*	$NetBSD: parser.c,v 1.109 2016/03/27 14:35:30 christos Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)parser.c	8.7 (Berkeley) 5/16/95";
 #else
-__RCSID("$NetBSD: parser.c,v 1.108 2016/03/27 14:34:46 christos Exp $");
+__RCSID("$NetBSD: parser.c,v 1.109 2016/03/27 14:35:30 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -1091,18 +1091,16 @@ parsebackq(VSS *const stack, char * cons
 struct nodelist **const pbqlist, const int oldstyle)
 {
 	struct nodelist **nlpp;
-	int savepbq;
+	const int savepbq = parsebackquote;
 	union node *n;
 	char *out;
 	char *str = NULL;
-	char *pout;
 	char *volatile sstr = str;
 	struct jmploc jmploc;
 	struct jmploc *const savehandler = handler;
-	int savelen;
+	const int savelen = in - stackblock();
 	int saveprompt;
 
-	savepbq = parsebackquote;
 	if (setjmp(jmploc.loc)) {
 		if (sstr)
 			ckfree(__UNVOLATILE(sstr));
@@ -1112,9 +1110,7 @@ parsebackq(VSS *const stack, char * cons
 		longjmp(handler->loc, 1);
 	}
 	INTOFF;
-	out = in;
 	sstr = str = NULL;
-	savelen = out - stackblock();
 	if (savelen > 0) {
 		sstr = str = ckmalloc(savelen);
 		memcpy(str, stackblock(), savelen);
@@ -1134,7 +1130,7 @@ parsebackq(VSS *const stack, char * cons
 		 * need to bother the state stack.  That will be used
 		 * (as appropriate) when the processed string is re-read.
 		 */
-STARTSTACKSTR(pout);
+STARTSTACKSTR(out);
 		for (;;) {
 			if (needprompt) {
 setprompt(2);
@@ -1161,7 +1157,7 @@ parsebackq(VSS *const stack, char * cons
 }
 if (pc != '\\' && pc != '`' && pc != '$'
 && (!ISDBLQUOTE() || pc != '"'))
-STPUTC('\\', pout);
+STPUTC('\\', out);
 break;
 
 			case '\n':
@@ -1177,13 +1173,13 @@ parsebackq(VSS *const stack, char * cons
 			default:
 break;
 			}
-			STPUTC(pc, pout);
+			STPUTC(pc, out);
 }
 done:
-STPUTC('\0', pout);
-psavelen = pout - stackblock();
+STPUTC('\0', out);
+psavelen = out - stackblock();
 if (psavelen > 0) {
-			pstr = grabstackstr(pout);
+			pstr = grabstackstr(out);
 			setinputstring(pstr, 1);
 }
 }
@@ -1220,12 +1216,13 @@ done:
 popfile();
 		tokpushback = 0;
 	}
+
 	while (stackblocksize() <= savelen)
 		growstackblock();
-	STARTSTACKSTR(pout);
+	STARTSTACKSTR(out);
 	if (str) {
-		memcpy(pout, str, savelen);
-		STADJUST(savelen, pout);
+		memcpy(out, str, savelen);
+		STADJUST(savelen, out);
 		INTOFF;
 		ckfree(str);
 		sstr = str = NULL;
@@ -1234,11 +1231,11 @@ done:
 	parsebackquote = savepbq;
 	handler = savehandler;
 	if (arinest || ISDBLQUOTE())
-		USTPUTC(CTLBACKQ | CTLQUOTE, pout);
+		USTPUTC(CTLBACKQ | CTLQUOTE, out);
 	else
-		USTPUTC(CTLBACKQ, pout);
+		USTPUTC(CTLBACKQ, out);
 
-	return pout;
+	return out;
 }
 
 STATIC int



CVS commit: src/bin/sh

2016-03-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar 27 14:35:30 UTC 2016

Modified Files:
src/bin/sh: parser.c

Log Message:
Finish constifying the new parsebackquote() function.  Save a
variable or two...   Should change nothing. (from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.108 -r1.109 src/bin/sh/parser.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/bin/sh

2016-03-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar 27 14:34:46 UTC 2016

Modified Files:
src/bin/sh: expand.c input.c main.c mkinit.sh mknodenames.sh parser.c
var.c var.h

Log Message:
General KNF and source code cleanups, avoid scattering the
magic string " \t\n" all over the place, slightly improved
syntax error messages, restructured some of the code for
clarity, don't allow IFS to be imported through the environment,
and remove the (never) conditionally compiled ATTY option.
Apart from one or two syntax error messages, and ignoring IFS
if present in the environment, this is intended to have no
user visible changes. (from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 src/bin/sh/expand.c
cvs rdiff -u -r1.47 -r1.48 src/bin/sh/input.c src/bin/sh/var.c
cvs rdiff -u -r1.62 -r1.63 src/bin/sh/main.c
cvs rdiff -u -r1.6 -r1.7 src/bin/sh/mkinit.sh
cvs rdiff -u -r1.2 -r1.3 src/bin/sh/mknodenames.sh
cvs rdiff -u -r1.107 -r1.108 src/bin/sh/parser.c
cvs rdiff -u -r1.26 -r1.27 src/bin/sh/var.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/sh/expand.c
diff -u src/bin/sh/expand.c:1.97 src/bin/sh/expand.c:1.98
--- src/bin/sh/expand.c:1.97	Wed Mar 16 11:44:35 2016
+++ src/bin/sh/expand.c	Sun Mar 27 10:34:46 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: expand.c,v 1.97 2016/03/16 15:44:35 christos Exp $	*/
+/*	$NetBSD: expand.c,v 1.98 2016/03/27 14:34:46 christos Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)expand.c	8.5 (Berkeley) 5/15/95";
 #else
-__RCSID("$NetBSD: expand.c,v 1.97 2016/03/16 15:44:35 christos Exp $");
+__RCSID("$NetBSD: expand.c,v 1.98 2016/03/27 14:34:46 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -193,7 +193,7 @@ argstr(char *p, int flag)
 	int ifs_split = EXP_IFS_SPLIT;
 
 	if (flag & EXP_IFS_SPLIT)
-		ifs = ifsset() ? ifsval() : " \t\n";
+		ifs = ifsval();
 
 	if (*p == '~' && (flag & (EXP_TILDE | EXP_VARTILDE)))
 		p = exptilde(p, flag);
@@ -705,7 +705,6 @@ again: /* jump here after setting a vari
 		STPUTC(CTLESC, expdest);
 	STPUTC(*val++, expdest);
 }
-
 			}
 		}
 	}
@@ -924,10 +923,7 @@ numvar:
 		}
 		/* fall through */
 	case '*':
-		if (ifsset() != 0)
-			sep = ifsval()[0];
-		else
-			sep = ' ';
+		sep = ifsval()[0];
 		for (ap = shellparam.p ; (p = *ap++) != NULL ; ) {
 			STRTODEST(p);
 			if (*ap && sep)
@@ -1011,7 +1007,7 @@ ifsbreakup(char *string, struct arglist 
 		return;
 	}
 
-	ifs = ifsset() ? ifsval() : " \t\n";
+	ifs = ifsval();
 
 	for (ifsp =  ifsp != NULL; ifsp = ifsp->next) {
 		p = string + ifsp->begoff;

Index: src/bin/sh/input.c
diff -u src/bin/sh/input.c:1.47 src/bin/sh/input.c:1.48
--- src/bin/sh/input.c:1.47	Sun Jan  3 22:00:24 2016
+++ src/bin/sh/input.c	Sun Mar 27 10:34:46 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: input.c,v 1.47 2016/01/04 03:00:24 christos Exp $	*/
+/*	$NetBSD: input.c,v 1.48 2016/03/27 14:34:46 christos Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)input.c	8.3 (Berkeley) 6/9/95";
 #else
-__RCSID("$NetBSD: input.c,v 1.47 2016/01/04 03:00:24 christos Exp $");
+__RCSID("$NetBSD: input.c,v 1.48 2016/03/27 14:34:46 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -453,6 +453,7 @@ setinputfd(int fd, int push)
 void
 setinputstring(char *string, int push)
 {
+
 	INTOFF;
 	if (push)
 		pushfile();
Index: src/bin/sh/var.c
diff -u src/bin/sh/var.c:1.47 src/bin/sh/var.c:1.48
--- src/bin/sh/var.c:1.47	Tue Mar  8 18:24:51 2016
+++ src/bin/sh/var.c	Sun Mar 27 10:34:46 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.47 2016/03/08 23:24:51 christos Exp $	*/
+/*	$NetBSD: var.c,v 1.48 2016/03/27 14:34:46 christos Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)var.c	8.3 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: var.c,v 1.47 2016/03/08 23:24:51 christos Exp $");
+__RCSID("$NetBSD: var.c,v 1.48 2016/03/27 14:34:46 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -87,9 +87,6 @@ struct varinit {
 
 struct localvar *localvars;
 
-#if ATTY
-struct var vatty;
-#endif
 #ifndef SMALL
 struct var vhistsize;
 struct var vterm;
@@ -103,11 +100,9 @@ struct var vps2;
 struct var vps4;
 struct var voptind;
 
+char ifs_default[] = " \t\n";
+
 const struct varinit varinit[] = {
-#if ATTY
-	{ ,	VSTRFIXED|VTEXTFIXED|VUNSET,	"ATTY=",
-	  NULL },
-#endif
 #ifndef SMALL
 	{ ,	VSTRFIXED|VTEXTFIXED|VUNSET,	"HISTSIZE=",
 	  sethistsize },
@@ -162,13 +157,14 @@ INIT {
 		}
 	}
 
-
 	/*
 	 * PPID is readonly
 	 *	set after processing environ to override anything there
+	 * Always default IFS, ignore any value from environment.
 	 */
 	snprintf(buf, sizeof(buf), "%d", (int)getppid());
 	setvar("PPID", buf, VREADONLY);
+	setvar("IFS", ifs_default, VTEXTFIXED);
 }
 #endif
 

Index: src/bin/sh/main.c
diff -u src/bin/sh/main.c:1.62 src/bin/sh/main.c:1.63
--- 

CVS commit: src/bin/sh

2016-03-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar 27 14:34:46 UTC 2016

Modified Files:
src/bin/sh: expand.c input.c main.c mkinit.sh mknodenames.sh parser.c
var.c var.h

Log Message:
General KNF and source code cleanups, avoid scattering the
magic string " \t\n" all over the place, slightly improved
syntax error messages, restructured some of the code for
clarity, don't allow IFS to be imported through the environment,
and remove the (never) conditionally compiled ATTY option.
Apart from one or two syntax error messages, and ignoring IFS
if present in the environment, this is intended to have no
user visible changes. (from kre@)


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 src/bin/sh/expand.c
cvs rdiff -u -r1.47 -r1.48 src/bin/sh/input.c src/bin/sh/var.c
cvs rdiff -u -r1.62 -r1.63 src/bin/sh/main.c
cvs rdiff -u -r1.6 -r1.7 src/bin/sh/mkinit.sh
cvs rdiff -u -r1.2 -r1.3 src/bin/sh/mknodenames.sh
cvs rdiff -u -r1.107 -r1.108 src/bin/sh/parser.c
cvs rdiff -u -r1.26 -r1.27 src/bin/sh/var.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/share/mk

2016-03-27 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Mar 27 10:46:41 UTC 2016

Modified Files:
src/share/mk: bsd.own.mk

Log Message:
Switch hppa to gcc 5.3


To generate a diff of this commit:
cvs rdiff -u -r1.912 -r1.913 src/share/mk/bsd.own.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/mk/bsd.own.mk
diff -u src/share/mk/bsd.own.mk:1.912 src/share/mk/bsd.own.mk:1.913
--- src/share/mk/bsd.own.mk:1.912	Sat Mar 26 10:38:22 2016
+++ src/share/mk/bsd.own.mk	Sun Mar 27 10:46:41 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: bsd.own.mk,v 1.912 2016/03/26 10:38:22 mrg Exp $
+#	$NetBSD: bsd.own.mk,v 1.913 2016/03/27 10:46:41 skrll Exp $
 
 # This needs to be before bsd.init.mk
 .if defined(BSD_MK_COMPAT_FILE)
@@ -63,7 +63,10 @@ MKGCC?=		no
 
 .if ${MACHINE_CPU} == "aarch64"
 HAVE_GCC?=	0
-.elif ${MACHINE_ARCH} == "vax" || ${MACHINE} == "playstation2"
+.elif \
+${MACHINE_ARCH} == "hppa" || \
+${MACHINE} == "playstation2" || \
+${MACHINE_ARCH} == "vax"
 HAVE_GCC?=	53
 .else
 # Otherwise, default to GCC4.8



CVS commit: src/share/mk

2016-03-27 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Mar 27 10:46:41 UTC 2016

Modified Files:
src/share/mk: bsd.own.mk

Log Message:
Switch hppa to gcc 5.3


To generate a diff of this commit:
cvs rdiff -u -r1.912 -r1.913 src/share/mk/bsd.own.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.