aboutsummaryrefslogtreecommitdiff
path: root/boca-1.5.0/doc/problemexamples/problemtemplate/compile
diff options
context:
space:
mode:
authorcassiopc <cassiopc@gmail.com>2012-08-08 17:52:19 +0000
committercassiopc <cassiopc@gmail.com>2012-08-08 17:52:19 +0000
commit5d4eca5257a60c5f1de043fdf3f67e0a9df011f4 (patch)
tree6d4ec6ffe1b6490be4120c0f06ae6cdabca41dd8 /boca-1.5.0/doc/problemexamples/problemtemplate/compile
parentf8c7c32e3ea6417ccf04309ec521b39a0c20414d (diff)
downloadboca-5d4eca5257a60c5f1de043fdf3f67e0a9df011f4.tar.gz
boca-5d4eca5257a60c5f1de043fdf3f67e0a9df011f4.zip
many small bug fixes
Diffstat (limited to 'boca-1.5.0/doc/problemexamples/problemtemplate/compile')
-rw-r--r--boca-1.5.0/doc/problemexamples/problemtemplate/compile/c41
-rw-r--r--boca-1.5.0/doc/problemexamples/problemtemplate/compile/cpp41
-rw-r--r--boca-1.5.0/doc/problemexamples/problemtemplate/compile/java61
3 files changed, 91 insertions, 52 deletions
diff --git a/boca-1.5.0/doc/problemexamples/problemtemplate/compile/c b/boca-1.5.0/doc/problemexamples/problemtemplate/compile/c
index 04a08e9..4cb7ea8 100644
--- a/boca-1.5.0/doc/problemexamples/problemtemplate/compile/c
+++ b/boca-1.5.0/doc/problemexamples/problemtemplate/compile/c
@@ -59,7 +59,7 @@ if [ "${name##*.}" == "zip" -a "${name##*.}" == "ZIP" ]; then
unzip "$name" -d src
name="*.c"
else
- mv $name src
+ cp "$name" src
fi
id -u bocajail >/dev/null 2>/dev/null
if [ $? == 0 ]; then
@@ -85,8 +85,10 @@ if [ ! -x $sf ]; then
exit 46
fi
maxm=512000
-if [ "$4" != "" -a "$4" -gt "0" ]; then
-maxm=${4}000
+if [ "$4" != "" ]; then
+ if [ "$4" -gt "0" ]; then
+ maxm=${4}000
+ fi
fi
# setting up the timelimit according to the problem
@@ -95,7 +97,7 @@ time=5
else
time=$3
fi
-let ttime=$time+30
+let "ttime = $time + 30"
if [ "$2" == "" ]; then
exe=run.exe
@@ -103,7 +105,7 @@ else
exe=$2
fi
-rm -f ../$exe 2>/dev/null
+rm -f $exe compileit.retcode runit.retcode 2>/dev/null
cat <<EOF > compileit.sh
#!/bin/bash
cc=\`which gcc\`
@@ -113,8 +115,8 @@ if [ ! -x "\$cc" ]; then
exit 47
fi
cd src
-"\$cc" -static -O2 -lm -o ../$exe "$name"
-echo \$? > compileit.retcode
+"\$cc" -static -O2 -o ../$exe $name -lm
+echo \$? > ../compileit.retcode
exit 0
EOF
chmod 755 compileit.sh
@@ -124,29 +126,40 @@ echo "Current directory is $cdir" >&2
echo $cdir | grep -q "/bocajail"
if [ $? == 0 ]; then
cdir=`echo $cdir | sed "s/.*\/bocajail//"`
+ echo "Internal directory is $cdir"
cat <<EOF > runit.sh
#!/bin/bash
+cd "$cdir"
[ -f /proc/cpuinfo ] || /bin/mount -t proc proc /proc
#/bin/mount --bind /dev /dev
[ -d /sys/kernel ] || /bin/mount -t sysfs sysfs /sys
$sf -r1 -F1000 -n0 -U$bocau -G$bocag -C. -ostdout0 -estderr0 -d$maxm -m$maxm -f20000 -t$ttime -T$ttime ./compileit.sh
echo \$? > runit.retcode
-/bin/umount /proc 2>/dev/null
-#/bin/umount /dev
-/bin/umount /sys 2>/dev/null
+if [ ! -d /bocajail ]; then
+ /bin/umount /proc 2>/dev/null
+ #/bin/umount /dev
+ /bin/umount /sys 2>/dev/null
+fi
EOF
chmod 755 runit.sh
chroot /bocajail "$cdir/runit.sh"
- ret=`cat runit.retcode`
+ if [ -r runit.retcode ]; then
+ ret=`cat runit.retcode`
+ else
+ ret=99
+ fi
else
echo "COMPILATION IS NOT BEING CHROOTED -- THIS IS NOT AN IDEAL SETTING"
$sf -r1 -F1000 -n0 -U$bocau -G$bocag -C. -ostdout0 -estderr0 -d$maxm -m$maxm -f20000 -t$ttime -T$ttime ./compileit.sh
ret=$?
fi
-rm -rf src/
-if [ -f stdout0 ]; then
- cat stdout0
+if [ -f "stdout0" ]; then
+ cat "stdout0"
fi
+if [ -f "stderr0" ]; then
+ cat "stderr0"
+fi
+rm -rf src/
if [ "$ret" != "0" ]; then
echo "Compilation Error: $ret"
exit $ret
diff --git a/boca-1.5.0/doc/problemexamples/problemtemplate/compile/cpp b/boca-1.5.0/doc/problemexamples/problemtemplate/compile/cpp
index 2ec55ac..6a61bc1 100644
--- a/boca-1.5.0/doc/problemexamples/problemtemplate/compile/cpp
+++ b/boca-1.5.0/doc/problemexamples/problemtemplate/compile/cpp
@@ -59,7 +59,7 @@ if [ "${name##*.}" == "zip" -a "${name##*.}" == "ZIP" ]; then
unzip "$name" -d src
name="*.c"
else
- mv $name src
+ cp "$name" src
fi
id -u bocajail >/dev/null 2>/dev/null
if [ $? == 0 ]; then
@@ -85,8 +85,10 @@ if [ ! -x $sf ]; then
exit 46
fi
maxm=512000
-if [ "$4" != "" -a "$4" -gt "0" ]; then
-maxm=${4}000
+if [ "$4" != "" ]; then
+ if [ "$4" -gt "0" ]; then
+ maxm=${4}000
+ fi
fi
# setting up the timelimit according to the problem
@@ -95,7 +97,7 @@ time=5
else
time=$3
fi
-let ttime=$time+30
+let "ttime = $time + 30"
if [ "$2" == "" ]; then
exe=run.exe
@@ -103,7 +105,7 @@ else
exe=$2
fi
-rm -f ../$exe 2>/dev/null
+rm -f $exe compileit.retcode runit.retcode 2>/dev/null
cat <<EOF > compileit.sh
#!/bin/bash
cc=\`which g++\`
@@ -113,8 +115,8 @@ if [ ! -x "\$cc" ]; then
exit 47
fi
cd src
-"\$cc" -static -O2 -lm -o ../$exe "$name"
-echo \$? > compileit.retcode
+"\$cc" -static -O2 -o ../$exe $name -lm
+echo \$? > ../compileit.retcode
exit 0
EOF
chmod 755 compileit.sh
@@ -124,29 +126,40 @@ echo "Current directory is $cdir" >&2
echo $cdir | grep -q "/bocajail"
if [ $? == 0 ]; then
cdir=`echo $cdir | sed "s/.*\/bocajail//"`
+ echo "Internal directory is $cdir"
cat <<EOF > runit.sh
#!/bin/bash
+cd "$cdir"
[ -f /proc/cpuinfo ] || /bin/mount -t proc proc /proc
#/bin/mount --bind /dev /dev
[ -d /sys/kernel ] || /bin/mount -t sysfs sysfs /sys
$sf -r1 -F1000 -n0 -U$bocau -G$bocag -C. -ostdout0 -estderr0 -d$maxm -m$maxm -f20000 -t$ttime -T$ttime ./compileit.sh
echo \$? > runit.retcode
-/bin/umount /proc 2>/dev/null
-#/bin/umount /dev
-/bin/umount /sys 2>/dev/null
+if [ ! -d /bocajail ]; then
+ /bin/umount /proc 2>/dev/null
+ #/bin/umount /dev
+ /bin/umount /sys 2>/dev/null
+fi
EOF
chmod 755 runit.sh
chroot /bocajail "$cdir/runit.sh"
- ret=`cat runit.retcode`
+ if [ -r runit.retcode ]; then
+ ret=`cat runit.retcode`
+ else
+ ret=99
+ fi
else
echo "COMPILATION IS NOT BEING CHROOTED -- THIS IS NOT AN IDEAL SETTING"
$sf -r1 -F1000 -n0 -U$bocau -G$bocag -C. -ostdout0 -estderr0 -d$maxm -m$maxm -f20000 -t$ttime -T$ttime ./compileit.sh
ret=$?
fi
-rm -rf src/
-if [ -f stdout0 ]; then
- cat stdout0
+if [ -f "stdout0" ]; then
+ cat "stdout0"
fi
+if [ -f "stderr0" ]; then
+ cat "stderr0"
+fi
+rm -rf src/
if [ "$ret" != "0" ]; then
echo "Compilation Error: $ret"
exit $ret
diff --git a/boca-1.5.0/doc/problemexamples/problemtemplate/compile/java b/boca-1.5.0/doc/problemexamples/problemtemplate/compile/java
index dae050e..f62215b 100644
--- a/boca-1.5.0/doc/problemexamples/problemtemplate/compile/java
+++ b/boca-1.5.0/doc/problemexamples/problemtemplate/compile/java
@@ -49,18 +49,6 @@ if [ ! -r "$1" ]; then
echo "$1 not found or it's not readable"
exit 44
fi
-mkdir -p src
-if [ "${name##*.}" == "zip" -a "${name##*.}" == "ZIP" ]; then
- unzip "$name" -d src
- if [ "${name##*.}" == "zip" ]; then
- name=`basename $name .zip`
- else
- name=`basename $name .ZIP`
- fi
-else
- mv $name src
-fi
-
id -u bocajail >/dev/null 2>/dev/null
if [ $? == 0 ]; then
bocau=`id -u bocajail`
@@ -76,6 +64,20 @@ if [ "$bocau" == "" -o "$bocag" == "" ]; then
exit 43
fi
+mkdir -p src
+if [ "${name##*.}" == "zip" -a "${name##*.}" == "ZIP" ]; then
+ unzip "$name" -d src
+ if [ "${name##*.}" == "zip" ]; then
+ name=`basename $name .zip`
+ else
+ name=`basename $name .ZIP`
+ fi
+else
+ cp $name src
+fi
+chown -R $bocau src
+chmod -R 700 src
+
# this script makes use of safeexec to execute the code with less privilegies
# make sure that directories below are correct.
sf=`which safeexec`
@@ -124,15 +126,16 @@ fi
export CLASSPATH=.:\$CLASSPATH
cd src
if [ -r "$name" ]; then
- \$javac -Xmx${maxm}M -Xms${maxm}M "$name"
- echo \$? > compileit.retcode
+ \$javac "$name"
+ echo \$? > ../compileit.retcode
fi
find . -name "*.java" | while read lin; do
- \$javac -Xmx${maxm}M -Xms${maxm}M "\$lin"
- echo \$? > compileit.retcode
+ \$javac "\$lin"
+ echo \$? > ../compileit.retcode
done
rm -f ../$jarfile
\$jar cvf ../$jarfile *
+exit 0
EOF
chmod 755 compileit.sh
@@ -141,29 +144,39 @@ if [ $? == 0 ]; then
cdir=`echo $cdir | sed "s/.*\/bocajail//"`
cat <<EOF > runit.sh
#!/bin/bash
+cd "$cdir"
[ -f /proc/cpuinfo ] || /bin/mount -t proc proc /proc
#/bin/mount --bind /dev /dev
[ -d /sys/kernel ] || /bin/mount -t sysfs sysfs /sys
$sf -r1 -t$time -T$ttime -F256 -u256 -ostdout0 -estderr0 -U$bocau -G$bocag -n0 -C. -f20000 -d20000000 -m20000000 ./compileit.sh
-
-/bin/umount /proc 2>/dev/null
-#/bin/umount /dev
-/bin/umount /sys 2>/dev/null
+echo \$? > runit.retcode
+if [ ! -d /bocajail ]; then
+ /bin/umount /proc 2>/dev/null
+ #/bin/umount /dev
+ /bin/umount /sys 2>/dev/null
+fi
EOF
chmod 755 runit.sh
chroot /bocajail "$cdir/runit.sh"
- ret=`cat runit.retcode`
+ if [ -r runit.retcode ]; then
+ ret=`cat runit.retcode`
+ else
+ ret=99
+ fi
else
echo "COMPILATION IS NOT BEING CHROOTED -- THIS IS NOT AN IDEAL SETTING"
# $javac "$name"
$sf -r1 -t$time -T$ttime -F256 -u256 -U$bocau -G$bocag -ostdout0 -estderr0 -n0 -C. -d20000000 -m20000000 ./compileit.sh
ret=$?
fi
-rm -rf src/
-if [ -f stdout0 ]; then
- cat stdout0
+if [ -f "stdout0" ]; then
+ cat "stdout0"
+fi
+if [ -f "stderr0" ]; then
+ cat "stderr0"
fi
+rm -rf src/
if [ "$ret" != "0" ]; then
echo "Compilation Error: $ret"
exit $ret