From 4aa2675eb6415e96945634ce27da4e5ee0c40c83 Mon Sep 17 00:00:00 2001 From: Glauber Costa <glommer@cloudius-systems.com> Date: Wed, 9 Apr 2014 12:11:21 +0400 Subject: [PATCH] libc: Add program_invocation_name variables Redis relies on the variables being present and correctly set. Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com> Signed-off-by: Glauber Costa <glommer@cloudius-systems.com> Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com> --- core/run.cc | 7 +++++++ libc/libc.cc | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/core/run.cc b/core/run.cc index 8e36f9dfc..b2e83192b 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 397be722e..faf66df8f 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; -- GitLab