Bug 91811 - startx uses GNUism "expr match", causing errors on non-GNU systems
Summary: startx uses GNUism "expr match", causing errors on non-GNU systems
Status: RESOLVED FIXED
Alias: None
Product: xorg
Classification: Unclassified
Component: App/xinit (show other bugs)
Version: 7.7 (2012.06)
Hardware: Other FreeBSD
: medium normal
Assignee: Xorg Project Team
QA Contact: Xorg Project Team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-08-30 13:12 UTC by Jens Schweikhardt
Modified: 2017-03-23 19:22 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description Jens Schweikhardt 2015-08-30 13:12:08 UTC
The startx script uses the expr(1) command with the "match" operator.
This is a GNUism not understood by FreeBSD's /bin/sh or expr.

In particular this part causes error reports by expr:

# if no vt is specified add vtarg (which may be empty)
have_vtarg="no"
for i in $serverargs; do
    if expr match "$i" '^vt[0-9]\+$' > /dev/null; then
        have_vtarg="yes"
    fi
done


The more portable way to do this is

    if expr "x$i" : 'xvt[0-9][0-9]*$' >/dev/null; then

which also deals with
 * $i being an option like -s which otherwise also causes an error
 * not using the redundant undefined behavior of the ^ anchor
 * avoiding the non-portable \+ quantor

A similar correction should be applied to

	    # display must be the FIRST server argument
	    if [ x"$serverargs" = x ] && \
		 expr "$1" : ':[0-9][0-9]*$' > /dev/null 2>&1; then
		display="$1"
	    else
		serverargs="$serverargs $1"
	    fi

if $1 in the expr command may start with a "-".
Comment 1 Eric Engestrom 2017-03-23 19:22:53 UTC
This was fixed by:

commit e3bab0cc706880c22f2b205e7abad9d8c0227071
Author: Mark Kettenis <kettenis@openbsd.org>
Date:   Thu Jan 29 11:23:01 2015 +0100

    startx: Don't use GNU expr extensions

    Use the ':' operator instead of "match" and avoid the use of "\+".  Both
    constructions aren't specified by POSIX and not supported in BSD expr.
    Also drop the '^' from the regular expressions as it is implicit and
    POSIX leaves its behaviour undefined.

    Signed-off-by: Mark Kettenis <kettenis@openbsd.org>
    Acked-by: Hans de Goede <hdegoede@redhat.com>
    Reviewed-by: Matthieu Herrb <matthieu@herrb.eu>


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.