team-ljyzipelo

공개
29줄1.1 KB
1use std::{io::Write, path::PathBuf, time::Duration};
2use worker_protocol::{
3 protocol::*,
4 wire::{Reader, Writer},
5};
6
7fn main() {
8 let executable = PathBuf::from(std::env::args_os().next().unwrap());
9 let mode = executable.file_stem().unwrap().to_string_lossy();
10 if mode.starts_with("hang") {
11 let parent = executable.parent().unwrap();
12 std::fs::write(parent.join("probe.pid.tmp"), std::process::id().to_string()).unwrap();
13 std::fs::rename(parent.join("probe.pid.tmp"), parent.join("probe.pid")).unwrap();
14 std::thread::sleep(Duration::from_secs(30));
15 return;
16 }
17 let mut reader = Reader::new(std::io::stdin());
18 let (job, _, _) = reader.read().unwrap().unwrap();
19 if mode.starts_with("wrong-action") {
20 Writer::new(std::io::stdout(), job)
21 .send(&Message::Accepted {
22 action: ActionKind::Extract,
23 encryption: false,
24 })
25 .unwrap();
26 } else if !mode.starts_with("early-exit") {
27 std::io::stdout().write_all(b"ZAW1").unwrap();
28 }
29}