From e1341569ec6666a434945d672803801de684977b Mon Sep 17 00:00:00 2001 From: slhmy <31381093+slhmy@users.noreply.github.com> Date: Mon, 9 Oct 2023 07:58:52 +0000 Subject: [PATCH] Upgrade dependencies --- Cargo.toml | 3 ++- judge-core/Cargo.toml | 4 ++-- judge-core/src/judge/interact.rs | 26 +++++++++++--------------- judge-server/Cargo.toml | 4 ++-- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index aaf37b4..8b13014 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,3 @@ [workspace] -members = ["judge-core", "judge-service", "judge-server", "judge-cli"] \ No newline at end of file +members = ["judge-core", "judge-service", "judge-server", "judge-cli"] +resolver = "2" \ No newline at end of file diff --git a/judge-core/Cargo.toml b/judge-core/Cargo.toml index 61d54e9..53deb10 100644 --- a/judge-core/Cargo.toml +++ b/judge-core/Cargo.toml @@ -10,7 +10,7 @@ description = "A judge library for online judge system" [dependencies] libc = "0.2" libseccomp = "0.3" -nix = "0.26" +nix = { version = "0.27", features = ["event", "fs", "process", "resource"] } log = "0.4" anyhow = "1.0" serde = "1" @@ -19,4 +19,4 @@ serde_json = "1" serde_yaml = "0.9" [dev-dependencies] -env_logger = "0.10.0" \ No newline at end of file +env_logger = "0.10.0" diff --git a/judge-core/src/judge/interact.rs b/judge-core/src/judge/interact.rs index ccdf027..1e28069 100644 --- a/judge-core/src/judge/interact.rs +++ b/judge-core/src/judge/interact.rs @@ -10,10 +10,11 @@ use crate::utils::get_pathbuf_str; use nix::errno::Errno; use nix::fcntl::{fcntl, FcntlArg, OFlag}; use nix::sys::epoll::{ - epoll_create1, epoll_ctl, epoll_wait, EpollCreateFlags, EpollEvent, EpollFlags, EpollOp, + Epoll, EpollCreateFlags, EpollEvent, EpollFlags, }; use nix::unistd::{pipe, read, write}; use std::fs::File; +use std::os::fd::BorrowedFd; use std::os::unix::io::{AsRawFd, RawFd}; use std::path::PathBuf; use std::time::Duration; @@ -84,15 +85,10 @@ fn read_msg_from_fd(from: RawFd) -> Result { Ok(msg) } -fn add_epoll_fd(epoll_fd: RawFd, fd: RawFd) -> Result<(), JudgeCoreError> { - let mut event = EpollEvent::new(EpollFlags::EPOLLIN, fd as u64); +fn add_epoll_fd(epoll: &Epoll, fd: RawFd) -> Result<(), JudgeCoreError> { + let event = EpollEvent::new(EpollFlags::EPOLLIN, fd as u64); log::debug!("Adding fd={} to epoll", fd); - Ok(epoll_ctl( - epoll_fd, - EpollOp::EpollCtlAdd, - fd, - Some(&mut event), - )?) + Ok(epoll.add(unsafe { BorrowedFd::borrow_raw(fd) }, event)?) } pub fn run_interact( @@ -101,7 +97,7 @@ pub fn run_interact( output_path: &String, ) -> Result, JudgeCoreError> { log::debug!("Creating epoll"); - let epoll_fd = epoll_create1(EpollCreateFlags::EPOLL_CLOEXEC)?; + let epoll = Epoll::new(EpollCreateFlags::EPOLL_CLOEXEC)?; log::debug!("Creating interact pipes"); let (proxy_read_user, user_write_proxy) = pipe()?; @@ -110,14 +106,14 @@ pub fn run_interact( let (interactor_read_proxy, proxy_write_interactor) = pipe()?; log::debug!("Adding read proxy fds to epoll"); - add_epoll_fd(epoll_fd, proxy_read_user)?; - add_epoll_fd(epoll_fd, proxy_read_interactor)?; + add_epoll_fd(&epoll, proxy_read_user)?; + add_epoll_fd(&epoll, proxy_read_interactor)?; log::debug!("Creating exit report pipes with epoll"); let (user_exit_read, user_exit_write) = pipe()?; let (interactor_exit_read, interactor_exit_write) = pipe()?; - add_epoll_fd(epoll_fd, user_exit_read)?; - add_epoll_fd(epoll_fd, interactor_exit_read)?; + add_epoll_fd(&epoll, user_exit_read)?; + add_epoll_fd(&epoll, interactor_exit_read)?; let mut user_listener = ProcessListener::new()?; let mut interact_listener = ProcessListener::new()?; @@ -165,7 +161,7 @@ pub fn run_interact( let mut interactor_exited = false; let mut option_user_result: Option = None; loop { - let num_events = epoll_wait(epoll_fd, &mut events, -1)?; + let num_events = epoll.wait(&mut events, -1)?; log::debug!("{} events found!", num_events); for event in events.iter().take(num_events) { diff --git a/judge-server/Cargo.toml b/judge-server/Cargo.toml index f2f59b1..81134e8 100644 --- a/judge-server/Cargo.toml +++ b/judge-server/Cargo.toml @@ -13,8 +13,8 @@ tokio = { version = "1", features = ["full"] } actix-web = "4" # Openapi generate -utoipa = { version = "3", features = ["actix_extras"] } -utoipa-swagger-ui = { version = "3", features = ["actix-web"] } +utoipa = { version = "4", features = ["actix_extras"] } +utoipa-swagger-ui = { version = "4", features = ["actix-web"] } # Support global variable lazy_static = "1.4"