summaryrefslogtreecommitdiffstats
path: root/crates/runner/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/runner/src/lib.rs')
-rw-r--r--crates/runner/src/lib.rs18
1 files changed, 3 insertions, 15 deletions
diff --git a/crates/runner/src/lib.rs b/crates/runner/src/lib.rs
index af1e2a7..d0d8317 100644
--- a/crates/runner/src/lib.rs
+++ b/crates/runner/src/lib.rs
@@ -6,12 +6,11 @@ mod tar;
mod task;
mod util;
-use std::{fs::File, os::unix::prelude::AsRawFd, path::Path};
+use std::fs::File;
use capctl::prctl;
use ipc_channel::ipc;
use nix::{
- fcntl,
sched::CloneFlags,
sys::{signal, stat, wait},
unistd::{self, Gid, Uid},
@@ -19,7 +18,6 @@ use nix::{
use serde::{Deserialize, Serialize};
use common::{error::*, types::*};
-use util::fs;
use self::{
jobserver::Jobserver,
@@ -123,7 +121,8 @@ impl Runner {
///
/// Unsafe: Do not call in multithreaded processes
pub unsafe fn new(options: &Options) -> Result<Self> {
- let lockfile = Runner::lock()?;
+ let lockfile = unix::lock(paths::LOCKFILE, true, false)
+ .context("Failed to get lock on build directory, is another instance running?")?;
let uid = unistd::geteuid();
let gid = unistd::getegid();
@@ -144,17 +143,6 @@ impl Runner {
Ok(Runner { channel: tx })
}
- fn lock() -> Result<File> {
- let path = Path::new(paths::LOCKFILE);
- fs::mkdir(path.parent().unwrap())?;
- let file = fs::create(path)?;
-
- fcntl::flock(file.as_raw_fd(), fcntl::FlockArg::LockExclusiveNonblock)
- .context("Failed to get lock on build directory, is another instance running?")?;
-
- Ok(file)
- }
-
pub fn spawn(&self, task: &Task) -> ipc::IpcReceiver<Result<TaskOutput>> {
let (reply_tx, reply_rx) = ipc::channel().expect("IPC channel creation failed");