Skip to content

Commit

Permalink
Fix error when setting default values for submission.
Browse files Browse the repository at this point in the history
  • Loading branch information
hermanzdosilovic committed Jan 13, 2020
1 parent 69a9fe1 commit a6f693a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
6 changes: 6 additions & 0 deletions app/helpers/nil_value.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module NilValue
def self.value_or_default(value, default)
return value unless value == nil
return default
end
end
8 changes: 4 additions & 4 deletions app/jobs/isolate_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def perform(submission)

def initialize_workdir
@box_id = submission.id%2147483647
@cgroups_flag = (submission.enable_per_process_and_thread_time_limit | submission.enable_per_process_and_thread_memory_limit ? "--cg" : "")
@cgroups_flag = (submission.enable_per_process_and_thread_time_limit || submission.enable_per_process_and_thread_memory_limit) ? "--cg" : ""
@workdir = `isolate #{cgroups_flag} -b #{box_id} --init`.chomp
@boxdir = workdir + "/box"
@tmpdir = workdir + "/tmp"
Expand Down Expand Up @@ -87,8 +87,8 @@ def compile
-w 10 \
-k #{Config::MAX_STACK_LIMIT} \
-p#{Config::MAX_MAX_PROCESSES_AND_OR_THREADS} \
#{Config::ALLOW_ENABLE_PER_PROCESS_AND_THREAD_MEMORY_LIMIT ? "--cg-mem=" : "-m "}#{Config::MAX_MEMORY_LIMIT} \
#{Config::ALLOW_ENABLE_PER_PROCESS_AND_THREAD_TIME_LIMIT ? "--cg-timing" : "--no-cg-timing"} \
#{submission.enable_per_process_and_thread_time_limit ? "--cg-timing" : (cgroups_flag.present? ? "--no-cg-timing" : "")} \
#{submission.enable_per_process_and_thread_memory_limit ? "--cg-mem=" : "-m "}#{submission.memory_limit} \
-f #{Config::MAX_MAX_FILE_SIZE} \
-E HOME=#{workdir} \
-E PATH=\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\" \
Expand Down Expand Up @@ -150,8 +150,8 @@ def run
-w #{submission.wall_time_limit} \
-k #{submission.stack_limit} \
-p#{submission.max_processes_and_or_threads} \
#{submission.enable_per_process_and_thread_time_limit ? "--cg-timing" : (cgroups_flag.present? ? "--no-cg-timing" : "")} \
#{submission.enable_per_process_and_thread_memory_limit ? "--cg-mem=" : "-m "}#{submission.memory_limit} \
#{submission.enable_per_process_and_thread_time_limit ? "--cg-timing" : "--no-cg-timing"} \
-f #{submission.max_file_size} \
-E HOME=#{workdir} \
-E PATH=\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\" \
Expand Down
10 changes: 8 additions & 2 deletions app/models/submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,14 @@ def set_defaults
self.memory_limit ||= Config::MEMORY_LIMIT
self.stack_limit ||= Config::STACK_LIMIT
self.max_processes_and_or_threads ||= Config::MAX_PROCESSES_AND_OR_THREADS
self.enable_per_process_and_thread_time_limit ||= Config::ENABLE_PER_PROCESS_AND_THREAD_TIME_LIMIT
self.enable_per_process_and_thread_memory_limit ||= Config::ENABLE_PER_PROCESS_AND_THREAD_MEMORY_LIMIT
self.enable_per_process_and_thread_time_limit = NilValue.value_or_default(
self.enable_per_process_and_thread_time_limit,
Config::ENABLE_PER_PROCESS_AND_THREAD_TIME_LIMIT
)
self.enable_per_process_and_thread_memory_limit = NilValue.value_or_default(
self.enable_per_process_and_thread_memory_limit,
Config::ENABLE_PER_PROCESS_AND_THREAD_MEMORY_LIMIT
)
self.max_file_size ||= Config::MAX_FILE_SIZE
end
end

0 comments on commit a6f693a

Please sign in to comment.