From 07b240d4f945a47a3b35ccf52b9efbe52a337796 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Mon, 3 Aug 2020 23:52:41 +0000 Subject: [PATCH] src/cmd/INIT: allow compiling on system with noexec /tmp Some systems disallow executing files in /tmp and there is nothing regular users can do about it. The build would fail with a misleading error message about cc being a cross-compiler. This commit makes the build system consistently use $TMPDIR with /tmp as a fallback if that variable is not defined. This allows the user to use another temporary directory with execute permission. The error message in bin/package is also extended to signal the possibility of a noexec temp dir. --- bin/mamprobe | 8 ++++---- bin/package | 23 ++++++++++++++--------- src/cmd/INIT/filter.sh | 4 +++- src/cmd/INIT/mamake.c | 2 +- src/cmd/INIT/mamprobe.sh | 8 ++++---- src/cmd/INIT/package.sh | 23 ++++++++++++++--------- 6 files changed, 40 insertions(+), 28 deletions(-) diff --git a/bin/mamprobe b/bin/mamprobe index 1257dfcb7..5988b8975 100755 --- a/bin/mamprobe +++ b/bin/mamprobe @@ -197,7 +197,7 @@ esac case $info in -) ;; -*) tmp=/tmp/mam$$ +*) tmp=${TMPDIR:-/tmp}/mam$$ trap "exec >/dev/null; rm -f $tmp" 0 1 2 3 15 exec > $tmp echo "probing C language processor $cc for mam information" >&2 @@ -268,8 +268,8 @@ done case $info in -) ;; *) exec >/dev/null - test -f $info && rm -f $info - cp $tmp $info - chmod -w $info + test -f "$info" && rm -f "$info" + cp "$tmp" "$info" + chmod -w "$info" ;; esac diff --git a/bin/package b/bin/package index 66fa89255..06d9184cd 100755 --- a/bin/package +++ b/bin/package @@ -59,6 +59,9 @@ esac LC_ALL=C export LC_ALL +TMPDIR=${TMPDIR:-/tmp} +export TMPDIR + src="cmd contrib etc lib" use="/usr/common /exp /usr/local /usr/add-on /usr/addon /usr/tools /usr /opt" usr="/home" @@ -1783,7 +1786,7 @@ hostinfo() # attribute ... esac case $cpu in 0|1) cpu=`( - cd ${TMPDIR:-/tmp} + cd "$TMPDIR" tmp=hi$$ trap 'rm -f $tmp.*' 0 1 2 cat > $tmp.c < $tmp.c < $tmp.a.c </dev/null` in *universal*64* | *64-bit* | *x86[_-]64*) pwd=`pwd` - cd ${TMPDIR:-/tmp} + cd "$TMPDIR" tmp=hi$$ trap 'rm -f $tmp.*' 0 1 2 cat > $tmp.a.c < pkg$$.e 2>&1 || { if $cc -Dnew=old -o pkg$$.exe pkg$$.c > /dev/null 2>&1 @@ -3050,6 +3053,8 @@ cat $INITROOT/$i.sh $EXECTYPE) echo "$command: $CC: seems to be a cross-compiler" >&2 echo "$command: set HOSTTYPE to something other than the native $EXECTYPE" >&2 + echo "$command: If not, your $TMPDIR directory may be mounted without execute permission." >&2 + echo "$command: Try exporting TMPDIR as a directory where you can execute binary files." >&2 exit 1 ;; esac @@ -3214,10 +3219,10 @@ cygwin.*) lose=ntsec ;; *ntsec*);; - *) exe=/tmp/pkg$$.exe - rm -f $exe - : > $exe - if test -x $exe + *) exe=$TMPDIR/pkg$$.exe + rm -f "$exe" + : > "$exe" + if test -x "$exe" then lose=ntsec fi ;; diff --git a/src/cmd/INIT/filter.sh b/src/cmd/INIT/filter.sh index 2637a5848..e2ad93680 100644 --- a/src/cmd/INIT/filter.sh +++ b/src/cmd/INIT/filter.sh @@ -21,7 +21,9 @@ command=filter -tmp=/tmp/$command$$ +TMPDIR=${TMPDIR:-/tmp} +export TMPDIR +tmp=$TMPDIR/$command$$ suf= case `(getopts '[-][123:xyz]' opt --xyz; echo 0$opt) 2>/dev/null` in diff --git a/src/cmd/INIT/mamake.c b/src/cmd/INIT/mamake.c index d1dcefdf7..60738e7d3 100644 --- a/src/cmd/INIT/mamake.c +++ b/src/cmd/INIT/mamake.c @@ -1518,7 +1518,7 @@ require(char* lib, int dontcare) else if (dontcare) { append(tmp, "set -\n"); - append(tmp, "cd /tmp\n"); + append(tmp, "cd \"${TMPDIR:-/tmp}\"\n"); append(tmp, "echo 'int main(){return 0;}' > x.${!-$$}.c\n"); append(tmp, "${CC} ${CCFLAGS} -o x.${!-$$}.x x.${!-$$}.c "); append(tmp, r); diff --git a/src/cmd/INIT/mamprobe.sh b/src/cmd/INIT/mamprobe.sh index 1257dfcb7..5988b8975 100644 --- a/src/cmd/INIT/mamprobe.sh +++ b/src/cmd/INIT/mamprobe.sh @@ -197,7 +197,7 @@ esac case $info in -) ;; -*) tmp=/tmp/mam$$ +*) tmp=${TMPDIR:-/tmp}/mam$$ trap "exec >/dev/null; rm -f $tmp" 0 1 2 3 15 exec > $tmp echo "probing C language processor $cc for mam information" >&2 @@ -268,8 +268,8 @@ done case $info in -) ;; *) exec >/dev/null - test -f $info && rm -f $info - cp $tmp $info - chmod -w $info + test -f "$info" && rm -f "$info" + cp "$tmp" "$info" + chmod -w "$info" ;; esac diff --git a/src/cmd/INIT/package.sh b/src/cmd/INIT/package.sh index 7b79942d6..c4c228433 100644 --- a/src/cmd/INIT/package.sh +++ b/src/cmd/INIT/package.sh @@ -58,6 +58,9 @@ esac LC_ALL=C export LC_ALL +TMPDIR=${TMPDIR:-/tmp} +export TMPDIR + src="cmd contrib etc lib" use="/usr/common /exp /usr/local /usr/add-on /usr/addon /usr/tools /usr /opt" usr="/home" @@ -1782,7 +1785,7 @@ hostinfo() # attribute ... esac case $cpu in 0|1) cpu=`( - cd ${TMPDIR:-/tmp} + cd "$TMPDIR" tmp=hi$$ trap 'rm -f $tmp.*' 0 1 2 cat > $tmp.c < $tmp.c < $tmp.a.c </dev/null` in *universal*64* | *64-bit* | *x86[_-]64*) pwd=`pwd` - cd ${TMPDIR:-/tmp} + cd "$TMPDIR" tmp=hi$$ trap 'rm -f $tmp.*' 0 1 2 cat > $tmp.a.c < pkg$$.e 2>&1 || { if $cc -Dnew=old -o pkg$$.exe pkg$$.c > /dev/null 2>&1 @@ -3049,6 +3052,8 @@ cat $INITROOT/$i.sh $EXECTYPE) echo "$command: $CC: seems to be a cross-compiler" >&2 echo "$command: set HOSTTYPE to something other than the native $EXECTYPE" >&2 + echo "$command: If not, your $TMPDIR directory may be mounted without execute permission." >&2 + echo "$command: Try exporting TMPDIR as a directory where you can execute binary files." >&2 exit 1 ;; esac @@ -3213,10 +3218,10 @@ cygwin.*) lose=ntsec ;; *ntsec*);; - *) exe=/tmp/pkg$$.exe - rm -f $exe - : > $exe - if test -x $exe + *) exe=$TMPDIR/pkg$$.exe + rm -f "$exe" + : > "$exe" + if test -x "$exe" then lose=ntsec fi ;;