A code autograder for student homework submissions
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

33 lignes
633 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, logpath)
  16. pid = Process.fork do
  17. fp = File.open(logpath, 'w+')
  18. Dir.chdir @root
  19. # TODO: rlimit in exec, umask?
  20. Process.exec command, :in => :close, :out => fp, :err => fp,
  21. :close_others => true
  22. end
  23. Process.waitpid pid, 0
  24. $?.exited? && $?.exitstatus == 0
  25. end
  26. end
  27. end