Further fixes to universal variable server socket management

- Change fishd_path to std::string
- Warn, rather than exiting with an error, if the universal variable
  server path is not available, and provide more useful advice.
- Export the new __fishd_runtime_dir variable.
This commit is contained in:
David Adam 2014-08-04 13:26:14 +08:00
parent 209d8b7f2f
commit 2aac8e5dde
7 changed files with 34 additions and 22 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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<wchar_t*>(user_dir_wstr.c_str());

View File

@ -242,16 +242,21 @@ 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;
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_server.fd = get_socket();
env_universal_common_init(&callback);
env_universal_read_all();
@ -261,6 +266,7 @@ void env_universal_init(const char * p,
env_universal_barrier();
}
}
}
void env_universal_destroy()
{

View File

@ -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));

View File

@ -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);

View File

@ -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);