rbx.cp 0.5.45__py3-none-any.whl → 0.5.47__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. rbx/box/checkers.py +81 -28
  2. rbx/box/cli.py +12 -10
  3. rbx/box/generators.py +77 -40
  4. rbx/box/packaging/boca/packager.py +44 -7
  5. rbx/box/packaging/main.py +7 -0
  6. rbx/box/packaging/moj/packager.py +88 -8
  7. rbx/box/packaging/packager.py +7 -2
  8. rbx/box/packaging/polygon/packager.py +5 -4
  9. rbx/box/solutions.py +7 -5
  10. rbx/box/statements/builders.py +22 -3
  11. rbx/box/stresses.py +0 -1
  12. rbx/box/tasks.py +18 -8
  13. rbx/box/testcase_utils.py +66 -0
  14. rbx/grading/judge/sandbox.py +29 -1
  15. rbx/grading/judge/sandboxes/isolate.py +12 -2
  16. rbx/grading/judge/sandboxes/stupid_sandbox.py +17 -5
  17. rbx/grading/judge/sandboxes/timeit.py +12 -3
  18. rbx/grading/processing_context.py +48 -0
  19. rbx/grading/steps.py +24 -13
  20. rbx/resources/packagers/boca/checker.sh +8 -6
  21. rbx/resources/packagers/boca/compare.sh +48 -0
  22. rbx/resources/packagers/boca/interactive/c +207 -0
  23. rbx/resources/packagers/boca/interactive/cc +207 -0
  24. rbx/resources/packagers/boca/interactive/cpp +207 -0
  25. rbx/resources/packagers/boca/interactive/java +240 -0
  26. rbx/resources/packagers/boca/interactive/kt +231 -0
  27. rbx/resources/packagers/boca/interactive/py2 +209 -0
  28. rbx/resources/packagers/boca/interactive/py3 +209 -0
  29. rbx/resources/packagers/boca/interactor_compile.sh +45 -0
  30. rbx/resources/packagers/boca/run/bkp +163 -0
  31. rbx/resources/packagers/boca/run/c +19 -19
  32. rbx/resources/packagers/boca/run/cc +19 -19
  33. rbx/resources/packagers/boca/run/cpp +19 -19
  34. rbx/resources/packagers/boca/run/java +51 -51
  35. rbx/resources/packagers/boca/run/kt +30 -30
  36. rbx/resources/packagers/boca/run/py2 +42 -42
  37. rbx/resources/packagers/boca/run/py3 +42 -42
  38. rbx/resources/packagers/moj/scripts/c/compile.sh +19 -0
  39. rbx/resources/packagers/moj/scripts/c/prep.sh +5 -0
  40. rbx/resources/packagers/moj/scripts/c/run.sh +16 -0
  41. rbx/resources/packagers/moj/scripts/compare.sh +32 -6
  42. rbx/resources/packagers/moj/scripts/cpp/compile.sh +19 -0
  43. rbx/resources/packagers/moj/scripts/cpp/prep.sh +5 -0
  44. rbx/resources/packagers/moj/scripts/cpp/run.sh +16 -0
  45. rbx/resources/packagers/moj/scripts/interactor_prep.sh +14 -0
  46. rbx/resources/packagers/moj/scripts/interactor_run.sh +38 -0
  47. rbx/resources/packagers/moj/scripts/java/compile.sh +12 -0
  48. rbx/resources/packagers/moj/scripts/java/prep.sh +8 -0
  49. rbx/resources/packagers/moj/scripts/java/run.sh +17 -0
  50. rbx/resources/packagers/moj/scripts/py2/compile.sh +7 -0
  51. rbx/resources/packagers/moj/scripts/py2/prep.sh +5 -0
  52. rbx/resources/packagers/moj/scripts/py2/run.sh +16 -0
  53. rbx/resources/packagers/moj/scripts/py3/compile.sh +7 -0
  54. rbx/resources/packagers/moj/scripts/py3/prep.sh +5 -0
  55. rbx/resources/packagers/moj/scripts/py3/run.sh +16 -0
  56. {rbx_cp-0.5.45.dist-info → rbx_cp-0.5.47.dist-info}/METADATA +1 -1
  57. {rbx_cp-0.5.45.dist-info → rbx_cp-0.5.47.dist-info}/RECORD +60 -33
  58. rbx/resources/packagers/boca/compare +0 -53
  59. {rbx_cp-0.5.45.dist-info → rbx_cp-0.5.47.dist-info}/LICENSE +0 -0
  60. {rbx_cp-0.5.45.dist-info → rbx_cp-0.5.47.dist-info}/WHEEL +0 -0
  61. {rbx_cp-0.5.45.dist-info → rbx_cp-0.5.47.dist-info}/entry_points.txt +0 -0
