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 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...);
|
||||
defer free(joined);
|
||||
log::printfln("exec: {}", joined);
|
||||
};
|
||||
|
||||
// we receive the args as <argv0> <path> <args>,
|
||||
// and want to invoke the program via `exec(path, argv0, args...)`.
|
||||
// TODO: rework `opts.cmd` handling to make this more consistent.
|
||||
let path = args[1];
|
||||
static delete(args[1]);
|
||||
let path = args[0];
|
||||
args[0] = name;
|
||||
rtext::check_error("exec", rtext::execve(path, args));
|
||||
|
||||
// XXX: os::exec::exec offers no way to preserve argv0, but the following
|
||||
// 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);
|
||||
};
|
||||
|
||||
export fn main() void = {
|
||||
let name = os::args[0];
|
||||
let opts = config::parse_args(os::args[1..]);
|
||||
|
||||
if (opts.help) {
|
||||
@@ -52,8 +50,8 @@ export fn main() void = {
|
||||
restrict::namespace_restrict(&what);
|
||||
restrict::landlock_restrict(&what);
|
||||
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 {
|
||||
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