bunpen: fix mixup between argv0 and the rest of argv
This commit is contained in:
@@ -9,27 +9,25 @@ use os;
|
|||||||
use os::exec;
|
use os::exec;
|
||||||
use types::c;
|
use types::c;
|
||||||
|
|
||||||
fn do_exec(args: []str) (os::exec::error | void) = {
|
fn do_exec(name: str, args: []str) (os::exec::error | void) = {
|
||||||
{
|
{
|
||||||
let joined = strings::join(" ", args...);
|
let joined = strings::join(" ", args...);
|
||||||
defer free(joined);
|
defer free(joined);
|
||||||
log::printfln("exec: {}", joined);
|
log::printfln("exec: {}", joined);
|
||||||
};
|
};
|
||||||
|
|
||||||
// we receive the args as <argv0> <path> <args>,
|
let path = args[0];
|
||||||
// and want to invoke the program via `exec(path, argv0, args...)`.
|
args[0] = name;
|
||||||
// TODO: rework `opts.cmd` handling to make this more consistent.
|
|
||||||
let path = args[1];
|
|
||||||
static delete(args[1]);
|
|
||||||
rtext::check_error("exec", rtext::execve(path, args));
|
rtext::check_error("exec", rtext::execve(path, args));
|
||||||
|
|
||||||
// XXX: os::exec::exec offers no way to preserve argv0, but the following
|
// XXX: os::exec::exec offers no way to preserve argv0, but the following
|
||||||
// works if you don't care about that:
|
// works if you don't care about that:
|
||||||
// let cmd = os::exec::cmd(args[1], args[2..]...)?;
|
// let cmd = os::exec::cmd(args[0], args[1..]...)?;
|
||||||
// os::exec::exec(&cmd);
|
// os::exec::exec(&cmd);
|
||||||
};
|
};
|
||||||
|
|
||||||
export fn main() void = {
|
export fn main() void = {
|
||||||
|
let name = os::args[0];
|
||||||
let opts = config::parse_args(os::args[1..]);
|
let opts = config::parse_args(os::args[1..]);
|
||||||
|
|
||||||
if (opts.help) {
|
if (opts.help) {
|
||||||
@@ -52,8 +50,8 @@ export fn main() void = {
|
|||||||
restrict::namespace_restrict(&what);
|
restrict::namespace_restrict(&what);
|
||||||
restrict::landlock_restrict(&what);
|
restrict::landlock_restrict(&what);
|
||||||
if (opts.drop_shell) {
|
if (opts.drop_shell) {
|
||||||
rtext::check_error("exec /bin/sh", do_exec(["sh", "/bin/sh"]));
|
rtext::check_error("exec /bin/sh", do_exec(name, ["/bin/sh"]));
|
||||||
} else {
|
} else {
|
||||||
rtext::check_error("exec <user command>", do_exec(opts.cmd));
|
rtext::check_error("exec <user command>", do_exec(name, opts.cmd));
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user