]>
Commit | Line | Data |
---|---|---|
1 | package Gruntmaster::Daemon::Runner::Interactive; | |
2 | ||
3 | use 5.014000; | |
4 | use strict; | |
5 | use warnings; | |
6 | ||
7 | use File::Slurp qw/slurp/; | |
8 | use Gruntmaster::Daemon::Constants qw/WA/; | |
9 | use Log::Log4perl qw/get_logger/; | |
10 | use POSIX qw/mkfifo/; | |
11 | use Try::Tiny; | |
12 | ||
13 | our $VERSION = '5999-TRIAL'; | |
14 | ||
15 | ################################################## | |
16 | ||
17 | sub run{ | |
18 | my ($test, $meta) = @_; | |
19 | get_logger->trace("Running on test $test..."); | |
20 | ||
21 | mkfifo 'fifo1', 0600 or die $! unless -e 'fifo1'; | |
22 | mkfifo 'fifo2', 0600 or die $! unless -e 'fifo2'; | |
23 | ||
24 | my $ret = fork // get_logger->logdie("Fork failed: $!"); | |
25 | if ($ret) { | |
26 | $meta->{files}{prog}{run}->($meta->{files}{prog}{name}, fds => [qw/0 fifo1 1 >fifo2/], map {defined $meta->{$_} ? ($_ => $meta->{$_}) : () } qw/timeout mlimit/); | |
27 | waitpid $ret, 0; | |
28 | die [WA, "Wrong Answer"] if $?; | |
29 | } else { | |
30 | try { | |
31 | $meta->{files}{int}{run}->($meta->{files}{int}{name}, fds => [qw/1 >fifo1 0 fifo2 4 >result/]); | |
32 | } catch { | |
33 | exit 1; | |
34 | }; | |
35 | exit | |
36 | } | |
37 | ||
38 | scalar slurp 'result' | |
39 | } | |
40 | ||
41 | 1 |