-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathjudged.php
45 lines (39 loc) · 1.39 KB
/
judged.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
/**
* This file can only be invoked from cli by the following command:
* /usr/bin/php /PATH/TO/MOODLE/mod/assignment/type/onlinejudge/judged.php
* A judge daemon will be created.
*/
require_once(dirname(__FILE__) . '/../../../../config.php');
require_once("$CFG->dirroot/mod/assignment/lib.php");
require_once('assignment.class.php');
if (isset($_SERVER['REMOTE_ADDR'])) { // if the script is accessed via the web.
print_error('errorclionly', 'assignment_onlinejudge');
exit;
}
// Kill old daemon if it exists
if(!empty($CFG->assignment_oj_daemon_pid)) {
if (function_exists('posix_kill')) { // Linux
mtrace('Killing old judged. PID = ' . $CFG->assignment_oj_daemon_pid);
posix_kill($CFG->assignment_oj_daemon_pid, SIGTERM);
// Wait for its quit
while(posix_kill($CFG->assignment_oj_daemon_pid, 0))
sleep(0);
mtrace('done');
$CFG->assignment_oj_daemon_pid = 0;
} else {
mtrace("It seems that a judged (PID: $CFG->assignment_oj_daemon_pid) is still running.");
mtrace("It must be killed manually.");
mtrace("If it has been killed, enter 'C' to continue.");
$input = trim(fgets(STDIN));
if ($input != 'C' && $input != 'c')
die;
}
}
// Create daemon
$oj = new assignment_onlinejudge();
if (function_exists('pcntl_fork')) // Linux
$oj->fork_daemon();
else // Windows
$oj->daemon();
?>