2005-10-17 13:36:57 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2006-02-28 13:17:16 +00:00
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <wchar.h>
|
2006-08-09 22:34:52 +00:00
|
|
|
#include <string.h>
|
2005-09-20 13:26:39 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/un.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2006-01-19 12:22:07 +00:00
|
|
|
|
2005-10-10 16:12:55 +00:00
|
|
|
#if HAVE_NCURSES_H
|
|
|
|
#include <ncurses.h>
|
|
|
|
#else
|
|
|
|
#include <curses.h>
|
|
|
|
#endif
|
2006-01-19 12:22:07 +00:00
|
|
|
|
|
|
|
#if HAVE_TERM_H
|
2005-09-20 13:26:39 +00:00
|
|
|
#include <term.h>
|
2006-01-19 12:22:07 +00:00
|
|
|
#elif HAVE_NCURSES_TERM_H
|
|
|
|
#include <ncurses/term.h>
|
|
|
|
#endif
|
|
|
|
|
2006-08-09 22:26:05 +00:00
|
|
|
#ifdef HAVE_SYS_SELECT_H
|
|
|
|
#include <sys/select.h>
|
|
|
|
#endif
|
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
#include <signal.h>
|
|
|
|
|
2006-02-28 13:17:16 +00:00
|
|
|
#include "fallback.h"
|
2005-09-20 13:26:39 +00:00
|
|
|
#include "util.h"
|
2006-02-28 13:17:16 +00:00
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
#include "common.h"
|
|
|
|
#include "wutil.h"
|
|
|
|
#include "env_universal_common.h"
|
|
|
|
#include "env_universal.h"
|
2014-04-25 23:09:26 +00:00
|
|
|
#include "env.h"
|
2005-09-20 13:26:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2013-02-12 07:16:50 +00:00
|
|
|
Set to true after initialization has been performed
|
2005-09-20 13:26:39 +00:00
|
|
|
*/
|
2013-02-12 07:16:50 +00:00
|
|
|
static bool s_env_univeral_inited = false;
|
2012-11-19 00:30:30 +00:00
|
|
|
static void (*external_callback)(fish_message_type_t type, const wchar_t *name, const wchar_t *val);
|
2005-09-22 20:16:52 +00:00
|
|
|
|
|
|
|
void env_universal_barrier();
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2005-10-03 13:24:46 +00:00
|
|
|
/**
|
|
|
|
Callback function used whenever a new fishd message is recieved
|
|
|
|
*/
|
2012-11-19 00:30:30 +00:00
|
|
|
static void callback(fish_message_type_t type, const wchar_t *name, const wchar_t *val)
|
2012-11-18 10:23:22 +00:00
|
|
|
{
|
2014-06-09 19:07:40 +00:00
|
|
|
if (external_callback)
|
|
|
|
external_callback(type, name, val);
|
2005-09-22 20:16:52 +00:00
|
|
|
}
|
|
|
|
|
2014-06-06 17:34:42 +00:00
|
|
|
void env_universal_init(void (*cb)(fish_message_type_t type, const wchar_t *name, const wchar_t *val))
|
2005-10-03 13:09:37 +00:00
|
|
|
{
|
2014-06-06 17:34:42 +00:00
|
|
|
external_callback = cb;
|
|
|
|
env_universal_common_init(&callback);
|
2013-02-12 07:16:50 +00:00
|
|
|
s_env_univeral_inited = true;
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void env_universal_destroy()
|
|
|
|
{
|
2013-02-12 07:16:50 +00:00
|
|
|
s_env_univeral_inited = false;
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-25 23:09:26 +00:00
|
|
|
env_var_t env_universal_get(const wcstring &name)
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2013-02-12 07:16:50 +00:00
|
|
|
if (!s_env_univeral_inited)
|
2014-04-25 23:09:26 +00:00
|
|
|
return env_var_t::missing_var();
|
2005-09-23 23:15:38 +00:00
|
|
|
|
2012-11-19 00:30:30 +00:00
|
|
|
return env_universal_common_get(name);
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
|
|
|
|
2013-01-19 21:16:21 +00:00
|
|
|
bool env_universal_get_export(const wcstring &name)
|
2005-09-22 20:16:52 +00:00
|
|
|
{
|
2013-02-12 07:16:50 +00:00
|
|
|
if (!s_env_univeral_inited)
|
2013-01-19 21:16:21 +00:00
|
|
|
return false;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2012-11-19 00:30:30 +00:00
|
|
|
return env_universal_common_get_export(name);
|
2005-09-22 20:16:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void env_universal_barrier()
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2012-03-31 22:33:34 +00:00
|
|
|
ASSERT_IS_MAIN_THREAD();
|
2014-05-15 02:49:06 +00:00
|
|
|
UNIVERSAL_LOG("BARRIER");
|
2014-06-06 17:34:42 +00:00
|
|
|
env_universal_common_sync();
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-19 21:16:21 +00:00
|
|
|
void env_universal_set(const wcstring &name, const wcstring &value, bool exportv)
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2013-02-12 07:16:50 +00:00
|
|
|
if (!s_env_univeral_inited)
|
2012-11-19 00:30:30 +00:00
|
|
|
return;
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2012-11-19 00:30:30 +00:00
|
|
|
debug(3, L"env_universal_set( \"%ls\", \"%ls\" )", name.c_str(), value.c_str());
|
2014-06-06 17:34:42 +00:00
|
|
|
|
|
|
|
env_universal_common_set(name.c_str(), value.c_str(), exportv);
|
|
|
|
env_universal_barrier();
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
|
|
|
|
2014-06-13 22:15:11 +00:00
|
|
|
bool env_universal_remove(const wcstring &name)
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2013-02-12 07:16:50 +00:00
|
|
|
if (!s_env_univeral_inited)
|
2014-06-13 22:15:11 +00:00
|
|
|
return false;
|
2012-11-19 00:30:30 +00:00
|
|
|
|
2014-06-13 22:15:11 +00:00
|
|
|
return env_universal_common_remove(name);
|
2005-09-22 20:16:52 +00:00
|
|
|
}
|
|
|
|
|
2013-02-12 07:16:50 +00:00
|
|
|
void env_universal_get_names(wcstring_list_t &lst,
|
|
|
|
bool show_exported,
|
|
|
|
bool show_unexported)
|
2011-12-28 02:41:38 +00:00
|
|
|
{
|
2013-02-12 07:16:50 +00:00
|
|
|
if (!s_env_univeral_inited)
|
2012-11-19 00:30:30 +00:00
|
|
|
return;
|
2011-12-28 02:41:38 +00:00
|
|
|
|
2012-11-19 00:30:30 +00:00
|
|
|
env_universal_common_get_names(lst,
|
|
|
|
show_exported,
|
|
|
|
show_unexported);
|
2011-12-28 02:41:38 +00:00
|
|
|
}
|
2014-04-26 00:44:49 +00:00
|
|
|
|