bunpen: implement --bunpen-debug=n for more controlled logging
This commit is contained in:
@@ -6,7 +6,7 @@ export type cli_opts = struct {
|
|||||||
// command to `exec` within the sandbox
|
// command to `exec` within the sandbox
|
||||||
cmd: []str,
|
cmd: []str,
|
||||||
// `--bunpen-debug`
|
// `--bunpen-debug`
|
||||||
debug: bool,
|
debug: uint,
|
||||||
drop_shell: bool,
|
drop_shell: bool,
|
||||||
// `--bunpen-help`
|
// `--bunpen-help`
|
||||||
help: bool,
|
help: bool,
|
||||||
@@ -25,8 +25,9 @@ export fn usage() void = {
|
|||||||
fmt::println("sandbox args:")!;
|
fmt::println("sandbox args:")!;
|
||||||
fmt::println(" --bunpen-help")!;
|
fmt::println(" --bunpen-help")!;
|
||||||
fmt::println(" show this message")!;
|
fmt::println(" show this message")!;
|
||||||
fmt::println(" --bunpen-debug")!;
|
fmt::println(" --bunpen-debug[=n]")!;
|
||||||
fmt::println(" print debug messages to stderr")!;
|
fmt::println(" print debug messages to stderr")!;
|
||||||
|
fmt::println(" omit `n` for light debugging, or specify n=0/1/2/3 where higher = more verbose")!;
|
||||||
fmt::println(" --bunpen-drop-shell")!;
|
fmt::println(" --bunpen-drop-shell")!;
|
||||||
fmt::println(" instead of running the program, drop into an interactive shell")!;
|
fmt::println(" instead of running the program, drop into an interactive shell")!;
|
||||||
// fmt::println(" --bunpen-replace-cli <bin>")!;
|
// fmt::println(" --bunpen-replace-cli <bin>")!;
|
||||||
@@ -84,7 +85,11 @@ export fn parse_args(args: []str) cli_opts = {
|
|||||||
next = &args[idx+1];
|
next = &args[idx+1];
|
||||||
};
|
};
|
||||||
switch (arg) {
|
switch (arg) {
|
||||||
case "--bunpen-debug" => parsed.debug = true;
|
case "--bunpen-debug" => parsed.debug = 2;
|
||||||
|
case "--bunpen-debug=0" => parsed.debug = 0;
|
||||||
|
case "--bunpen-debug=1" => parsed.debug = 1;
|
||||||
|
case "--bunpen-debug=2" => parsed.debug = 2;
|
||||||
|
case "--bunpen-debug=3" => parsed.debug = 3;
|
||||||
case "--bunpen-drop-shell" => parsed.drop_shell = true;
|
case "--bunpen-drop-shell" => parsed.drop_shell = true;
|
||||||
case "--bunpen-help" => parsed.help = true;
|
case "--bunpen-help" => parsed.help = true;
|
||||||
case "--bunpen-home-path" => idx += 1; append(parsed.home_paths, expect_arg("--bunpen-home-path", next));
|
case "--bunpen-home-path" => idx += 1; append(parsed.home_paths, expect_arg("--bunpen-home-path", next));
|
||||||
|
@@ -9,7 +9,7 @@ use path;
|
|||||||
export type help = !void;
|
export type help = !void;
|
||||||
|
|
||||||
export type cli_request = struct {
|
export type cli_request = struct {
|
||||||
debug: bool,
|
debug: uint,
|
||||||
// args to invoke the binary with.
|
// args to invoke the binary with.
|
||||||
// `exec_args[0]` is, by convention, the name of the executable,
|
// `exec_args[0]` is, by convention, the name of the executable,
|
||||||
// relevant for multi-call binaries like `busybox`.
|
// relevant for multi-call binaries like `busybox`.
|
||||||
|
@@ -35,9 +35,7 @@ export fn main() void = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
log::tree::install(tree::global);
|
log::tree::install(tree::global);
|
||||||
if (req.debug) {
|
log::tree::set_level(tree::global, req.debug);
|
||||||
log::tree::set_level(tree::global, 2); // TODO: make more configurable
|
|
||||||
};
|
|
||||||
|
|
||||||
let what = restrict::resources {
|
let what = restrict::resources {
|
||||||
paths = req.paths,
|
paths = req.paths,
|
||||||
|
@@ -45,7 +45,7 @@ export fn namespace_restrict(what: *resources) void = {
|
|||||||
isolate_paths(what.paths);
|
isolate_paths(what.paths);
|
||||||
// try to change to the old working directory;
|
// try to change to the old working directory;
|
||||||
// this can fail if it's not within the sandbox.
|
// this can fail if it's not within the sandbox.
|
||||||
rtext::swallow_error("[namespace] restore $PWD", os::chdir(pwd));
|
rtext::swallow_error("namespace: restore $PWD", os::chdir(pwd));
|
||||||
|
|
||||||
// TODO: CLONE_NEWPID (might not work without forking to also become reaper)
|
// TODO: CLONE_NEWPID (might not work without forking to also become reaper)
|
||||||
};
|
};
|
||||||
|
@@ -17,9 +17,9 @@ export fn swallow_error(context: str, what: (void | fs::error | os::exec::error
|
|||||||
match (what) {
|
match (what) {
|
||||||
// N.B.: use `println(...)` over `printfln("{}: {}")` so that my treelogger
|
// N.B.: use `println(...)` over `printfln("{}: {}")` so that my treelogger
|
||||||
// can extract the context.
|
// can extract the context.
|
||||||
case let e: fs::error => log::println(context, ": ", fs::strerror(e));
|
case let e: fs::error => log::println(context, ":", fs::strerror(e));
|
||||||
case let e: os::exec::error => log::println(context, ": ", os::exec::strerror(e));
|
case let e: os::exec::error => log::println(context, ":", os::exec::strerror(e));
|
||||||
case let e: rt::errno => log::println(context, ": ", rt::errname(e), ": ", rt::strerror(e));
|
case let e: rt::errno => log::println(context, ":", rt::errname(e), ":", rt::strerror(e));
|
||||||
case => void;
|
case => void;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user