Bug 91811

Summary: startx uses GNUism "expr match", causing errors on non-GNU systems
Product: xorg Reporter: Jens Schweikhardt <schweikh>
Component: App/xinitAssignee: Xorg Project Team <xorg-team>
Status: RESOLVED FIXED QA Contact: Xorg Project Team <xorg-team>
Severity: normal    
Priority: medium    
Version: 7.7 (2012.06)   
Hardware: Other   
OS: FreeBSD   
Whiteboard:
i915 platform: i915 features:

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.