Changes to make fish use the relocated fishd instead of the installed one, if it exists

This commit is contained in:
ridiculousfish 2012-07-18 10:50:38 -07:00
parent 150789690f
commit e9f43f1097
3 changed files with 47 additions and 23 deletions

30
env.cpp
View file

@ -70,6 +70,12 @@
*/
#define ENV_NULL L"\x1d"
/** Some configuration path environment variables */
#define FISH_DATADIR_VAR L"__fish_datadir"
#define FISH_SYSCONFDIR_VAR L"__fish_sysconfdir"
#define FISH_HELPDIR_VAR L"__fish_help_dir"
#define FISH_BIN_DIR L"__fish_bin_dir"
/**
At init, we read all the environment variables from this array.
*/
@ -237,6 +243,19 @@ static void start_fishd()
}
wcstring cmd = format_string(FISHD_CMD, pw->pw_name);
/* Prefer the fishd in __fish_bin_dir, if exists */
const env_var_t bin_dir = env_get_string(L"__fish_bin_dir");
if (! bin_dir.missing_or_empty())
{
wcstring path = bin_dir + L"/fishd";
if (waccess(path, X_OK) == 0)
{
/* The path command just looks like 'fishd', so insert the bin path to make it absolute */
cmd.insert(0, bin_dir + L"/");
}
}
parser_t &parser = parser_t::principal_parser();
parser.eval( cmd, 0, TOP );
}
@ -510,7 +529,7 @@ static bool variable_can_be_array(const wchar_t *key) {
}
}
void env_init()
void env_init(const struct config_paths_t *paths /* or NULL */)
{
char **p;
struct passwd *pw;
@ -600,6 +619,15 @@ void env_init()
free(key);
}
/* Set the given paths in the environment, if we have any */
if (paths != NULL)
{
env_set(FISH_DATADIR_VAR, paths->data.c_str(), ENV_GLOBAL | ENV_EXPORT);
env_set(FISH_SYSCONFDIR_VAR, paths->sysconf.c_str(), ENV_GLOBAL | ENV_EXPORT);
env_set(FISH_HELPDIR_VAR, paths->doc.c_str(), ENV_GLOBAL | ENV_EXPORT);
env_set(FISH_BIN_DIR, paths->bin.c_str(), ENV_GLOBAL | ENV_EXPORT);
}
/*
Set up the PATH variable
*/

13
env.h
View file

@ -52,11 +52,20 @@ enum{
}
;
/* A struct of configuration directories, determined in main() that fish will optionally pass to env_init.
*/
struct config_paths_t
{
wcstring data; // e.g. /usr/local/share
wcstring sysconf; // e.g. /usr/local/etc
wcstring doc; // e.g. /usr/local/share/doc/fish
wcstring bin; // e.g. /usr/local/bin
};
/**
Initialize environment variable data
*/
void env_init();
void env_init(const struct config_paths_t *paths = NULL);
/**
Destroy environment variable data
@ -164,6 +173,8 @@ void env_export_arr(bool recalc, null_terminated_array_t<char> &result);
*/
wcstring_list_t env_get_names( int flags );
/**
Update the PWD variable
directory

View file

@ -130,15 +130,6 @@ static std::string get_executable_path(const char *argv0)
return std::string(argv0 ? argv0 : "");
}
/* A struct of configuration directories.
*/
struct config_paths_t
{
wcstring data; // e.g. /usr/local/share
wcstring sysconf; // e.g. /usr/local/etc
wcstring doc; // e.g. /usr/local/share/doc/fish
wcstring bin; // e.g. /usr/local/bin
};
static struct config_paths_t determine_config_directory_paths(const char *argv0)
{
@ -216,12 +207,6 @@ static struct config_paths_t determine_config_directory_paths(const char *argv0)
done = true;
}
/* Set the results in the environment */
env_set(L"__fish_datadir", paths.data.c_str(), ENV_GLOBAL | ENV_EXPORT);
env_set(L"__fish_sysconfdir", paths.sysconf.c_str(), ENV_GLOBAL | ENV_EXPORT);
env_set(L"__fish_help_dir", paths.doc.c_str(), ENV_GLOBAL | ENV_EXPORT);
env_set(L"__fish_bin_dir", paths.bin.c_str(), ENV_GLOBAL | ENV_EXPORT);
return paths;
}
@ -451,13 +436,15 @@ int main( int argc, char **argv )
no_exec = 0;
}
const struct config_paths_t paths = determine_config_directory_paths(argv[0]);
proc_init();
event_init();
wutil_init();
//parser_init();
builtin_init();
function_init();
env_init();
env_init(&paths);
reader_init();
history_init();
@ -466,8 +453,6 @@ int main( int argc, char **argv )
if (g_log_forks)
printf("%d: g_fork_count: %d\n", __LINE__, g_fork_count);
/* Determine config paths */
const struct config_paths_t paths = determine_config_directory_paths(argv[0]);
if( read_init(paths) )
{
if( cmd != 0 )