rbx/grading/steps.py CHANGED
@@ -21,6 +21,7 @@ from rich.text import Text
21
21
  from rbx import utils
22
22
  from rbx.config import get_bits_stdcpp, get_jngen, get_testlib
23
23
  from rbx.console import console
24
+ from rbx.grading import processing_context
24
25
  from rbx.grading.judge.sandbox import SandboxBase, SandboxParams
25
26
  from rbx.grading.judge.storage import Storage, copyfileobj
26
27
 
@@ -197,6 +198,7 @@ class RunLog(BaseModel):
197
198
  exitstatus: str = SandboxBase.EXIT_SANDBOX_ERROR
198
199
  time: Optional[float] = 0.0
199
200
  memory: Optional[int] = 0
201
+ sandbox: str = ''
200
202
  warnings: bool = False
201
203
  metadata: Optional[RunLogMetadata] = None
202
204
 
@@ -210,7 +212,7 @@ class RunLog(BaseModel):
210
212
  return 'OK'
211
213
  time = self.time or 0.0
212
214
  memory = self.memory or 0
213
- return f'FAILED with exit code {self.exitcode} and sandbox status {self.exitstatus} (time: {time}s, memory: {memory//(1024*1024)}MB)'
215
+ return f'FAILED with exit code {self.exitcode} and sandbox status {self.exitstatus} (time: {time}s, memory: {memory // (1024 * 1024)}MB)'
214
216
 
215
217
 
216
218
  class PreprocessLog(RunLog):
@@ -567,6 +569,7 @@ def compile(
567
569
  memory=sandbox.get_memory_used(),
568
570
  warnings=_check_for_compilation_warnings(sandbox, stderr_file),
569
571
  log='\n'.join(std_outputs),
572
+ sandbox=sandbox.get_detailed_logs(),
570
573
  )
571
574
  logs.append(log)
572
575
 
@@ -594,6 +597,7 @@ async def run(
594
597
  sandbox: SandboxBase,
595
598
  artifacts: GradingArtifacts,
596
599
  metadata: Optional[RunLogMetadata] = None,
600
+ kill_on_processing_context_exit: bool = False,
597
601
  ) -> Optional[RunLog]:
598
602
  _process_input_artifacts(artifacts, sandbox)
599
603
  _process_fifos(artifacts, sandbox)
@@ -609,6 +613,9 @@ async def run(
609
613
  )
610
614
  return None
611
615
 
616
+ if sandbox.get_exit_code() != 0 and kill_on_processing_context_exit:
617
+ processing_context.terminate_all_processes_in_context()
618
+
612
619
  if not _process_output_artifacts(artifacts, sandbox):
613
620
  return None
614
621
 
@@ -625,6 +632,7 @@ async def run(
625
632
  time=sandbox.get_execution_time(),
626
633
  memory=sandbox.get_memory_used(),
627
634
  metadata=metadata,
635
+ sandbox=sandbox.get_detailed_logs(),
628
636
  )
629
637
  if metadata is not None and metadata.is_sanitized:
