Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-8]: src/bin/sh Pull up following revision(s) (requested by kre in...
details: https://anonhg.NetBSD.org/src/rev/0f33f3e2494a
branches: netbsd-8
changeset: 445288:0f33f3e2494a
user: martin <martin%NetBSD.org@localhost>
date: Sun Oct 21 12:00:32 2018 +0000
description:
Pull up following revision(s) (requested by kre in ticket #1067):
bin/sh/mkinit.sh: revision 1.9
Dynamically detect the way the shell matches \ in a pattern,
and use whatever works for the sh running this script. Previously
we were using the (broken, and incorrect) method that worked in
old broken NetBSD sh's (and some others) and not the method that
works with the current (fixed) /bin/sh and other correct shells
(like bash). (For an exotic reason, in the particular use case,
both methods work with ksh93, but it is also generally correct).
This hasn't really mattered, as the difference is only significant
(only causes actual issues - the build fails) when compiling with DEBUG
enabled, which is something that most sane humans would never do, if they
want to retain that sanity.
The problem was detected by Patrick Welche when looking for an
unrelated problem, which was once considered to be a possible sh
problem, but turned out to be something entirely different.
XXX pullup -8
diffstat:
bin/sh/mkinit.sh | 34 ++++++++++++++++++++++++++++++++--
1 files changed, 32 insertions(+), 2 deletions(-)
diffs (49 lines):
diff -r d93a51645f1c -r 0f33f3e2494a bin/sh/mkinit.sh
--- a/bin/sh/mkinit.sh Sun Oct 21 11:55:54 2018 +0000
+++ b/bin/sh/mkinit.sh Sun Oct 21 12:00:32 2018 +0000
@@ -1,5 +1,5 @@
#! /bin/sh
-# $NetBSD: mkinit.sh,v 1.7 2016/03/27 14:34:46 christos Exp $
+# $NetBSD: mkinit.sh,v 1.7.8.1 2018/10/21 12:00:32 martin Exp $
# Copyright (c) 2003 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -33,7 +33,37 @@
nl='
'
openparen='('
-backslash='\'
+
+# shells have bugs (including older NetBSD sh) in how \ is
+# used in pattern matching. So work out what the shell
+# running this script expects. We could also just use a
+# literal \ in the pattern, which would need to be quoted
+# of course, but then we'd run into a whole host of potential
+# other shell bugs (both with the quoting in the pattern, and
+# with the matching that follows if that works as inended).
+# Far easier, and more reliable, is to just work out what works,
+# and then use it, which more or less mandates using a variable...
+backslash='\\'
+var='abc\' # dummy test case.
+if [ "$var" = "${var%$backslash}" ]
+then
+ # buggy sh, try the broken way
+ backslash='\'
+ if [ "$var" = "${var%$backslash}" ]
+ then
+ printf >&2 "$0: %s\n" 'No pattern match with \ (broken shell)'
+ exit 1
+ fi
+fi
+# We know we can detect the presence of a trailing \, which is all we need.
+# Now to confirm we will not generate false matches.
+var='abc'
+if [ "$var" != "${var%$backslash}" ]
+then
+ printf >&2 "$0: %s\n" 'Bogus pattern match with \ (broken shell)'
+ exit 1
+fi
+unset var
includes=' "shell.h" "mystring.h" "init.h" '
defines=
Home |
Main Index |
Thread Index |
Old Index