Show how fish was executed, using argv[0] for program_name

... rather than hard code it to "fish". This affects
what is found in $_ and improves the errors:

For example, if fish was ran with ./fish, instead of
something like:

  fish: Expected 3 surprises, only got 2 surprises

we'll see:

 ./fish: Expected 3 surprises, only got 2 surprises

like most other shell utilities. It's just a tiny bit
of detail that can avoid confusion.
This commit is contained in:
Aaron Gyes 2018-11-25 16:06:39 -08:00
parent 85cecd30fb
commit 1cb8b2a87b
11 changed files with 24 additions and 24 deletions

View file

@ -429,7 +429,7 @@ int builtin_status(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
streams.out.append(var->as_string()); streams.out.append(var->as_string());
streams.out.push_back(L'\n'); streams.out.push_back(L'\n');
} else { } else {
streams.out.append(program_name); streams.out.append(str2wcstring(program_name).c_str());
streams.out.push_back(L'\n'); streams.out.push_back(L'\n');
} }
break; break;

View file

@ -554,7 +554,7 @@ unique_ptr<expression> test_parser::parse_args(const wcstring_list_t &args, wcst
assert(result->range.end <= args.size()); assert(result->range.end <= args.size());
if (result->range.end < args.size()) { if (result->range.end < args.size()) {
if (err.empty()) { if (err.empty()) {
append_format(err, L"%ls: unexpected argument at index %lu: '%ls'\n", program_name, append_format(err, L"%s: unexpected argument at index %lu: '%ls'\n", program_name,
(unsigned long)result->range.end, args.at(result->range.end).c_str()); (unsigned long)result->range.end, args.at(result->range.end).c_str());
} }
result.reset(NULL); result.reset(NULL);

View file

@ -62,7 +62,7 @@ const wchar_t *ellipsis_str = nullptr;
wchar_t omitted_newline_char; wchar_t omitted_newline_char;
wchar_t obfuscation_read_char; wchar_t obfuscation_read_char;
bool g_profiling_active = false; bool g_profiling_active = false;
const wchar_t *program_name; const char *program_name;
int debug_level = 1; // default maximum debug output level (errors and warnings) int debug_level = 1; // default maximum debug output level (errors and warnings)
int debug_stack_frames = 0; // default number of stack frames to show on debug() calls int debug_stack_frames = 0; // default number of stack frames to show on debug() calls
@ -603,16 +603,16 @@ ssize_t read_loop(int fd, void *buff, size_t count) {
/// like `debug()`. It is only intended to supress diagnostic noise from testing things like the /// like `debug()`. It is only intended to supress diagnostic noise from testing things like the
/// fish parser where we expect a lot of diagnostic messages due to testing error conditions. /// fish parser where we expect a lot of diagnostic messages due to testing error conditions.
bool should_suppress_stderr_for_tests() { bool should_suppress_stderr_for_tests() {
return program_name && !wcscmp(program_name, TESTS_PROGRAM_NAME); return program_name && !strcmp(program_name, TESTS_PROGRAM_NAME);
} }
static void debug_shared(const wchar_t level, const wcstring &msg) { static void debug_shared(const wchar_t level, const wcstring &msg) {
pid_t current_pid = getpid(); pid_t current_pid = getpid();
if (current_pid == initial_pid) { if (current_pid == initial_pid) {
fwprintf(stderr, L"<%lc> %ls: %ls\n", (unsigned long)level, program_name, msg.c_str()); fwprintf(stderr, L"<%lc> %s: %ls\n", (unsigned long)level, program_name, msg.c_str());
} else { } else {
fwprintf(stderr, L"<%lc> %ls: %d: %ls\n", (unsigned long)level, program_name, current_pid, fwprintf(stderr, L"<%lc> %s: %d: %ls\n", (unsigned long)level, program_name, current_pid,
msg.c_str()); msg.c_str());
} }
} }

View file

@ -221,7 +221,7 @@ extern int debug_stack_frames;
extern bool g_profiling_active; extern bool g_profiling_active;
/// Name of the current program. Should be set at startup. Used by the debug function. /// Name of the current program. Should be set at startup. Used by the debug function.
extern const wchar_t *program_name; extern const char *program_name;
/// Set to false if it's been determined we can't trust the last modified timestamp on the tty. /// Set to false if it's been determined we can't trust the last modified timestamp on the tty.
extern const bool has_working_tty_timestamps; extern const bool has_working_tty_timestamps;
@ -532,7 +532,7 @@ string_fuzzy_match_t string_fuzzy_match_string(const wcstring &string,
fuzzy_match_type_t limit_type = fuzzy_match_none); fuzzy_match_type_t limit_type = fuzzy_match_none);
// Check if we are running in the test mode, where we should suppress error output // Check if we are running in the test mode, where we should suppress error output
#define TESTS_PROGRAM_NAME L"(ignore)" #define TESTS_PROGRAM_NAME "(ignore)"
bool should_suppress_stderr_for_tests(); bool should_suppress_stderr_for_tests();
void assert_is_main_thread(const char *who); void assert_is_main_thread(const char *who);

View file

@ -1047,7 +1047,7 @@ class universal_notifier_shmem_poller_t : public universal_notifier_t {
// Use a path based on our uid to avoid collisions. // Use a path based on our uid to avoid collisions.
char path[NAME_MAX]; char path[NAME_MAX];
snprintf(path, sizeof path, "/%ls_shmem_%d", program_name ? program_name : L"fish", snprintf(path, sizeof path, "/%s_shmem_%d", L"fish",
getuid()); getuid());
bool errored = false; bool errored = false;
@ -1181,8 +1181,7 @@ class universal_notifier_notifyd_t : public universal_notifier_t {
void setup_notifyd() { void setup_notifyd() {
// Per notify(3), the user.uid.%d style is only accessible to processes with that uid. // Per notify(3), the user.uid.%d style is only accessible to processes with that uid.
char local_name[256]; char local_name[256];
snprintf(local_name, sizeof local_name, "user.uid.%d.%ls.uvars", getuid(), snprintf(local_name, sizeof local_name, "user.uid.%d.fish.uvars", getuid());
program_name ? program_name : L"fish");
name.assign(local_name); name.assign(local_name);
uint32_t status = uint32_t status =

View file

@ -100,7 +100,7 @@ static struct config_paths_t determine_config_directory_paths(const char *argv0)
#ifdef CMAKE_BINARY_DIR #ifdef CMAKE_BINARY_DIR
// Detect if we're running right out of the CMAKE build directory // Detect if we're running right out of the CMAKE build directory
if (string_prefixes_string(CMAKE_BINARY_DIR, exec_path.c_str())) { if (string_prefixes_string(CMAKE_BINARY_DIR, exec_path.c_str())) {
debug(2, "Running out of build directory, using paths relative to CMAKE_SOURCE_DIR:\n %s", CMAKE_SOURCE_DIR); debug(2, "Running out of5 build directory, using paths relative to CMAKE_SOURCE_DIR:\n %s", CMAKE_SOURCE_DIR);
done = true; done = true;
paths.data = wcstring{L"" CMAKE_SOURCE_DIR} + L"/share"; paths.data = wcstring{L"" CMAKE_SOURCE_DIR} + L"/share";
@ -334,7 +334,13 @@ int main(int argc, char **argv) {
int res = 1; int res = 1;
int my_optind = 0; int my_optind = 0;
program_name = L"fish"; const char *dummy_argv[2] = {"fish", NULL};
if (!argv[0]) {
argv = (char **)dummy_argv; //!OCLINT(parameter reassignment)
argc = 1; //!OCLINT(parameter reassignment)
}
program_name = argv[0];
set_main_thread(); set_main_thread();
setup_fork_guards(); setup_fork_guards();
signal_unblock_all(); signal_unblock_all();
@ -344,11 +350,6 @@ int main(int argc, char **argv) {
// struct stat tmp; // struct stat tmp;
// stat("----------FISH_HIT_MAIN----------", &tmp); // stat("----------FISH_HIT_MAIN----------", &tmp);
const char *dummy_argv[2] = {"fish", NULL};
if (!argv[0]) {
argv = (char **)dummy_argv; //!OCLINT(parameter reassignment)
argc = 1; //!OCLINT(parameter reassignment)
}
fish_cmd_opts_t opts; fish_cmd_opts_t opts;
my_optind = fish_parse_opt(argc, argv, &opts); my_optind = fish_parse_opt(argc, argv, &opts);

View file

@ -381,7 +381,7 @@ static std::string html_colorize(const wcstring &text,
static std::string no_colorize(const wcstring &text) { return wcs2string(text); } static std::string no_colorize(const wcstring &text) { return wcs2string(text); }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
program_name = L"fish_indent"; program_name = argv[0];
set_main_thread(); set_main_thread();
setup_fork_guards(); setup_fork_guards();
// Using the user's default locale could be a problem if it doesn't use UTF-8 encoding. That's // Using the user's default locale could be a problem if it doesn't use UTF-8 encoding. That's

View file

@ -383,7 +383,7 @@ static bool parse_flags(int argc, char **argv, bool *continuous_mode) {
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
program_name = L"fish_key_reader"; program_name = argv[0];
bool continuous_mode = false; bool continuous_mode = false;
if (!parse_flags(argc, argv, &continuous_mode)) return 1; if (!parse_flags(argc, argv, &continuous_mode)) return 1;

View file

@ -775,7 +775,7 @@ void parser_t::get_backtrace(const wcstring &src, const parse_error_list_t &erro
prefix = format_string(_(L"%ls: "), user_presentable_path(filename).c_str()); prefix = format_string(_(L"%ls: "), user_presentable_path(filename).c_str());
} }
} else { } else {
prefix = L"fish: "; prefix = format_string(L"%s: ", program_name);
} }
const wcstring description = const wcstring description =

View file

@ -659,7 +659,7 @@ static int process_clean_after_marking(bool allow_interactive) {
// we don't need to. // we don't need to.
const wcstring job_number_desc = const wcstring job_number_desc =
(job_count == 1) ? wcstring() : format_string(_(L"Job %d, "), j->job_id); (job_count == 1) ? wcstring() : format_string(_(L"Job %d, "), j->job_id);
fwprintf(stdout, _(L"%ls: %ls\'%ls\' terminated by signal %ls (%ls)"), fwprintf(stdout, _(L"%s: %ls\'%ls\' terminated by signal %ls (%ls)"),
program_name, job_number_desc.c_str(), program_name, job_number_desc.c_str(),
truncate_command(j->command()).c_str(), sig2wcs(WTERMSIG(p->status)), truncate_command(j->command()).c_str(), sig2wcs(WTERMSIG(p->status)),
signal_get_desc(WTERMSIG(p->status))); signal_get_desc(WTERMSIG(p->status)));
@ -667,7 +667,7 @@ static int process_clean_after_marking(bool allow_interactive) {
const wcstring job_number_desc = const wcstring job_number_desc =
(job_count == 1) ? wcstring() : format_string(L"from job %d, ", j->job_id); (job_count == 1) ? wcstring() : format_string(L"from job %d, ", j->job_id);
const wchar_t *fmt = const wchar_t *fmt =
_(L"%ls: Process %d, \'%ls\' %ls\'%ls\' terminated by signal %ls (%ls)"); _(L"%s: Process %d, \'%ls\' %ls\'%ls\' terminated by signal %ls (%ls)");
fwprintf(stdout, fmt, program_name, p->pid, p->argv0(), job_number_desc.c_str(), fwprintf(stdout, fmt, program_name, p->pid, p->argv0(), job_number_desc.c_str(),
truncate_command(j->command()).c_str(), sig2wcs(WTERMSIG(p->status)), truncate_command(j->command()).c_str(), sig2wcs(WTERMSIG(p->status)),
signal_get_desc(WTERMSIG(p->status))); signal_get_desc(WTERMSIG(p->status)));

View file

@ -2037,7 +2037,7 @@ void reader_run_command(parser_t &parser, const wcstring &cmd) {
term_steal(); term_steal();
// For compatibility with fish 2.0's $_, now replaced with `status current-command` // For compatibility with fish 2.0's $_, now replaced with `status current-command`
env_set_one(L"_", ENV_GLOBAL, program_name); env_set_one(L"_", ENV_GLOBAL, str2wcstring(program_name).c_str());
#ifdef HAVE__PROC_SELF_STAT #ifdef HAVE__PROC_SELF_STAT
proc_update_jiffies(); proc_update_jiffies();