630
638
  run_log.warnings = _check_for_sanitizer_warnings(
@@ -649,19 +657,22 @@ async def run_coordinated(
649
657
  interactor: CoordinatedRunParams,
650
658
  solution: CoordinatedRunParams,
651
659
  ) -> Tuple[Optional[RunLog], Optional[RunLog]]:
652
- runs = tuple(
653
- run(
654
- params.command,
655
- params.params,
656
- params.sandbox,
657
- params.artifacts,
658
- params.metadata,
660
+ with processing_context.new_processing_context():
661
+ runs = tuple(
662
+ run(
663
+ params.command,
664
+ params.params,
665
+ params.sandbox,
666
+ params.artifacts,
667
+ params.metadata,
668
+ kill_on_processing_context_exit=True,
669
+ )
670
+ for params in [interactor, solution]
671
+ )
672
+ return typing.cast(
673
+ Tuple[Optional[RunLog], Optional[RunLog]],
674
+ tuple(await asyncio.gather(*runs)),
659
675
  )
660
- for params in [interactor, solution]
661
- )
662
- return typing.cast(
663
- Tuple[Optional[RunLog], Optional[RunLog]], tuple(await asyncio.gather(*runs))
664
- )
665
676
 
666
677
 
667
678
  def _normalize_checked_words(s: str) -> Tuple[str, ...]:
@@ -1,9 +1,10 @@
1
1
  ### START OF CHECKER COMPILATION
2
+ CDIR=$(pwd)
2
3
  CHECKER_PATH="checker.cpp"
3
- CHECKER_OUT="../checker.exe"
4
+ CHECKER_OUT="checker.exe"
4
5
 
5
6
  # find compiler
6
- cc=`which g++`
7
+ cc=$(which g++)
7
8
  [ -x "$cc" ] || cc=/usr/bin/g++
8
9
  if [ ! -x "$cc" ]; then
9
10
  echo "$cc not found or it's not executable"
@@ -12,25 +13,26 @@ fi
12
13
  read -r -d '' TestlibContent <<"EOF"
13
14
  {{testlib_content}}
14
15
  EOF
15
-
16
+
16
17
  read -r -d '' CheckerContent <<"EOF"
17
18
  {{checker_content}}
18
19
  EOF
19
20
 
20
- printf "%s" "${TestlibContent}" > testlib.h
21
- printf "%s" "${CheckerContent}" > $CHECKER_PATH
21
+ printf "%s" "${TestlibContent}" >testlib.h
22
+ printf "%s" "${CheckerContent}" >$CHECKER_PATH
22
23
 
23
24
  checker_hash=($(md5sum $CHECKER_PATH))
24
25
  checker_cache="/tmp/boca-chk-${checker_hash}"
25
26
 
26
27
  echo "Polygon checker hash: $checker_hash"
28
+ echo "Copying polygon checker to $CDIR/$CHECKER_OUT"
27
29
  if [ -f "$checker_cache" ]; then
28
30
  echo "Recovering polygon checker from cache: $checker_cache"
29
31
  cp "$checker_cache" $CHECKER_OUT -f
30
32
  else
31
33
  echo "Compiling polygon checker: $CHECKER_PATH"
32
34
  $cc {{rbxFlags}} $CHECKER_PATH -o $CHECKER_OUT
33
-
35
+
34
36
  if [ $? -ne 0 ]; then
35
37
  echo "Checker could not be compiled"
36
38
  exit 47
@@ -0,0 +1,48 @@
1
+ #!/bin/bash
2
+ if [ ! -r "$1" -o ! -r "$2" ]; then
3
+ echo "Parameter problem"
4
+ exit 43
5
+ fi
6
+
7
+ INTERACTOREXITCODE=$(grep '^testlib exitcode' "$1" | awk '{print $NF}')
8
+ if [[ -n $INTERACTOREXITCODE ]]; then
9
+ echo "interactor exitcode = $INTERACTOREXITCODE"
10
+ if [[ $INTERACTOREXITCODE -eq 1 ]]; then
11
+ echo "interactor return wrong answer"
12
+ exit 6
13
+ elif [[ $INTERACTOREXITCODE -eq 2 ]]; then
14
+ echo "interactor invalid input"
15
+ exit 6
16
+ elif [[ $INTERACTOREXITCODE -eq 3 ]]; then
17
+ echo "interactor failed with exit code 3"
18
+ exit 43
19
+ else
20
+ echo "interactor failed with exit code $INTERACTOREXITCODE"
21
+ exit 47
22
+ fi
23
+ fi
24
+
25
+ # Next lines of this script just compares team_output and sol_output,
26
+ # although it is possible to change them to more complex evaluations.
27
+ output=$(./checker.exe $3 $1 $2 2>&1 >/dev/null)
28
+ EC=$?
29
+
30
+ echo "checker exitcode = $EC"
31
+ echo "$output"
32
+
33
+ if [ $EC -eq 0 ]; then
34
+ echo "checker found no differences"
35
+ exit 4
36
+ elif [ $EC -eq 1 ]; then
37
+ echo "checker found differences"
38
+ exit 6
39
+ elif [ $EC -eq 2 ]; then
40
+ echo "checker found invalid output"
41
+ exit 6
42
+ elif [ $EC -eq 3 ]; then
43
+ echo "judge failed with $EC"
44
+ exit 43
45
+ else
46
+ echo "judge failed with $EC"
47
+ exit 47
48
+ fi
@@ -0,0 +1,207 @@
1
+ #!/bin/bash
2
+ # ////////////////////////////////////////////////////////////////////////////////
3
+ # //BOCA Online Contest Administrator
4
+ # // Copyright (C) 2003-2014 by BOCA System (bocasystem@gmail.com)
5
+ # //
6
+ # // This program is free software: you can redistribute it and/or modify
7
+ # // it under the terms of the GNU General Public License as published by
8
+ # // the Free Software Foundation, either version 3 of the License, or
9
+ # // (at your option) any later version.
10
+ # //
11
+ # // This program is distributed in the hope that it will be useful,
12
+ # // but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # // GNU General Public License for more details.
15
+ # // You should have received a copy of the GNU General Public License
16
+ # // along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ # ////////////////////////////////////////////////////////////////////////////////
18
+ #Last modified: 21/aug/2014 by cassio@ime.usp.br
19
+ #
20
+ # parameters are:
21
+ # $1 exe_file
22
+ # $2 input_file
23
+ # $3 timelimit (limit to run all the repetitions, by default only one repetition)
24
+ # $4 number_of_repetitions_to_run (optional, can be used for better tuning the timelimit)
25
+ # $5 maximum allowed memory (in MBytes)
26
+ # $6 maximum allowed output size (in KBytes)
27
+ #
28
+ # the output of the submission should be directed to the standard output
29
+ #
30
+ # the return code show what happened (according to safeexec):
31
+ # 0 ok
32
+ # 1 compile error
33
+ # 2 runtime error
34
+ # 3 timelimit exceeded
35
+ # 4 internal error
36
+ # 5 parameter error
37
+ # 6 internal error
38
+ # 7 memory limit exceeded
39
+ # 8 security threat
40
+ # 9 runtime error
41
+ # other_codes are unknown to boca: in this case BOCA will present the
42
+ # last line of standard output to the judge
43
+
44
+ umask 0022
45
+ id -u bocajail >/dev/null 2>/dev/null
46
+ if [ $? == 0 ]; then
47
+ bocau=$(id -u bocajail)
48
+ bocag=$(id -g bocajail)
49
+ chown bocajail.nogroup .
50
+ else
51
+ bocau=$(id -u nobody)
52
+ bocag=$(id -g nobody)
53
+ chown nobody.nogroup .
54
+ fi
55
+ if [ "$bocau" == "" -o "$bocag" == "" ]; then
56
+ echo "error finding user to run script"
57
+ exit 43
58
+ fi
59
+
60
+ # this script makes use of safeexec to execute the code with less privilegies
61
+ # make sure that directories below are correct.
62
+ sf=$(which safeexec)
63
+ [ -x "$sf" ] || sf=/usr/bin/safeexec
64
+
65
+ if [ "$1" == "" -o "$2" == "" -o "$3" == "" ]; then
66
+ echo "parameter problem"
67
+ exit 43
68
+ fi
69
+ if [ ! -x "$1" ]; then
70
+ echo "$1 not found (or is not in the current dir) or it's not executable"
71
+ exit 44
72
+ fi
73
+ if [ ! -r "$2" ]; then
74
+ echo "$2 not found (or is not in the current dir) or it's not readable"
75
+ exit 45
76
+ fi
77
+ if [ ! -x "$sf" ]; then
78
+ echo "$sf not found or it's not executable"
79
+ exit 46
80
+ fi
81
+
82
+ time=$3
83
+ if [ "$time" -gt "0" ]; then
84
+ let "ttime = $time + 30"
85
+ else
86
+ time=1
87
+ ttime=30
88
+ fi
89
+
90
+ nruns=1
91
+ if [ "$4" != "" ]; then
92
+ if [ "$4" -gt "0" ]; then
93
+ nruns=$4
94
+ fi
95
+ fi
96
+ maxm=512000
97
+ if [ "$5" != "" ]; then
98
+ if [ "$5" -gt "0" ]; then
99
+ maxm=${5}000
100
+ fi
101
+ fi
102
+ maxf=1024
103
+ if [ "$6" != "" ]; then
104
+ if [ "$6" -gt "0" ]; then
105
+ maxf=${6}
106
+ fi
107
+ fi
108
+
109
+ cp "$2" stdin0 2>/dev/null
110
+ cp "$1" run.exe 2>/dev/null
111
+ cp ../interactor.exe interactor.exe 2>/dev/null
112
+
113
+ file run.exe | grep -iq "statically linked"
114
+ if [ "$?" != "0" ]; then
115
+ echo "Aborting because $1 is not statically linked"
116
+ exit 47
117
+ fi
118
+
119
+ cdir=$(pwd)
120
+ echo "Current directory is $cdir -- chrooting on it" >&2
121
+
122
+ ### START OF BOCA RUN COMMAND
123
+ cat <<EOF >runit.sh
124
+ #!/bin/bash
125
+ mkfifo fifo.in fifo.out
126
+
127
+ echo "Running solution as \$@" >&2
128
+
129
+ "\$@" >fifo.out <fifo.in 2>/dev/null &
130
+ SFPID=\$!
131
+
132
+ ./interactor.exe "stdin0" "stdout0" <fifo.out >fifo.in 2>stderr0 &
133
+ INTPID=\$!
134
+
135
+ wait \$SFPID
136
+ ECSF=\$?
137
+
138
+ wait \$INTPID
139
+ ECINT=\$?
140
+
141
+ rm -rf fifo.in fifo.out
142
+
143
+ echo "interactor \$INTPID -> \$ECINT" >&2
144
+ echo "solution \$SFPID -> \$ECSF" >&2
145
+
146
+ echo "interactor exitcode \$ECINT" >&2
147
+ echo "solution exitcode \$ECSF" >&2
148
+
149
+ ret=0
150
+ if [[ \$ECINT -ge 1 ]] && [[ \$ECINT -le 4 ]]; then
151
+ echo "testlib exitcode \$ECINT" >stdout0
152
+ ret=0
153
+ elif [[ \$ECSF -ne 0 ]]; then
154
+ ret=\$ECSF
155
+ elif [[ \$ECINT -ne 0 ]]; then
156
+ ret=9
157
+ fi
158
+
159
+ exit \$ret
160
+ EOF
161
+
162
+ chmod 755 runit.sh
163
+
164
+ ret=0
165
+ echo $cdir | grep -q "/bocajail"
166
+ if [ $? -eq 0 ]; then
167
+ cdir=$(echo $cdir | sed "s/.*\/bocajail//")
168
+ cat <<EOF >runch.sh
169
+ #!/bin/bash
170
+ cd "$cdir"
171
+ [ -f /proc/cpuinfo ] || /bin/mount -t proc proc /proc
172
+ [ -d /sys/kernel ] || /bin/mount -t sysfs sysfs /sys
173
+ "$sf" -F10 -f$maxf -r$nruns -n0 -C. -U$bocau -G$bocag -d$maxm -m$maxm -t$time -T$ttime -ostdout0 -estderr0 -- ./runit.sh ./run.exe
174
+ retval=\$?
175
+ echo \$retval > runch.exitcode
176
+ if [ ! -d /bocajail ]; then
177
+ /bin/umount /proc 2>/dev/null
178
+ /bin/umount /sys 2>/dev/null
179
+ fi
180
+ EOF
181
+ chmod 755 runch.sh
182
+ chroot /bocajail $cdir/runch.sh
183
+ if [ -r runch.exitcode ]; then
184
+ ret=$(cat runch.exitcode)
185
+ fi
186
+ if [ "$ret" == "" ]; then
187
+ echo "Execution error - check autojudging"
188
+ exit 49
189
+ fi
190
+ else
191
+ echo "CODE NOT BEING CHROOTED. DO NOT RUN THIS ON THE MAIN SERVER" >&2
192
+ echo "CODE NOT BEING CHROOTED. DO NOT RUN THIS ON THE MAIN SERVER" >&2
193
+ echo "CODE NOT BEING CHROOTED. DO NOT RUN THIS ON THE MAIN SERVER" >&2
194
+
195
+ "$sf" -F10 -f$maxf -r$nruns -n0 -C. -U$bocau -G$bocag -d$maxm -m$maxm -t$time -T$ttime -ostdout0 -estderr0 -- ./runit.sh ./run.exe
196
+ ret=$?
197
+ fi
198
+ ### END OF BOCA RUN COMMAND
199
+
200
+ if [ $ret -gt 10 ]; then
201
+ echo "execution error with code $ret" >&2
202
+ ret=0
203
+ fi
204
+ if [ -f stdout0 ]; then
205
+ cat stdout0
206
+ fi
207
+ exit $ret
@@ -0,0 +1,207 @@
1
+ #!/bin/bash
2
+ # ////////////////////////////////////////////////////////////////////////////////
3
+ # //BOCA Online Contest Administrator
4
+ # // Copyright (C) 2003-2014 by BOCA System (bocasystem@gmail.com)
5
+ # //
6
+ # // This program is free software: you can redistribute it and/or modify
7
+ # // it under the terms of the GNU General Public License as published by
8
+ # // the Free Software Foundation, either version 3 of the License, or
9
+ # // (at your option) any later version.
10
+ # //
11
+ # // This program is distributed in the hope that it will be useful,
12
+ # // but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # // GNU General Public License for more details.
15
+ # // You should have received a copy of the GNU General Public License
16
+ # // along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ # ////////////////////////////////////////////////////////////////////////////////
18
+ #Last modified: 21/aug/2014 by cassio@ime.usp.br
19
+ #
20
+ # parameters are:
21
+ # $1 exe_file
22
+ # $2 input_file
23
+ # $3 timelimit (limit to run all the repetitions, by default only one repetition)
24
+ # $4 number_of_repetitions_to_run (optional, can be used for better tuning the timelimit)
25
+ # $5 maximum allowed memory (in MBytes)
26
+ # $6 maximum allowed output size (in KBytes)
27
+ #
28
+ # the output of the submission should be directed to the standard output
29
+ #
30
+ # the return code show what happened (according to safeexec):
31
+ # 0 ok
32
+ # 1 compile error
33
+ # 2 runtime error
34
+ # 3 timelimit exceeded
35
+ # 4 internal error
36
+ # 5 parameter error
37
+ # 6 internal error
38
+ # 7 memory limit exceeded
39
+ # 8 security threat
40
+ # 9 runtime error
41
+ # other_codes are unknown to boca: in this case BOCA will present the
42
+ # last line of standard output to the judge
43
+
44
+ umask 0022
45
+ id -u bocajail >/dev/null 2>/dev/null
46
+ if [ $? == 0 ]; then
47
+ bocau=$(id -u bocajail)
48
+ bocag=$(id -g bocajail)
49
+ chown bocajail.nogroup .
50
+ else
51
+ bocau=$(id -u nobody)
52
+ bocag=$(id -g nobody)
53
+ chown nobody.nogroup .
54
+ fi
55
+ if [ "$bocau" == "" -o "$bocag" == "" ]; then
56
+ echo "error finding user to run script"
57
+ exit 43
58
+ fi
59
+
60
+ # this script makes use of safeexec to execute the code with less privilegies
61
+ # make sure that directories below are correct.
62
+ sf=$(which safeexec)
63
+ [ -x "$sf" ] || sf=/usr/bin/safeexec
64
+
65
+ if [ "$1" == "" -o "$2" == "" -o "$3" == "" ]; then
66
+ echo "parameter problem"
67
+ exit 43
68
+ fi
69
+ if [ ! -x "$1" ]; then
70
+ echo "$1 not found (or is not in the current dir) or it's not executable"
71
+ exit 44
72
+ fi
73
+ if [ ! -r "$2" ]; then
74
+ echo "$2 not found (or is not in the current dir) or it's not readable"
75
+ exit 45
76
+ fi
77
+ if [ ! -x "$sf" ]; then
78
+ echo "$sf not found or it's not executable"
79
+ exit 46
80
+ fi
81
+
82
+ time=$3
83
+ if [ "$time" -gt "0" ]; then
84
+ let "ttime = $time + 30"
85
+ else
86
+ time=1
87
+ ttime=30
88
+ fi
89
+
90
+ nruns=1
91
+ if [ "$4" != "" ]; then
92
+ if [ "$4" -gt "0" ]; then
93
+ nruns=$4
94
+ fi
95
+ fi
96
+ maxm=512000
97
+ if [ "$5" != "" ]; then
98
+ if [ "$5" -gt "0" ]; then
99
+ maxm=${5}000
100
+ fi
101
+ fi
102
+ maxf=1024
103
+ if [ "$6" != "" ]; then
104
+ if [ "$6" -gt "0" ]; then
105
+ maxf=${6}
106
+ fi
107
+ fi
108
+
109
+ cp "$2" stdin0 2>/dev/null
110
+ cp "$1" run.exe 2>/dev/null
111
+ cp ../interactor.exe interactor.exe 2>/dev/null
112
+
113
+ file run.exe | grep -iq "statically linked"
114
+ if [ "$?" != "0" ]; then
115
+ echo "Aborting because $1 is not statically linked"
116
+ exit 47
117
+ fi
118
+
119
+ cdir=$(pwd)
120
+ echo "Current directory is $cdir -- chrooting on it" >&2
121
+
122
+ ### START OF BOCA RUN COMMAND
123
+ cat <<EOF >runit.sh
124
+ #!/bin/bash
125
+ mkfifo fifo.in fifo.out
126
+
127
+ echo "Running solution as \$@" >&2
128
+
129
+ "\$@" >fifo.out <fifo.in 2>/dev/null &
130
+ SFPID=\$!
131
+
132
+ ./interactor.exe "stdin0" "stdout0" <fifo.out >fifo.in 2>stderr0 &
133
+ INTPID=\$!
134
+
135
+ wait \$SFPID
136
+ ECSF=\$?
137
+
138
+ wait \$INTPID
139
+ ECINT=\$?
140
+
141
+ rm -rf fifo.in fifo.out
142
+
143
+ echo "interactor \$INTPID -> \$ECINT" >&2
144
+ echo "solution \$SFPID -> \$ECSF" >&2
145
+
146
+ echo "interactor exitcode \$ECINT" >&2
147
+ echo "solution exitcode \$ECSF" >&2
148
+
149
+ ret=0
150
+ if [[ \$ECINT -ge 1 ]] && [[ \$ECINT -le 4 ]]; then
151
+ echo "testlib exitcode \$ECINT" >stdout0
152
+ ret=0
153
+ elif [[ \$ECSF -ne 0 ]]; then
154
+ ret=\$ECSF
155
+ elif [[ \$ECINT -ne 0 ]]; then
156
+ ret=9
157
+ fi
158
+
159
+ exit \$ret
160
+ EOF
161
+
162
+ chmod 755 runit.sh
163
+
164
+ ret=0
165
+ echo $cdir | grep -q "/bocajail"
166
+ if [ $? -eq 0 ]; then
167
+ cdir=$(echo $cdir | sed "s/.*\/bocajail//")
168
+ cat <<EOF >runch.sh
169
+ #!/bin/bash
170
+ cd "$cdir"
171
+ [ -f /proc/cpuinfo ] || /bin/mount -t proc proc /proc
172
+ [ -d /sys/kernel ] || /bin/mount -t sysfs sysfs /sys
173
+ "$sf" -F10 -f$maxf -r$nruns -n0 -C. -U$bocau -G$bocag -d$maxm -m$maxm -t$time -T$ttime -ostdout0 -estderr0 -- ./runit.sh ./run.exe
174
+ retval=\$?
175
+ echo \$retval > runch.exitcode
176
+ if [ ! -d /bocajail ]; then
177
+ /bin/umount /proc 2>/dev/null
178
+ /bin/umount /sys 2>/dev/null
179
+ fi
180
+ EOF
181
+ chmod 755 runch.sh
182
+ chroot /bocajail $cdir/runch.sh
183
+ if [ -r runch.exitcode ]; then
184
+ ret=$(cat runch.exitcode)
185
+ fi
186
+ if [ "$ret" == "" ]; then
187
+ echo "Execution error - check autojudging"
188
+ exit 49
189
+ fi
190
+ else
191
+ echo "CODE NOT BEING CHROOTED. DO NOT RUN THIS ON THE MAIN SERVER" >&2
192
+ echo "CODE NOT BEING CHROOTED. DO NOT RUN THIS ON THE MAIN SERVER" >&2
193
+ echo "CODE NOT BEING CHROOTED. DO NOT RUN THIS ON THE MAIN SERVER" >&2
194
+
195
+ "$sf" -F10 -f$maxf -r$nruns -n0 -C. -U$bocau -G$bocag -d$maxm -m$maxm -t$time -T$ttime -ostdout0 -estderr0 -- ./runit.sh ./run.exe
196
+ ret=$?
197
+ fi
198
+ ### END OF BOCA RUN COMMAND
199
+
200
+ if [ $ret -gt 10 ]; then
201
+ echo "execution error with code $ret" >&2
202
+ ret=0
203
+ fi
204
+ if [ -f stdout0 ]; then
205
+ cat stdout0
206
+ fi
207
+ exit $ret