]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
contrib: Fix exit status of relpath.sh for invalid args [PR125956]
authorJonathan Wakely <jwakely@redhat.com>
Wed, 24 Jun 2026 20:50:24 +0000 (21:50 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Thu, 16 Jul 2026 13:08:53 +0000 (14:08 +0100)
The relpath.sh script always writes its usage message to stdout and
exits with zero status, even for invalid arguments. This caused a
problem for libstdc++-v3/src/c++23/Makefile which assumed that
relpath.sh won't exit successfully on error, via:

relpath=$(relpath.sh ...) && sed 's,@MODPATH@,$$relpath,' ...

Because relpath.sh exits successfully for invalid args, the sed command
still ran even when relpath.sh was invoked incorrectly.

The libstdc++ Makefile has been changed to work around this, but
relpath.sh should still have an idiomatic exit status.

contrib/ChangeLog:

PR libstdc++/125956
* relpath.sh: For invalid arguments write to stderr and exit
with non-zero status.

contrib/relpath.sh

index 1b329fc04a78e9c273d0c29bbe194c745a703c7f..286e7f1a1752593fdf73a71eb44c899baf222ce6 100755 (executable)
@@ -1,10 +1,18 @@
 #!/bin/sh
 
-if [ "$1" = "--help" -o $# -ne 2 -o -f "$1" ]; then
+usage()
+{
     echo Usage: relpath.sh FROM TO
     echo Print the relative path from FROM to TO
     echo FROM must be a directory, but need not exist
+}
+
+if [ "$1" = "--help" ]; then
+    usage
     exit 0
+elif [ $# -ne 2 -o -f "$1" ]; then
+    usage >&2
+    exit 1
 fi
 
 from="${1%%/}"