cvisor 0.1.0-x86_64-linux-musl → 0.2.0-x86_64-linux-musl
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.
- checksums.yaml +4 -4
- data/README.md +21 -5
- data/lib/cvisor.rb +18 -5
- data/native/libcvisor-x86_64.so +0 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7349bc76588bd03fd93a0e5f745fef82700fa1bae7e6531280947c7c87573bba
|
|
4
|
+
data.tar.gz: 4103d75dcb922bd6599e986fd700697d1803b309f3db0539cd04ec05db828e8e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ad2ede5fe2200c27f45794d82cce9b535b018fea4946e39b6ec4d3ea8970aaf1b59924961cd4f8189453b084c6f73228617d62647709ea2ebf504fa19deb7490
|
|
7
|
+
data.tar.gz: 00db936505362b486b340e8a3c54ed7d94188cc2977b4e0f9467e85516d1587585c0806fbbc381c8654fe93bf52cc7d305ae43ae189f877e6efdae959bf7b863
|
data/README.md
CHANGED
|
@@ -9,13 +9,29 @@ require "cvisor"
|
|
|
9
9
|
|
|
10
10
|
sb = Cvisor::Sandbox.new
|
|
11
11
|
out = sb.run("echo hello")
|
|
12
|
-
puts out.stdout
|
|
13
|
-
puts out.stderr
|
|
12
|
+
puts out.stdout # "hello\n"
|
|
13
|
+
puts out.stderr # ""
|
|
14
|
+
puts out.exit_code # 0
|
|
14
15
|
```
|
|
15
16
|
|
|
16
|
-
`Sandbox#run(cmd)` blocks until the sandboxed command exits and
|
|
17
|
-
`Output` with `#stdout` / `#stderr` (String)
|
|
18
|
-
`#stderr_bytes
|
|
17
|
+
`Sandbox#run(cmd, timeout_ms: nil)` blocks until the sandboxed command exits and
|
|
18
|
+
returns an `Output` with `#stdout` / `#stderr` (String), `#stdout_bytes` /
|
|
19
|
+
`#stderr_bytes`, and `#exit_code` (Integer, shell convention: status, or
|
|
20
|
+
128+signo when killed by a signal).
|
|
21
|
+
|
|
22
|
+
Pass a positive `timeout_ms:` to SIGKILL the guest after that many
|
|
23
|
+
milliseconds; a timed-out run reports exit code 137:
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
sb.run("sleep 30", timeout_ms: 300).exit_code # 137
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`Sandbox#set_allow_network(allow)` toggles outbound INET/INET6 networking for
|
|
30
|
+
the sandbox (allowed by default):
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
sb.set_allow_network(false) # deny outbound networking
|
|
34
|
+
```
|
|
19
35
|
|
|
20
36
|
## Interactive console
|
|
21
37
|
|
data/lib/cvisor.rb
CHANGED
|
@@ -27,8 +27,11 @@ module Cvisor
|
|
|
27
27
|
extern "void* cvisor_sandbox_new(void)"
|
|
28
28
|
extern "void cvisor_sandbox_free(void*)"
|
|
29
29
|
extern "void cvisor_sandbox_set_log_level(void*, int)"
|
|
30
|
+
extern "void cvisor_sandbox_set_allow_network(void*, int)"
|
|
30
31
|
extern "void* cvisor_run(void*, const char*)"
|
|
32
|
+
extern "void* cvisor_run_timeout(void*, const char*, unsigned long long)"
|
|
31
33
|
extern "void cvisor_output_free(void*)"
|
|
34
|
+
extern "int cvisor_output_exit_code(void*)"
|
|
32
35
|
extern "void* cvisor_output_stdout(void*, void*)"
|
|
33
36
|
extern "void* cvisor_output_stderr(void*, void*)"
|
|
34
37
|
extern "void cvisor_bytes_free(void*, size_t)"
|
|
@@ -36,11 +39,12 @@ module Cvisor
|
|
|
36
39
|
|
|
37
40
|
# Captured output of one run.
|
|
38
41
|
class Output
|
|
39
|
-
attr_reader :stdout_bytes, :stderr_bytes
|
|
42
|
+
attr_reader :stdout_bytes, :stderr_bytes, :exit_code
|
|
40
43
|
|
|
41
|
-
def initialize(stdout_bytes, stderr_bytes)
|
|
44
|
+
def initialize(stdout_bytes, stderr_bytes, exit_code)
|
|
42
45
|
@stdout_bytes = stdout_bytes
|
|
43
46
|
@stderr_bytes = stderr_bytes
|
|
47
|
+
@exit_code = exit_code
|
|
44
48
|
end
|
|
45
49
|
|
|
46
50
|
def stdout = @stdout_bytes.force_encoding("UTF-8")
|
|
@@ -57,12 +61,21 @@ module Cvisor
|
|
|
57
61
|
Native.cvisor_sandbox_set_log_level(@ptr, level == "DEBUG" ? 1 : 0)
|
|
58
62
|
end
|
|
59
63
|
|
|
60
|
-
def
|
|
61
|
-
|
|
64
|
+
def set_allow_network(allow)
|
|
65
|
+
Native.cvisor_sandbox_set_allow_network(@ptr, allow ? 1 : 0)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def run(command, timeout_ms: nil)
|
|
69
|
+
out = if timeout_ms.is_a?(Integer) && timeout_ms.positive?
|
|
70
|
+
Native.cvisor_run_timeout(@ptr, command, timeout_ms)
|
|
71
|
+
else
|
|
72
|
+
Native.cvisor_run(@ptr, command)
|
|
73
|
+
end
|
|
62
74
|
raise "sandbox run failed" if out.null?
|
|
63
75
|
begin
|
|
64
76
|
Output.new(read_output(out, :cvisor_output_stdout),
|
|
65
|
-
read_output(out, :cvisor_output_stderr)
|
|
77
|
+
read_output(out, :cvisor_output_stderr),
|
|
78
|
+
Native.cvisor_output_exit_code(out))
|
|
66
79
|
ensure
|
|
67
80
|
Native.cvisor_output_free(out)
|
|
68
81
|
end
|
data/native/libcvisor-x86_64.so
CHANGED
|
Binary file
|