diff --git a/src/builtin_status.cpp b/src/builtin_status.cpp index 4862a8897..a7544ab1a 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(program_name); + streams.out.append(str2wcstring(program_name).c_str()); streams.out.push_back(L'\n'); } break; diff --git a/src/builtin_test.cpp b/src/builtin_test.cpp index 07ae926b9..0752d73b2 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"%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()); } result.reset(NULL); diff --git a/src/common.cpp b/src/common.cpp index 82c85181f..e1b7e4282 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 wchar_t *program_name; +const char *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 && !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) { pid_t current_pid = getpid(); 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 { - 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()); } } diff --git a/src/common.h b/src/common.h index 83d6cd0ba..862256c9c 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 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. 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 L"(ignore)" +#define TESTS_PROGRAM_NAME "(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 7fd8bf1e9..ac05ff382 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, "/%ls_shmem_%d", program_name ? program_name : L"fish", + snprintf(path, sizeof path, "/%s_shmem_%d", L"fish", getuid()); bool errored = false; @@ -1181,8 +1181,7 @@ 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.%ls.uvars", getuid(), - program_name ? program_name : L"fish"); + snprintf(local_name, sizeof local_name, "user.uid.%d.fish.uvars", getuid()); name.assign(local_name); uint32_t status = diff --git a/src/fish.cpp b/src/fish.cpp index 49110ac1e..70c0661c5 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 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; paths.data = wcstring{L"" CMAKE_SOURCE_DIR} + L"/share"; @@ -334,7 +334,13 @@ int main(int argc, char **argv) { int res = 1; 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(); setup_fork_guards(); signal_unblock_all(); @@ -344,11 +350,6 @@ 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 59e560bd5..f16cc0a45 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 = L"fish_indent"; + program_name = argv[0]; 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 aec1626be..8d3eba92e 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 = L"fish_key_reader"; + program_name = argv[0]; bool continuous_mode = false; if (!parse_flags(argc, argv, &continuous_mode)) return 1; diff --git a/src/parser.cpp b/src/parser.cpp index b16c86e47..ea53bd6b4 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 = L"fish: "; + prefix = format_string(L"%s: ", program_name); } const wcstring description = diff --git a/src/proc.cpp b/src/proc.cpp index 5e0523187..7a1bcf6b7 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -659,7 +659,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"%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(), truncate_command(j->command()).c_str(), sig2wcs(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 = (job_count == 1) ? wcstring() : format_string(L"from job %d, ", j->job_id); 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(), 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 70b6c4a3d..c0a7e89fc 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, program_name); + env_set_one(L"_", ENV_GLOBAL, str2wcstring(program_name).c_str()); #ifdef HAVE__PROC_SELF_STAT proc_update_jiffies();