-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathlib.rs
More file actions
70 lines (55 loc) · 2.26 KB
/
lib.rs
File metadata and controls
70 lines (55 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#![cfg_attr(target_os = "windows", feature(windows_process_extensions_main_thread_handle))]
#![feature(once_cell_try)]
// Persist the injected DLL/shared library somewhere in the filesystem.
// Not needed on musl (seccomp-only tracking).
#[cfg(not(target_env = "musl"))]
mod artifact;
pub mod error;
mod ipc;
#[cfg(unix)]
#[path = "./unix/mod.rs"]
mod os_impl;
#[cfg(target_os = "windows")]
#[path = "./windows/mod.rs"]
mod os_impl;
#[cfg(unix)]
mod arena;
mod command;
use std::{env::temp_dir, fs::create_dir, io, process::ExitStatus, sync::LazyLock};
pub use command::Command;
pub use fspy_shared::ipc::{AccessMode, PathAccess};
use futures_util::future::BoxFuture;
pub use os_impl::PathAccessIterable;
use os_impl::SpyImpl;
use tokio::process::{ChildStderr, ChildStdin, ChildStdout};
/// The result of a tracked child process upon its termination.
pub struct ChildTermination {
/// The exit status of the child process.
pub status: ExitStatus,
/// The path accesses captured from the child process.
pub path_accesses: PathAccessIterable,
}
pub struct TrackedChild {
/// The handle for writing to the child's standard input (stdin), if it has
/// been captured.
pub stdin: Option<ChildStdin>,
/// The handle for reading from the child's standard output (stdout), if it
/// has been captured.
pub stdout: Option<ChildStdout>,
/// The handle for reading from the child's standard error (stderr), if it
/// has been captured.
pub stderr: Option<ChildStderr>,
/// The future that resolves to exit status and path accesses when the process exits.
pub wait_handle: BoxFuture<'static, io::Result<ChildTermination>>,
/// A duplicated process handle of the child, captured before the tokio `Child`
/// is moved into the background wait task. This is an independently owned handle
/// (via `DuplicateHandle`) so it remains valid even after tokio closes its copy.
/// Callers can use this to assign the process to a Win32 Job Object.
#[cfg(windows)]
pub process_handle: std::os::windows::io::OwnedHandle,
}
pub(crate) static SPY_IMPL: LazyLock<SpyImpl> = LazyLock::new(|| {
let tmp_dir = temp_dir().join("fspy");
let _ = create_dir(&tmp_dir);
SpyImpl::init_in(&tmp_dir).expect("Failed to initialize global spy")
});