1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

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.
This commit is contained in:
Martijn Dekker 2020-08-03 23:52:41 +00:00
parent aa4669ad17
commit 07b240d4f9
6 changed files with 40 additions and 28 deletions

View file

@ -197,7 +197,7 @@ esac
case $info in case $info in
-) ;; -) ;;
*) tmp=/tmp/mam$$ *) tmp=${TMPDIR:-/tmp}/mam$$
trap "exec >/dev/null; rm -f $tmp" 0 1 2 3 15 trap "exec >/dev/null; rm -f $tmp" 0 1 2 3 15
exec > $tmp exec > $tmp
echo "probing C language processor $cc for mam information" >&2 echo "probing C language processor $cc for mam information" >&2
@ -268,8 +268,8 @@ done
case $info in case $info in
-) ;; -) ;;
*) exec >/dev/null *) exec >/dev/null
test -f $info && rm -f $info test -f "$info" && rm -f "$info"
cp $tmp $info cp "$tmp" "$info"
chmod -w $info chmod -w "$info"
;; ;;
esac esac

View file

@ -59,6 +59,9 @@ esac
LC_ALL=C LC_ALL=C
export LC_ALL export LC_ALL
TMPDIR=${TMPDIR:-/tmp}
export TMPDIR
src="cmd contrib etc lib" src="cmd contrib etc lib"
use="/usr/common /exp /usr/local /usr/add-on /usr/addon /usr/tools /usr /opt" use="/usr/common /exp /usr/local /usr/add-on /usr/addon /usr/tools /usr /opt"
usr="/home" usr="/home"
@ -1783,7 +1786,7 @@ hostinfo() # attribute ...
esac esac
case $cpu in case $cpu in
0|1) cpu=`( 0|1) cpu=`(
cd ${TMPDIR:-/tmp} cd "$TMPDIR"
tmp=hi$$ tmp=hi$$
trap 'rm -f $tmp.*' 0 1 2 trap 'rm -f $tmp.*' 0 1 2
cat > $tmp.c <<! cat > $tmp.c <<!
@ -1821,7 +1824,7 @@ int main()
done done
case $rating in case $rating in
[0123456789]*) ;; [0123456789]*) ;;
*) cd ${TMPDIR:-/tmp} *) cd "$TMPDIR"
tmp=hi$$ tmp=hi$$
trap 'rm -f $tmp.*' 0 1 2 trap 'rm -f $tmp.*' 0 1 2
cat > $tmp.c <<! cat > $tmp.c <<!
@ -2437,7 +2440,7 @@ int main()
esac esac
;; ;;
*) pwd=`pwd` *) pwd=`pwd`
cd ${TMPDIR:-/tmp} cd "$TMPDIR"
tmp=hi$$ tmp=hi$$
trap 'rm -f $tmp.*' 0 1 2 trap 'rm -f $tmp.*' 0 1 2
cat > $tmp.a.c <<! cat > $tmp.a.c <<!
@ -2495,7 +2498,7 @@ int b() { return 0; }
'') case `file /bin/sh 2>/dev/null` in '') case `file /bin/sh 2>/dev/null` in
*universal*64* | *64-bit* | *x86[_-]64*) *universal*64* | *64-bit* | *x86[_-]64*)
pwd=`pwd` pwd=`pwd`
cd ${TMPDIR:-/tmp} cd "$TMPDIR"
tmp=hi$$ tmp=hi$$
trap 'rm -f $tmp.*' 0 1 2 trap 'rm -f $tmp.*' 0 1 2
cat > $tmp.a.c <<! cat > $tmp.a.c <<!
@ -2848,7 +2851,7 @@ cat $INITROOT/$i.sh
# check if $CC (full path $cc) is a cross compiler # check if $CC (full path $cc) is a cross compiler
( (
cd /tmp || exit 3 cd "$TMPDIR" || exit 3
cp $INITROOT/hello.c pkg$$.c || exit 3 cp $INITROOT/hello.c pkg$$.c || exit 3
$cc -o pkg$$.exe pkg$$.c > pkg$$.e 2>&1 || { $cc -o pkg$$.exe pkg$$.c > pkg$$.e 2>&1 || {
if $cc -Dnew=old -o pkg$$.exe pkg$$.c > /dev/null 2>&1 if $cc -Dnew=old -o pkg$$.exe pkg$$.c > /dev/null 2>&1
@ -3050,6 +3053,8 @@ cat $INITROOT/$i.sh
$EXECTYPE) $EXECTYPE)
echo "$command: $CC: seems to be a cross-compiler" >&2 echo "$command: $CC: seems to be a cross-compiler" >&2
echo "$command: set HOSTTYPE to something other than the native $EXECTYPE" >&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 exit 1
;; ;;
esac esac
@ -3214,10 +3219,10 @@ cygwin.*)
lose=ntsec lose=ntsec
;; ;;
*ntsec*);; *ntsec*);;
*) exe=/tmp/pkg$$.exe *) exe=$TMPDIR/pkg$$.exe
rm -f $exe rm -f "$exe"
: > $exe : > "$exe"
if test -x $exe if test -x "$exe"
then lose=ntsec then lose=ntsec
fi fi
;; ;;

View file

@ -21,7 +21,9 @@
command=filter command=filter
tmp=/tmp/$command$$ TMPDIR=${TMPDIR:-/tmp}
export TMPDIR
tmp=$TMPDIR/$command$$
suf= suf=
case `(getopts '[-][123:xyz]' opt --xyz; echo 0$opt) 2>/dev/null` in case `(getopts '[-][123:xyz]' opt --xyz; echo 0$opt) 2>/dev/null` in

