Skip to content

Commit

Permalink
Adds FNQJOBID to queued process
Browse files Browse the repository at this point in the history
Closes #1
  • Loading branch information
mdaverde committed Apr 11, 2021
1 parent a63199b commit 2e7125a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/ops/queue.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{env, ffi, fs, io, path, process, time};
use std::io::Write;
use std::os::unix::prelude::*;
use std::{ffi, fs, io, path, process, time};

use nix::{errno, fcntl, sys, unistd};

Expand Down Expand Up @@ -178,6 +178,8 @@ pub fn queue(

task_file.set_permissions(fs::Permissions::from_mode(0o700))?;

let task_filename = task_handler.filename();

let cmd_c: ffi::CString =
ffi::CString::new(task_handler.cmd.as_os_str().as_bytes())?;
task_handler.args.insert(0, task_handler.cmd);
Expand All @@ -187,6 +189,7 @@ pub fn queue(
.map(|arg| ffi::CString::new(arg.as_os_str().as_bytes()))
.collect::<Result<Vec<ffi::CString>, ffi::NulError>>()?;

env::set_var("FNQJOBID", task_filename);
unistd::setsid()?;
if let Err(err) = unistd::execvp(&cmd_c, &args_c) {
if nix::Error::Sys(errno::Errno::ENOENT) == err {
Expand Down
2 changes: 1 addition & 1 deletion tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ setup
printf "# env tests\n"
check 'enqueueing env' f1=$($FNQ env)
$FNQ --wait
# check 'FNQJOBID is set' grep -q FNQJOBID=$f1 $f1
check 'FNQJOBID is set' grep -q FNQJOBID=$f1 $f1
)
teardown

Expand Down

0 comments on commit 2e7125a

Please sign in to comment.