From fe67cc4f6e6174db91b7893c3726dd5e03613967 Mon Sep 17 00:00:00 2001 From: Aaron Gyes Date: Wed, 28 Nov 2018 06:08:24 -0800 Subject: [PATCH] Revert "Show how fish was executed, using argv[0] for program_name" This reverts commit 1cb8b2a87b05298b70ab285607f5863942b14f58. argv[0] has the full path in it for a user when he executes it out of $PATH. This is really annoying in the title which uses $_. --- src/builtin_status.cpp | 2 +- src/builtin_test.cpp | 2 +- src/common.cpp | 8 ++++---- src/common.h | 4 ++-- src/env_universal_common.cpp | 5 +++-- src/fish.cpp | 15 +++++++-------- src/fish_indent.cpp | 2 +- src/fish_key_reader.cpp | 2 +- src/parser.cpp | 2 +- src/proc.cpp | 4 ++-- src/reader.cpp | 2 +- 11 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/builtin_status.cpp b/src/builtin_status.cpp index a7544ab1a..4862a8897 100644 --- a/src/builtin_status.cpp +++ b/src/builtin_status.cpp @@ -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.push_back(L'\n'); } else { - streams.out.append(str2wcstring(program_name).c_str()); + streams.out.append(program_name); streams.out.push_back(L'\n'); } break; diff --git a/src/builtin_test.cpp b/src/builtin_test.cpp index 0752d73b2..07ae926b9 100644 --- a/src/builtin_test.cpp +++ b/src/builtin_test.cpp @@ -554,7 +554,7 @@ unique_ptr test_parser::parse_args(const wcstring_list_t &args, wcst assert(result->range.end <= args.size()); if (result->range.end < args.size()) { if (err.empty()) { - append_format(err, L"%s: unexpected argument at index %lu: '%ls'\n", program_name, + append_format(err, L"%ls: unexpected argument at index %lu: '%ls'\n", program_name, (unsigned long)result->range.end, args.at(result->range.end).c_str()); } result.reset(NULL); diff --git a/src/common.cpp b/src/common.cpp index e1b7e4282..82c85181f 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -62,7 +62,7 @@ const wchar_t *ellipsis_str = nullptr; wchar_t omitted_newline_char; wchar_t obfuscation_read_char; bool g_profiling_active = false; -const char *program_name; +const wchar_t *program_name; 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 @@ -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 /// fish parser where we expect a lot of diagnostic messages due to testing error conditions. bool should_suppress_stderr_for_tests() { - return program_name && !strcmp(program_name, TESTS_PROGRAM_NAME); + return program_name && !wcscmp(program_name, TESTS_PROGRAM_NAME); } static void debug_shared(const wchar_t level, const wcstring &msg) { pid_t current_pid = getpid(); if (current_pid == initial_pid) { - fwprintf(stderr, L"<%lc> %s: %ls\n", (unsigned long)level, program_name, msg.c_str()); + fwprintf(stderr, L"<%lc> %ls: %ls\n", (unsigned long)level, program_name, msg.c_str()); } else { - fwprintf(stderr, L"<%lc> %s: %d: %ls\n", (unsigned long)level, program_name, current_pid, + fwprintf(stderr, L"<%lc> %ls: %d: %ls\n", (unsigned long)level, program_name, current_pid, msg.c_str()); } } diff --git a/src/common.h b/src/common.h index 862256c9c..83d6cd0ba 100644 --- a/src/common.h +++ b/src/common.h @@ -221,7 +221,7 @@ extern int debug_stack_frames; extern bool g_profiling_active; /// Name of the current program. Should be set at startup. Used by the debug function. -extern const char *program_name; +extern const wchar_t *program_name; /// 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; @@ -532,7 +532,7 @@ string_fuzzy_match_t string_fuzzy_match_string(const wcstring &string, fuzzy_match_type_t limit_type = fuzzy_match_none); // Check if we are running in the test mode, where we should suppress error output -#define TESTS_PROGRAM_NAME "(ignore)" +#define TESTS_PROGRAM_NAME L"(ignore)" bool should_suppress_stderr_for_tests(); void assert_is_main_thread(const char *who); diff --git a/src/env_universal_common.cpp b/src/env_universal_common.cpp index ac05ff382..7fd8bf1e9 100644 --- a/src/env_universal_common.cpp +++ b/src/env_universal_common.cpp @@ -1047,7 +1047,7 @@ class universal_notifier_shmem_poller_t : public universal_notifier_t { // Use a path based on our uid to avoid collisions. char path[NAME_MAX]; - snprintf(path, sizeof path, "/%s_shmem_%d", L"fish", + snprintf(path, sizeof path, "/%ls_shmem_%d", program_name ? program_name : L"fish", getuid()); bool errored = false; @@ -1181,7 +1181,8 @@ class universal_notifier_notifyd_t : public universal_notifier_t { void setup_notifyd() { // Per notify(3), the user.uid.%d style is only accessible to processes with that uid. char local_name[256]; - snprintf(local_name, sizeof local_name, "user.uid.%d.fish.uvars", getuid()); + snprintf(local_name, sizeof local_name, "user.uid.%d.%ls.uvars", getuid(), + program_name ? program_name : L"fish"); name.assign(local_name); uint32_t status = diff --git a/src/fish.cpp b/src/fish.cpp index 70c0661c5..49110ac1e 100644 --- a/src/fish.cpp +++ b/src/fish.cpp @@ -100,7 +100,7 @@ static struct config_paths_t determine_config_directory_paths(const char *argv0) #ifdef CMAKE_BINARY_DIR // Detect if we're running right out of the CMAKE build directory if (string_prefixes_string(CMAKE_BINARY_DIR, exec_path.c_str())) { - debug(2, "Running out of5 build directory, using paths relative to CMAKE_SOURCE_DIR:\n %s", CMAKE_SOURCE_DIR); + debug(2, "Running out of build directory, using paths relative to CMAKE_SOURCE_DIR:\n %s", CMAKE_SOURCE_DIR); done = true; paths.data = wcstring{L"" CMAKE_SOURCE_DIR} + L"/share"; @@ -334,13 +334,7 @@ int main(int argc, char **argv) { int res = 1; int my_optind = 0; - 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]; + program_name = L"fish"; set_main_thread(); setup_fork_guards(); signal_unblock_all(); @@ -350,6 +344,11 @@ int main(int argc, char **argv) { // struct stat 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; my_optind = fish_parse_opt(argc, argv, &opts); diff --git a/src/fish_indent.cpp b/src/fish_indent.cpp index f16cc0a45..59e560bd5 100644 --- a/src/fish_indent.cpp +++ b/src/fish_indent.cpp @@ -381,7 +381,7 @@ static std::string html_colorize(const wcstring &text, static std::string no_colorize(const wcstring &text) { return wcs2string(text); } int main(int argc, char *argv[]) { - program_name = argv[0]; + program_name = L"fish_indent"; set_main_thread(); setup_fork_guards(); // Using the user's default locale could be a problem if it doesn't use UTF-8 encoding. That's diff --git a/src/fish_key_reader.cpp b/src/fish_key_reader.cpp index 8d3eba92e..aec1626be 100644 --- a/src/fish_key_reader.cpp +++ b/src/fish_key_reader.cpp @@ -383,7 +383,7 @@ static bool parse_flags(int argc, char **argv, bool *continuous_mode) { } int main(int argc, char **argv) { - program_name = argv[0]; + program_name = L"fish_key_reader"; bool continuous_mode = false; if (!parse_flags(argc, argv, &continuous_mode)) return 1; diff --git a/src/parser.cpp b/src/parser.cpp index ea53bd6b4..b16c86e47 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -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()); } } else { - prefix = format_string(L"%s: ", program_name); + prefix = L"fish: "; } const wcstring description = diff --git a/src/proc.cpp b/src/proc.cpp index b49644093..39dcded0f 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -655,7 +655,7 @@ static int process_clean_after_marking(bool allow_interactive) { // we don't need to. const wcstring job_number_desc = (job_count == 1) ? wcstring() : format_string(_(L"Job %d, "), j->job_id); - fwprintf(stdout, _(L"%s: %ls\'%ls\' terminated by signal %ls (%ls)"), + fwprintf(stdout, _(L"%ls: %ls\'%ls\' terminated by signal %ls (%ls)"), program_name, job_number_desc.c_str(), truncate_command(j->command()).c_str(), sig2wcs(WTERMSIG(p->status)), signal_get_desc(WTERMSIG(p->status))); @@ -663,7 +663,7 @@ static int process_clean_after_marking(bool allow_interactive) { const wcstring job_number_desc = (job_count == 1) ? wcstring() : format_string(L"from job %d, ", j->job_id); const wchar_t *fmt = - _(L"%s: Process %d, \'%ls\' %ls\'%ls\' terminated by signal %ls (%ls)"); + _(L"%ls: Process %d, \'%ls\' %ls\'%ls\' terminated by signal %ls (%ls)"); fwprintf(stdout, fmt, program_name, p->pid, p->argv0(), job_number_desc.c_str(), truncate_command(j->command()).c_str(), sig2wcs(WTERMSIG(p->status)), signal_get_desc(WTERMSIG(p->status))); diff --git a/src/reader.cpp b/src/reader.cpp index c0a7e89fc..70b6c4a3d 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -2037,7 +2037,7 @@ void reader_run_command(parser_t &parser, const wcstring &cmd) { term_steal(); // For compatibility with fish 2.0's $_, now replaced with `status current-command` - env_set_one(L"_", ENV_GLOBAL, str2wcstring(program_name).c_str()); + env_set_one(L"_", ENV_GLOBAL, program_name); #ifdef HAVE__PROC_SELF_STAT proc_update_jiffies();