@ship.zone/runner 2.1.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.smartconfig.json +118 -3
- package/changelog.md +101 -0
- package/dist_rust/runnerworkspace_linux_amd64_musl +0 -0
- package/dist_rust/runnerworkspace_linux_amd64_musl.third-party-notices.json +679 -0
- package/dist_rust/runnerworkspace_linux_amd64_musl.third-party-notices.txt +15719 -0
- package/dist_rust/runnerworkspace_linux_amd64_musl.tsrust-build.json +5 -5
- package/dist_rust/runnerworkspace_linux_arm64_musl +0 -0
- package/dist_rust/runnerworkspace_linux_arm64_musl.third-party-notices.json +679 -0
- package/dist_rust/runnerworkspace_linux_arm64_musl.third-party-notices.txt +15719 -0
- package/dist_rust/runnerworkspace_linux_arm64_musl.tsrust-build.json +5 -5
- package/dist_ts/00_commitinfo_data.d.ts +8 -0
- package/dist_ts/00_commitinfo_data.js +9 -0
- package/dist_ts/api-client.d.ts +47 -0
- package/dist_ts/api-client.js +600 -0
- package/dist_ts/artifact-manager.d.ts +11 -0
- package/dist_ts/artifact-manager.js +140 -0
- package/dist_ts/attempt-state.d.ts +18 -0
- package/dist_ts/attempt-state.js +151 -0
- package/dist_ts/cache-manager.d.ts +13 -0
- package/dist_ts/cache-manager.js +300 -0
- package/dist_ts/cli-entry.d.ts +2 -0
- package/dist_ts/cli-entry.js +18 -0
- package/dist_ts/cli.d.ts +14 -0
- package/dist_ts/cli.js +243 -0
- package/dist_ts/config.d.ts +8 -0
- package/dist_ts/config.js +495 -0
- package/dist_ts/egress-proxy.d.ts +99 -0
- package/dist_ts/egress-proxy.js +607 -0
- package/dist_ts/errors.d.ts +41 -0
- package/dist_ts/errors.js +90 -0
- package/dist_ts/filesystem.d.ts +73 -0
- package/dist_ts/filesystem.js +207 -0
- package/dist_ts/index.d.ts +20 -0
- package/dist_ts/index.js +21 -0
- package/dist_ts/interfaces.d.ts +685 -0
- package/dist_ts/interfaces.js +3 -0
- package/dist_ts/log-sender.d.ts +26 -0
- package/dist_ts/log-sender.js +124 -0
- package/dist_ts/microvm-executor.d.ts +90 -0
- package/dist_ts/microvm-executor.js +1045 -0
- package/dist_ts/node-version.d.ts +11 -0
- package/dist_ts/node-version.js +43 -0
- package/dist_ts/npm-grants.d.ts +9 -0
- package/dist_ts/npm-grants.js +44 -0
- package/dist_ts/oci-registry.d.ts +73 -0
- package/dist_ts/oci-registry.js +508 -0
- package/dist_ts/plugins.d.ts +23 -0
- package/dist_ts/plugins.js +27 -0
- package/dist_ts/protocol-validator.d.ts +39 -0
- package/dist_ts/protocol-validator.js +488 -0
- package/dist_ts/redactor.d.ts +78 -0
- package/dist_ts/redactor.js +235 -0
- package/dist_ts/registration-state.d.ts +16 -0
- package/dist_ts/registration-state.js +171 -0
- package/dist_ts/runner.d.ts +65 -0
- package/dist_ts/runner.js +912 -0
- package/dist_ts/source-workspace.d.ts +10 -0
- package/dist_ts/source-workspace.js +125 -0
- package/dist_ts/spec-version.d.ts +11 -0
- package/dist_ts/spec-version.js +41 -0
- package/dist_ts/staging-scavenger.d.ts +7 -0
- package/dist_ts/staging-scavenger.js +63 -0
- package/dist_ts/state-owner.d.ts +74 -0
- package/dist_ts/state-owner.js +291 -0
- package/dist_ts/transfer-archive.d.ts +78 -0
- package/dist_ts/transfer-archive.js +1619 -0
- package/dist_ts/validation.d.ts +11 -0
- package/dist_ts/validation.js +79 -0
- package/dist_ts/vsock-protocol.d.ts +130 -0
- package/dist_ts/vsock-protocol.js +336 -0
- package/dist_ts/wire-schema.d.ts +10 -0
- package/dist_ts/wire-schema.js +114 -0
- package/native-notices/crates/bitflags-2.13.1/license-apache +201 -0
- package/native-notices/crates/bitflags-2.13.1/license-mit +25 -0
- package/native-notices/crates/cc-1.8.0/license-apache +201 -0
- package/native-notices/crates/cc-1.8.0/license-mit +25 -0
- package/native-notices/crates/cfg-if-1.0.4/license-apache +201 -0
- package/native-notices/crates/cfg-if-1.0.4/license-mit +25 -0
- package/native-notices/crates/cfg_aliases-0.2.2/license +9 -0
- package/native-notices/crates/cfg_aliases-0.2.2/notices.md +26 -0
- package/native-notices/crates/find-msvc-tools-0.1.14/license-apache +201 -0
- package/native-notices/crates/find-msvc-tools-0.1.14/license-mit +25 -0
- package/native-notices/crates/itoa-1.0.18/license-apache +176 -0
- package/native-notices/crates/itoa-1.0.18/license-mit +23 -0
- package/native-notices/crates/libc-0.2.189/license-apache +176 -0
- package/native-notices/crates/libc-0.2.189/license-mit +25 -0
- package/native-notices/crates/memchr-2.8.3/copying +3 -0
- package/native-notices/crates/memchr-2.8.3/license-mit +21 -0
- package/native-notices/crates/memchr-2.8.3/unlicense +24 -0
- package/native-notices/crates/nix-0.30.1/license +21 -0
- package/native-notices/crates/proc-macro2-1.0.107/license-apache +176 -0
- package/native-notices/crates/proc-macro2-1.0.107/license-mit +23 -0
- package/native-notices/crates/quote-1.0.47/license-apache +176 -0
- package/native-notices/crates/quote-1.0.47/license-mit +23 -0
- package/native-notices/crates/serde-1.0.229/license-apache +176 -0
- package/native-notices/crates/serde-1.0.229/license-mit +23 -0
- package/native-notices/crates/serde_core-1.0.229/license-apache +176 -0
- package/native-notices/crates/serde_core-1.0.229/license-mit +23 -0
- package/native-notices/crates/serde_derive-1.0.229/license-apache +176 -0
- package/native-notices/crates/serde_derive-1.0.229/license-mit +23 -0
- package/native-notices/crates/serde_json-1.0.151/license-apache +176 -0
- package/native-notices/crates/serde_json-1.0.151/license-mit +23 -0
- package/native-notices/crates/shlex-2.0.1/license-apache +13 -0
- package/native-notices/crates/shlex-2.0.1/license-mit +21 -0
- package/native-notices/crates/syn-3.0.3/license-apache +176 -0
- package/native-notices/crates/syn-3.0.3/license-mit +23 -0
- package/native-notices/crates/tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8/license-apache +201 -0
- package/native-notices/crates/tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8/license-mit +25 -0
- package/native-notices/crates/tikv-jemallocator-0.7.0/license-apache +201 -0
- package/native-notices/crates/tikv-jemallocator-0.7.0/license-mit +25 -0
- package/native-notices/crates/unicode-ident-1.0.24/license-apache +176 -0
- package/native-notices/crates/unicode-ident-1.0.24/license-mit +23 -0
- package/native-notices/crates/unicode-ident-1.0.24/license-unicode +39 -0
- package/native-notices/crates/zmij-1.0.23/license-mit +23 -0
- package/native-notices/manifest.json +763 -0
- package/native-notices/native/tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8/jemalloc-5.3.1/jemalloc-copying +27 -0
- package/native-notices/readme.md +46 -0
- package/native-notices/runtime/gcc/gpl-3.0.txt +674 -0
- package/native-notices/runtime/gcc/runtime-library-exception-3.1.txt +73 -0
- package/native-notices/runtime/libunwind-22.1.2/license.txt +311 -0
- package/native-notices/runtime/musl-1.2.5/copyright +193 -0
- package/native-notices/rust/compiler-builtins-license.txt +275 -0
- package/native-notices/rust/copyright-library.html +8266 -0
- package/native-notices/rust/crates/addr2line-0.25.1/license-apache +201 -0
- package/native-notices/rust/crates/addr2line-0.25.1/license-mit +25 -0
- package/native-notices/rust/crates/adler2-2.0.1/license-0bsd +12 -0
- package/native-notices/rust/crates/adler2-2.0.1/license-apache +201 -0
- package/native-notices/rust/crates/adler2-2.0.1/license-mit +23 -0
- package/native-notices/rust/crates/memchr-2.7.6/copying +3 -0
- package/native-notices/rust/crates/memchr-2.7.6/license-mit +21 -0
- package/native-notices/rust/crates/memchr-2.7.6/unlicense +24 -0
- package/native-notices/rust/crates/miniz_oxide-0.8.9/license +25 -0
- package/native-notices/rust/crates/miniz_oxide-0.8.9/license-apache.md +177 -0
- package/native-notices/rust/crates/miniz_oxide-0.8.9/license-mit.md +24 -0
- package/native-notices/rust/crates/miniz_oxide-0.8.9/license-zlib.md +14 -0
- package/native-notices/rust/crates/object-0.37.3/license-apache +201 -0
- package/native-notices/rust/crates/object-0.37.3/license-mit +25 -0
- package/native-notices/rust/licenses/apache-2.0.txt +73 -0
- package/native-notices/rust/licenses/bsd-2-clause.txt +9 -0
- package/native-notices/rust/licenses/cc-by-sa-4.0.txt +427 -0
- package/native-notices/rust/licenses/gcc-exception-3.1.txt +30 -0
- package/native-notices/rust/licenses/gpl-2.0-only.txt +133 -0
- package/native-notices/rust/licenses/gpl-3.0-or-later.txt +202 -0
- package/native-notices/rust/licenses/isc.txt +7 -0
- package/native-notices/rust/licenses/llvm-exception.txt +15 -0
- package/native-notices/rust/licenses/mit.txt +9 -0
- package/native-notices/rust/licenses/ncsa.txt +29 -0
- package/native-notices/rust/licenses/ofl-1.1.txt +43 -0
- package/native-notices/rust/licenses/unicode-3.0.txt +39 -0
- package/package.json +31 -26
- package/readme.md +157 -95
- package/rust/.cargo/config.toml +1 -1
- package/rust/Cargo.lock +1 -0
- package/rust/Cargo.toml +3 -2
- package/rust/src/cpio.rs +147 -0
- package/rust/src/extfs.rs +747 -0
- package/rust/src/guest.rs +2411 -0
- package/rust/src/lib.rs +197 -1
- package/rust/src/main.rs +7 -2
- package/rust/src/oci_tar.rs +842 -0
- package/rust-toolchain.toml +4 -0
- package/ts/00_commitinfo_data.ts +2 -2
- package/ts/api-client.ts +29 -8
- package/ts/artifact-manager.ts +9 -7
- package/ts/attempt-state.ts +75 -84
- package/ts/cache-manager.ts +22 -28
- package/ts/cli-entry.ts +17 -0
- package/ts/cli.ts +86 -53
- package/ts/config.ts +146 -62
- package/ts/egress-proxy.ts +649 -0
- package/ts/errors.ts +19 -0
- package/ts/filesystem.ts +316 -0
- package/ts/index.ts +20 -15
- package/ts/interfaces.ts +105 -23
- package/ts/log-sender.ts +4 -4
- package/ts/microvm-executor.ts +1265 -0
- package/ts/node-version.ts +49 -0
- package/ts/npm-grants.ts +49 -0
- package/ts/oci-registry.ts +649 -0
- package/ts/plugins.ts +25 -3
- package/ts/protocol-validator.ts +34 -30
- package/ts/redactor.ts +2 -2
- package/ts/registration-state.ts +82 -90
- package/ts/runner.ts +81 -34
- package/ts/source-workspace.ts +11 -8
- package/ts/spec-version.ts +2 -2
- package/ts/staging-scavenger.ts +37 -26
- package/ts/state-owner.ts +353 -0
- package/ts/transfer-archive.ts +214 -243
- package/ts/validation.ts +1 -1
- package/ts/vsock-protocol.ts +437 -0
- package/ts/wire-schema.ts +3 -3
- package/deno.json +0 -56
- package/deno.lock +0 -1495
- package/dist_npm/mod.d.ts +0 -967
- package/dist_npm/mod.js +0 -10058
- package/mod.ts +0 -8
- package/musl-copyright.md +0 -81
- package/third-party-licenses.md +0 -187
- package/ts/oci-executor.ts +0 -3137
package/rust/src/lib.rs
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
#[cfg(not(unix))]
|
|
2
2
|
compile_error!("runnerworkspace requires a Unix platform");
|
|
3
3
|
|
|
4
|
+
pub mod cpio;
|
|
5
|
+
pub mod extfs;
|
|
6
|
+
pub mod guest;
|
|
7
|
+
pub mod oci_tar;
|
|
8
|
+
|
|
4
9
|
use serde::Serialize;
|
|
5
10
|
use std::ffi::CString;
|
|
6
11
|
use std::ffi::OsString;
|
|
@@ -17,6 +22,8 @@ const COPY_BUFFER_SIZE: usize = 64 * 1024;
|
|
|
17
22
|
const MAXIMUM_TRAVERSAL_DEPTH: usize = 256;
|
|
18
23
|
const HOLD_PARK_INTERVAL: Duration = Duration::from_millis(100);
|
|
19
24
|
const RESERVE_FILE_NAME: &str = ".runnerworkspace-reserve";
|
|
25
|
+
const STATE_OWNER_LOCK_NAME: &str = ".runner-owner.lock";
|
|
26
|
+
const STATE_OWNER_LOCK_MODE: u32 = 0o600;
|
|
20
27
|
const DESTINATION_CLEANUP_FAILURE: &str = "unable to clean destination after failure";
|
|
21
28
|
const RESERVE_CLEANUP_FAILURE: &str = "unable to clean volume after reserve failure";
|
|
22
29
|
|
|
@@ -24,14 +31,33 @@ static HOLD_TERMINATION_REQUESTED: AtomicBool = AtomicBool::new(false);
|
|
|
24
31
|
|
|
25
32
|
type Result<T> = std::result::Result<T, Error>;
|
|
26
33
|
|
|
34
|
+
/// Exit code of `own-state` when another process already holds the runner state lock.
|
|
35
|
+
pub const STATE_OWNED_ELSEWHERE_EXIT_CODE: i32 = 3;
|
|
36
|
+
|
|
27
37
|
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
|
28
38
|
pub struct Error {
|
|
29
39
|
message: &'static str,
|
|
40
|
+
exit_code: i32,
|
|
30
41
|
}
|
|
31
42
|
|
|
32
43
|
impl Error {
|
|
33
44
|
const fn new(message: &'static str) -> Self {
|
|
34
|
-
Self {
|
|
45
|
+
Self {
|
|
46
|
+
message,
|
|
47
|
+
exit_code: 1,
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const fn state_owned_elsewhere() -> Self {
|
|
52
|
+
Self {
|
|
53
|
+
message: "runner state is owned by another process",
|
|
54
|
+
exit_code: STATE_OWNED_ELSEWHERE_EXIT_CODE,
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/// The process exit code that reports this error.
|
|
59
|
+
pub const fn exit_code(&self) -> i32 {
|
|
60
|
+
self.exit_code
|
|
35
61
|
}
|
|
36
62
|
}
|
|
37
63
|
|
|
@@ -630,10 +656,134 @@ where
|
|
|
630
656
|
ownership,
|
|
631
657
|
)?)
|
|
632
658
|
}
|
|
659
|
+
"own-state" => {
|
|
660
|
+
let state_directory = PathBuf::from(
|
|
661
|
+
iterator
|
|
662
|
+
.next()
|
|
663
|
+
.ok_or_else(|| Error::new("own-state requires a state directory"))?,
|
|
664
|
+
);
|
|
665
|
+
if iterator.next().is_some() {
|
|
666
|
+
return Err(Error::new("own-state accepts only a state directory"));
|
|
667
|
+
}
|
|
668
|
+
own_state(&state_directory)
|
|
669
|
+
}
|
|
670
|
+
"build-initrd" => {
|
|
671
|
+
let mut options = Options::parse(iterator)?;
|
|
672
|
+
let binary = PathBuf::from(options.take_one("--binary")?);
|
|
673
|
+
let output = PathBuf::from(options.take_one("--output")?);
|
|
674
|
+
options.finish()?;
|
|
675
|
+
let bytes = cpio::build_initrd(&binary, &output)?;
|
|
676
|
+
emit_json(&serde_json::json!({ "bytes": bytes }))
|
|
677
|
+
}
|
|
678
|
+
"build-rootfs" => {
|
|
679
|
+
let mut options = Options::parse(iterator)?;
|
|
680
|
+
let output = PathBuf::from(options.take_one("--output")?);
|
|
681
|
+
let maximum_bytes = parse_u64(options.take_one("--maximum-bytes")?)?;
|
|
682
|
+
let layers = options
|
|
683
|
+
.take_many("--layer")
|
|
684
|
+
.into_iter()
|
|
685
|
+
.map(PathBuf::from)
|
|
686
|
+
.collect::<Vec<_>>();
|
|
687
|
+
options.finish()?;
|
|
688
|
+
let layer_refs = layers.iter().map(PathBuf::as_path).collect::<Vec<_>>();
|
|
689
|
+
let root = oci_tar::apply_oci_layers(&layer_refs, maximum_bytes)?;
|
|
690
|
+
let bytes = extfs::write_ext2_image(&root, &output)?;
|
|
691
|
+
emit_json(&serde_json::json!({ "bytes": bytes }))
|
|
692
|
+
}
|
|
693
|
+
"guest-init" => {
|
|
694
|
+
let mut options = Options::parse(iterator)?;
|
|
695
|
+
let unix_socket = options.take_one("--unix-socket").ok().map(PathBuf::from);
|
|
696
|
+
let workspace = options.take_one("--workspace").ok().map(PathBuf::from);
|
|
697
|
+
options.finish()?;
|
|
698
|
+
match (unix_socket, workspace) {
|
|
699
|
+
(Some(sock), Some(ws)) => guest::serve_unix_socket(&sock, &ws),
|
|
700
|
+
(None, None) => guest::run_pid1(),
|
|
701
|
+
_ => Err(Error::new(
|
|
702
|
+
"guest-init requires both --unix-socket and --workspace or neither",
|
|
703
|
+
)),
|
|
704
|
+
}
|
|
705
|
+
}
|
|
633
706
|
_ => Err(Error::new("unknown command")),
|
|
634
707
|
}
|
|
635
708
|
}
|
|
636
709
|
|
|
710
|
+
/// Holds the exclusive runner state lock for the lifetime of the parent runner process.
|
|
711
|
+
///
|
|
712
|
+
/// The lock is a kernel `flock` on `<state>/.runner-owner.lock`, so it ends with this process.
|
|
713
|
+
/// Once held, `locked` is printed and the helper waits for end of input on stdin, which the runner
|
|
714
|
+
/// closes on release or exit. The parent-death signal is a backstop for a parent that dies
|
|
715
|
+
/// without closing stdin. Interactive and service-manager termination signals are ignored, so
|
|
716
|
+
/// the lock outlives a graceful runner shutdown until the runner releases it.
|
|
717
|
+
fn own_state(state_directory: &Path) -> Result<()> {
|
|
718
|
+
use nix::sys::signal::{self, SigHandler, Signal};
|
|
719
|
+
|
|
720
|
+
let parent = std::os::unix::process::parent_id();
|
|
721
|
+
nix::sys::prctl::set_pdeathsig(Signal::SIGKILL)
|
|
722
|
+
.map_err(|_| Error::new("unable to set the parent-death signal"))?;
|
|
723
|
+
if std::os::unix::process::parent_id() != parent {
|
|
724
|
+
return Err(Error::new("runner exited before the state lock was taken"));
|
|
725
|
+
}
|
|
726
|
+
for ignored in [Signal::SIGINT, Signal::SIGTERM, Signal::SIGHUP] {
|
|
727
|
+
// Ignoring a signal installs no handler code, so no async-signal-safety rule applies.
|
|
728
|
+
unsafe { signal::signal(ignored, SigHandler::SigIgn) }
|
|
729
|
+
.map_err(|_| Error::new("unable to ignore termination signals"))?;
|
|
730
|
+
}
|
|
731
|
+
let lock = lock_state_directory(state_directory)?;
|
|
732
|
+
{
|
|
733
|
+
let stdout = io::stdout();
|
|
734
|
+
let mut output = stdout.lock();
|
|
735
|
+
output
|
|
736
|
+
.write_all(b"locked\n")
|
|
737
|
+
.and_then(|()| output.flush())
|
|
738
|
+
.map_err(|_| Error::new("unable to report the state lock"))?;
|
|
739
|
+
}
|
|
740
|
+
wait_for_end_of_input(io::stdin().lock())?;
|
|
741
|
+
drop(lock);
|
|
742
|
+
Ok(())
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
fn lock_state_directory(state_directory: &Path) -> Result<nix::fcntl::Flock<fs::File>> {
|
|
746
|
+
use nix::fcntl::{Flock, FlockArg};
|
|
747
|
+
|
|
748
|
+
require_absolute(state_directory)?;
|
|
749
|
+
let file = OpenOptions::new()
|
|
750
|
+
.read(true)
|
|
751
|
+
.write(true)
|
|
752
|
+
.create(true)
|
|
753
|
+
.mode(STATE_OWNER_LOCK_MODE)
|
|
754
|
+
.custom_flags(nix::libc::O_CLOEXEC | nix::libc::O_NOFOLLOW)
|
|
755
|
+
.open(state_directory.join(STATE_OWNER_LOCK_NAME))
|
|
756
|
+
.map_err(|_| Error::new("unable to open the runner state lock"))?;
|
|
757
|
+
let metadata = file
|
|
758
|
+
.metadata()
|
|
759
|
+
.map_err(|_| Error::new("unable to inspect the runner state lock"))?;
|
|
760
|
+
if !metadata.file_type().is_file()
|
|
761
|
+
|| metadata.nlink() != 1
|
|
762
|
+
|| metadata.uid() != nix::unistd::geteuid().as_raw()
|
|
763
|
+
{
|
|
764
|
+
return Err(Error::new(
|
|
765
|
+
"runner state lock must be a single-link regular file owned by the runner",
|
|
766
|
+
));
|
|
767
|
+
}
|
|
768
|
+
match Flock::lock(file, FlockArg::LockExclusiveNonblock) {
|
|
769
|
+
Ok(lock) => Ok(lock),
|
|
770
|
+
Err((_, nix::errno::Errno::EWOULDBLOCK)) => Err(Error::state_owned_elsewhere()),
|
|
771
|
+
Err(_) => Err(Error::new("unable to lock the runner state")),
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
fn wait_for_end_of_input<R: Read>(mut input: R) -> Result<()> {
|
|
776
|
+
let mut buffer = [0_u8; 64];
|
|
777
|
+
loop {
|
|
778
|
+
match input.read(&mut buffer) {
|
|
779
|
+
Ok(0) => return Ok(()),
|
|
780
|
+
Ok(_) => {}
|
|
781
|
+
Err(error) if error.kind() == io::ErrorKind::Interrupted => {}
|
|
782
|
+
Err(_) => return Err(Error::new("unable to read the state owner input")),
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
|
|
637
787
|
fn emit_json<T: Serialize>(value: &T) -> Result<()> {
|
|
638
788
|
let stdout = io::stdout();
|
|
639
789
|
let mut output = stdout.lock();
|
|
@@ -1730,6 +1880,52 @@ mod tests {
|
|
|
1730
1880
|
assert!(termination_requested.load(Ordering::Relaxed));
|
|
1731
1881
|
}
|
|
1732
1882
|
|
|
1883
|
+
#[test]
|
|
1884
|
+
fn state_lock_is_exclusive_and_released_with_its_holder() {
|
|
1885
|
+
let temporary = TestDirectory::new();
|
|
1886
|
+
let first = lock_state_directory(&temporary.path).expect("first lock");
|
|
1887
|
+
assert_eq!(
|
|
1888
|
+
lock_state_directory(&temporary.path).unwrap_err(),
|
|
1889
|
+
Error::state_owned_elsewhere()
|
|
1890
|
+
);
|
|
1891
|
+
assert_eq!(
|
|
1892
|
+
Error::state_owned_elsewhere().exit_code(),
|
|
1893
|
+
STATE_OWNED_ELSEWHERE_EXIT_CODE
|
|
1894
|
+
);
|
|
1895
|
+
drop(first);
|
|
1896
|
+
let second = lock_state_directory(&temporary.path).expect("lock after release");
|
|
1897
|
+
let metadata = fs::symlink_metadata(temporary.child(STATE_OWNER_LOCK_NAME)).unwrap();
|
|
1898
|
+
assert_eq!(metadata.permissions().mode() & 0o777, STATE_OWNER_LOCK_MODE);
|
|
1899
|
+
drop(second);
|
|
1900
|
+
}
|
|
1901
|
+
|
|
1902
|
+
#[test]
|
|
1903
|
+
fn state_lock_rejects_links_and_relative_directories() {
|
|
1904
|
+
let temporary = TestDirectory::new();
|
|
1905
|
+
let target = temporary.child("target");
|
|
1906
|
+
write_file(&target, b"");
|
|
1907
|
+
std::os::unix::fs::symlink(&target, temporary.child(STATE_OWNER_LOCK_NAME)).unwrap();
|
|
1908
|
+
assert_eq!(
|
|
1909
|
+
lock_state_directory(&temporary.path).unwrap_err(),
|
|
1910
|
+
Error::new("unable to open the runner state lock")
|
|
1911
|
+
);
|
|
1912
|
+
fs::remove_file(temporary.child(STATE_OWNER_LOCK_NAME)).unwrap();
|
|
1913
|
+
fs::hard_link(&target, temporary.child(STATE_OWNER_LOCK_NAME)).unwrap();
|
|
1914
|
+
assert_eq!(
|
|
1915
|
+
lock_state_directory(&temporary.path).unwrap_err(),
|
|
1916
|
+
Error::new("runner state lock must be a single-link regular file owned by the runner")
|
|
1917
|
+
);
|
|
1918
|
+
assert_eq!(
|
|
1919
|
+
lock_state_directory(Path::new("relative")).unwrap_err(),
|
|
1920
|
+
Error::new("root paths must be absolute")
|
|
1921
|
+
);
|
|
1922
|
+
}
|
|
1923
|
+
|
|
1924
|
+
#[test]
|
|
1925
|
+
fn state_owner_waits_for_end_of_input() {
|
|
1926
|
+
wait_for_end_of_input(&b"ignored input"[..]).expect("end of input");
|
|
1927
|
+
}
|
|
1928
|
+
|
|
1733
1929
|
#[test]
|
|
1734
1930
|
fn reports_statvfs_values() {
|
|
1735
1931
|
let temporary = TestDirectory::new();
|
package/rust/src/main.rs
CHANGED
|
@@ -3,8 +3,13 @@
|
|
|
3
3
|
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
|
|
4
4
|
|
|
5
5
|
fn main() {
|
|
6
|
-
|
|
6
|
+
let result = if runnerworkspace::guest::invoked_as_pid1() {
|
|
7
|
+
runnerworkspace::guest::run_pid1()
|
|
8
|
+
} else {
|
|
9
|
+
runnerworkspace::run(std::env::args_os().skip(1))
|
|
10
|
+
};
|
|
11
|
+
if let Err(error) = result {
|
|
7
12
|
eprintln!("runnerworkspace: {error}");
|
|
8
|
-
std::process::exit(
|
|
13
|
+
std::process::exit(error.exit_code());
|
|
9
14
|
}
|
|
10
15
|
}
|