From 258ccc09b0dd066808f51e93bb34c944ebf08c63 Mon Sep 17 00:00:00 2001 From: Jake Hillion Date: Fri, 20 May 2022 17:48:39 +0100 Subject: [PATCH 1/2] return correct exit code --- examples/fib/main.rs | 1 + examples/fib/specification.json | 12 ++++++++++++ src/main.rs | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 examples/fib/main.rs create mode 100644 examples/fib/specification.json diff --git a/examples/fib/main.rs b/examples/fib/main.rs new file mode 100644 index 0000000..f328e4d --- /dev/null +++ b/examples/fib/main.rs @@ -0,0 +1 @@ +fn main() {} diff --git a/examples/fib/specification.json b/examples/fib/specification.json new file mode 100644 index 0000000..3e339bf --- /dev/null +++ b/examples/fib/specification.json @@ -0,0 +1,12 @@ +{ + "entrypoints": { + "main1": { + "args": [ + "BinaryName" + ], + "environment": [ + "Stdout" + ] + } + } +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 5dbb0ae..62c853e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -98,7 +98,7 @@ fn main() { }; match run(&args) { - Ok(_) => exitcode::OK, + Ok(code) => code, Err(e) => { error!("error: {}", e); -1 -- 2.47.0 From 9fe48a7749d2919e14b522877455846587f6a5a7 Mon Sep 17 00:00:00 2001 From: Jake Hillion Date: Fri, 20 May 2022 17:48:51 +0100 Subject: [PATCH 2/2] fib example --- README.md | 10 ++++++++++ examples/fib/main.rs | 17 ++++++++++++++++- examples/fib/spec.json | 30 ++++++++++++++++++++++++++++++ examples/fib/specification.json | 12 ------------ 4 files changed, 56 insertions(+), 13 deletions(-) create mode 100644 examples/fib/spec.json delete mode 100644 examples/fib/specification.json diff --git a/README.md b/README.md index 35ce8de..c29320e 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,16 @@ ## Running the examples +### examples/fib + +The fib example performs fibonacci trivially on a fixed number. It is the most basic example of a process that requires no privilege, excluding `Stdout` to print the result. + +To run this example: + + cargo build + cargo build --example fib + target/debug/clone-shim -s examples/fib/spec.json target/debug/examples/fib + ### examples/basic The basic example instructs the shim to spawn two processes, each of which writes "hello from main{1,2}!" to stdout. diff --git a/examples/fib/main.rs b/examples/fib/main.rs index f328e4d..e364deb 100644 --- a/examples/fib/main.rs +++ b/examples/fib/main.rs @@ -1 +1,16 @@ -fn main() {} +fn main() { + println!("fib(1) = {}", fib(1)); + println!("fib(7) = {}", fib(7)); + println!("fib(19) = {}", fib(19)); +} + +fn fib(i: u64) -> u64 { + let mut a = 0; + let mut b = 1; + + for _ in 0..i { + (a, b) = (b, a + b); + } + + a +} diff --git a/examples/fib/spec.json b/examples/fib/spec.json new file mode 100644 index 0000000..a1ff278 --- /dev/null +++ b/examples/fib/spec.json @@ -0,0 +1,30 @@ +{ + "entrypoints": { + "fib": { + "args": [ + "BinaryName" + ], + "environment": [ + "Stdout", + { + "Filesystem": { + "host_path": "/lib/x86_64-linux-gnu/libgcc_s.so.1", + "environment_path": "/lib/libgcc_s.so.1" + } + }, + { + "Filesystem": { + "host_path": "/lib/x86_64-linux-gnu/libc.so.6", + "environment_path": "/lib/libc.so.6" + } + }, + { + "Filesystem": { + "host_path": "/lib64/ld-linux-x86-64.so.2", + "environment_path": "/lib64/ld-linux-x86-64.so.2" + } + } + ] + } + } +} \ No newline at end of file diff --git a/examples/fib/specification.json b/examples/fib/specification.json deleted file mode 100644 index 3e339bf..0000000 --- a/examples/fib/specification.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "entrypoints": { - "main1": { - "args": [ - "BinaryName" - ], - "environment": [ - "Stdout" - ] - } - } -} \ No newline at end of file -- 2.47.0