diff --git a/core/run.cc b/core/run.cc index 8e36f9dfc71a63683ddbb30c525d5bd63561470b..b2e83192bc9a6ba4602c735a6232017e35a4a66e 100644 --- a/core/run.cc +++ b/core/run.cc @@ -7,6 +7,8 @@ #include <osv/run.hh> #include <osv/debug.hh> +#include <errno.h> +#include <libgen.h> extern int optind; @@ -27,6 +29,11 @@ std::shared_ptr<elf::object> run(std::string path, if (!main) { return nullptr; } + + char *c_path = (char *)(path.c_str()); + // path is guaranteed to keep existing this function + program_invocation_name = c_path; + program_invocation_short_name = basename(c_path); // make sure to have a fresh optind across calls // FIXME: fails if run() is executed in parallel int old_optind = optind; diff --git a/libc/libc.cc b/libc/libc.cc index 397be722e9f51210982c1327d91381a05d990224..faf66df8f8daaa945543462c4c8e7cccbe847f29 100644 --- a/libc/libc.cc +++ b/libc/libc.cc @@ -25,6 +25,11 @@ #include <osv/clock.hh> #include <osv/mempool.hh> +// FIXME: If we ever support multiple different executables we will have to maybe put those +// on a shared library +char *program_invocation_name; +char *program_invocation_short_name; + int libc_error(int err) { errno = err;