diff --git a/common.cpp b/common.cpp index cb20cd2fb..d92a634f2 100644 --- a/common.cpp +++ b/common.cpp @@ -2268,10 +2268,11 @@ static int check_runtime_path(const char * path) } /** Return the path of an appropriate runtime data directory */ -const char* common_get_runtime_path(void) +std::string common_get_runtime_path() { const char *dir = getenv("XDG_RUNTIME_DIR"); const char *uname = getenv("USER"); + std::string path; if (uname == NULL) { @@ -2283,19 +2284,19 @@ const char* common_get_runtime_path(void) { // /tmp/fish.user dir = "/tmp/fish."; - std::string path; path.reserve(strlen(dir) + strlen(uname)); path.append(dir); path.append(uname); if (check_runtime_path(path.c_str()) != 0) { - debug(0, L"Couldn't create secure runtime path: '%s'", path.c_str()); - exit(EXIT_FAILURE); + debug(0, L"Runtime path not available. Try deleting the directory %s and restarting fish.", path.c_str()); + path.clear(); } - return strdup(path.c_str()); } else { - return dir; + path.reserve(strlen(dir)); + path.append(dir); } + return path; } diff --git a/common.h b/common.h index 32635b492..489b8b167 100644 --- a/common.h +++ b/common.h @@ -743,6 +743,6 @@ extern "C" { } /** Return the path of an appropriate runtime data directory */ -const char* common_get_runtime_path(void); +std::string common_get_runtime_path(); #endif diff --git a/env.cpp b/env.cpp index f47884feb..1bb2efeff 100644 --- a/env.cpp +++ b/env.cpp @@ -674,8 +674,8 @@ void env_init(const struct config_paths_t *paths /* or NULL */) const env_var_t user_dir_wstr = env_get_string(L"USER"); - const char * fishd_dir = common_get_runtime_path(); - env_set(L"__fish_runtime_dir", str2wcstring(fishd_dir).c_str(), ENV_GLOBAL); + std::string fishd_dir = common_get_runtime_path(); + env_set(L"__fish_runtime_dir", str2wcstring(fishd_dir).c_str(), ENV_GLOBAL | ENV_EXPORT); wchar_t * user_dir = user_dir_wstr.missing()?NULL:const_cast(user_dir_wstr.c_str()); diff --git a/env_universal.cpp b/env_universal.cpp index 1a9744393..78e3130aa 100644 --- a/env_universal.cpp +++ b/env_universal.cpp @@ -242,23 +242,29 @@ static void reconnect() } -void env_universal_init(const char * p, +void env_universal_init(std::string p, wchar_t *u, void (*sf)(), void (*cb)(fish_message_type_t type, const wchar_t *name, const wchar_t *val)) { - path=p; + path=p.c_str(); user=u; start_fishd=sf; external_callback = cb; - env_universal_server.fd = get_socket(); - env_universal_common_init(&callback); - env_universal_read_all(); - s_env_univeral_inited = true; - if (env_universal_server.fd >= 0) + if (p == "") { + debug(1, L"Could not connect to universal variable server. You will not be able to share variable values between fish sessions."); + } + else { - env_universal_barrier(); + env_universal_server.fd = get_socket(); + env_universal_common_init(&callback); + env_universal_read_all(); + s_env_univeral_inited = true; + if (env_universal_server.fd >= 0) + { + env_universal_barrier(); + } } } diff --git a/env_universal.h b/env_universal.h index 9e6ab85a1..f14db293b 100644 --- a/env_universal.h +++ b/env_universal.h @@ -17,7 +17,7 @@ extern connection_t env_universal_server; /** Initialize the envuni library */ -void env_universal_init(const char * p, +void env_universal_init(std::string p, wchar_t *u, void (*sf)(), void (*cb)(fish_message_type_t type, const wchar_t *name, const wchar_t *val)); diff --git a/fish_pager.cpp b/fish_pager.cpp index 99dca8e28..a508acf6f 100644 --- a/fish_pager.cpp +++ b/fish_pager.cpp @@ -1032,8 +1032,8 @@ static void init(int mangle_descriptors, int out) exit(1); } - - env_universal_init("", 0, 0, 0); + std::string dir = common_get_runtime_path(); + env_universal_init(dir, 0, 0, 0); input_common_init(&interrupt_handler); output_set_writer(&pager_buffered_writer); diff --git a/fishd.cpp b/fishd.cpp index 9614f2255..44df647aa 100644 --- a/fishd.cpp +++ b/fishd.cpp @@ -159,10 +159,15 @@ static int quit=0; */ static std::string get_socket_filename(void) { - const char *dir = common_get_runtime_path(); + std::string dir = common_get_runtime_path(); + + if (dir == "") { + debug(0, L"Cannot access desired socket path."); + exit(EXIT_FAILURE); + } std::string name; - name.reserve(strlen(dir) + strlen(SOCK_FILENAME) + 1); + name.reserve(dir.length() + strlen(SOCK_FILENAME) + 1); name.append(dir); name.push_back('/'); name.append(SOCK_FILENAME);