View file

@ -1518,7 +1518,7 @@ require(char* lib, int dontcare)
else if (dontcare) else if (dontcare)
{ {
append(tmp, "set -\n"); 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, "echo 'int main(){return 0;}' > x.${!-$$}.c\n");
append(tmp, "${CC} ${CCFLAGS} -o x.${!-$$}.x x.${!-$$}.c "); append(tmp, "${CC} ${CCFLAGS} -o x.${!-$$}.x x.${!-$$}.c ");
append(tmp, r); append(tmp, r);

View file

@ -197,7 +197,7 @@ esac
case $info in case $info in
-) ;; -) ;;
*) tmp=/tmp/mam$$ *) tmp=${TMPDIR:-/tmp}/mam$$
trap "exec >/dev/null; rm -f $tmp" 0 1 2 3 15 trap "exec >/dev/null; rm -f $tmp" 0 1 2 3 15
exec > $tmp exec > $tmp
echo "probing C language processor $cc for mam information" >&2 echo "probing C language processor $cc for mam information" >&2
@ -268,8 +268,8 @@ done
case $info in case $info in
-) ;; -) ;;
*) exec >/dev/null *) exec >/dev/null
test -f $info && rm -f $info test -f "$info" && rm -f "$info"
cp $tmp $info cp "$tmp" "$info"
chmod -w $info chmod -w "$info"
;; ;;
esac esac

View file

@ -58,6 +58,9 @@ esac
LC_ALL=C LC_ALL=C
export LC_ALL export LC_ALL
TMPDIR=${TMPDIR:-/tmp}
export TMPDIR
src="cmd contrib etc lib" src="cmd contrib etc lib"
use="/usr/common /exp /usr/local /usr/add-on /usr/addon /usr/tools /usr /opt" use="/usr/common /exp /usr/local /usr/add-on /usr/addon /usr/tools /usr /opt"
usr="/home" usr="/home"
@ -1782,7 +1785,7 @@ hostinfo() # attribute ...
esac esac
case $cpu in case $cpu in
0|1) cpu=`( 0|1) cpu=`(
cd ${TMPDIR:-/tmp} cd "$TMPDIR"
tmp=hi$$ tmp=hi$$
trap 'rm -f $tmp.*' 0 1 2 trap 'rm -f $tmp.*' 0 1 2
cat > $tmp.c <<! cat > $tmp.c <<!
@ -1820,7 +1823,7 @@ int main()
done done
case $rating in case $rating in
[0123456789]*) ;; [0123456789]*) ;;
*) cd ${TMPDIR:-/tmp} *) cd "$TMPDIR"
tmp=hi$$ tmp=hi$$
trap 'rm -f $tmp.*' 0 1 2 trap 'rm -f $tmp.*' 0 1 2
cat > $tmp.c <<! cat > $tmp.c <<!
@ -2436,7 +2439,7 @@ int main()
esac esac
;; ;;
*) pwd=`pwd` *) pwd=`pwd`
cd ${TMPDIR:-/tmp} cd "$TMPDIR"
tmp=hi$$ tmp=hi$$
trap 'rm -f $tmp.*' 0 1 2 trap 'rm -f $tmp.*' 0 1 2
cat > $tmp.a.c <<! cat > $tmp.a.c <<!
@ -2494,7 +2497,7 @@ int b() { return 0; }
'') case `file /bin/sh 2>/dev/null` in '') case `file /bin/sh 2>/dev/null` in
*universal*64* | *64-bit* | *x86[_-]64*) *universal*64* | *64-bit* | *x86[_-]64*)
pwd=`pwd` pwd=`pwd`
cd ${TMPDIR:-/tmp} cd "$TMPDIR"
tmp=hi$$ tmp=hi$$
trap 'rm -f $tmp.*' 0 1 2 trap 'rm -f $tmp.*' 0 1 2
cat > $tmp.a.c <<! cat > $tmp.a.c <<!
@ -2847,7 +2850,7 @@ cat $INITROOT/$i.sh
# check if $CC (full path $cc) is a cross compiler # check if $CC (full path $cc) is a cross compiler
( (
cd /tmp || exit 3 cd "$TMPDIR" || exit 3
cp $INITROOT/hello.c pkg$$.c || exit 3 cp $INITROOT/hello.c pkg$$.c || exit 3
$cc -o pkg$$.exe pkg$$.c > pkg$$.e 2>&1 || { $cc -o pkg$$.exe pkg$$.c > pkg$$.e 2>&1 || {
if $cc -Dnew=old -o pkg$$.exe pkg$$.c > /dev/null 2>&1 if $cc -Dnew=old -o pkg$$.exe pkg$$.c > /dev/null 2>&1
@ -3049,6 +3052,8 @@ cat $INITROOT/$i.sh
$EXECTYPE) $EXECTYPE)
echo "$command: $CC: seems to be a cross-compiler" >&2 echo "$command: $CC: seems to be a cross-compiler" >&2
echo "$command: set HOSTTYPE to something other than the native $EXECTYPE" >&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 exit 1
;; ;;
esac esac
@ -3213,10 +3218,10 @@ cygwin.*)
lose=ntsec lose=ntsec
;; ;;
*ntsec*);; *ntsec*);;
*) exe=/tmp/pkg$$.exe *) exe=$TMPDIR/pkg$$.exe
rm -f $exe rm -f "$exe"
: > $exe : > "$exe"
if test -x $exe if test -x "$exe"
then lose=ntsec then lose=ntsec
fi fi
;; ;;