A code autograder for student homework submissions
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
475 B

  1. module KGrader
  2. class Jail
  3. def initialize(root)
  4. @root = root
  5. end
  6. def reset
  7. FileUtils.rm_rf @root
  8. end
  9. def init
  10. FileUtils.mkdir_p @root
  11. end
  12. def stage(source, target)
  13. FileUtils.cp source, File.join(@root, target)
  14. end
  15. def exec(command)
  16. pid = Process.fork do
  17. Dir.chdir @root
  18. # TODO: rlimit in exec, umask?
  19. Process.exec command
  20. end
  21. Process.waitpid pid, 0
  22. end
  23. end
  24. end