aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-03-06 15:51:48 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-03-06 15:52:16 -0800
commit68b93c624f51da262dc90d5566c666e59c186840 (patch)
treef6ce97beee067f6ce30550dd9cda9ded8642d1eb
parent36fe1e4a463560672cbf8cbfbe45b26fcf2a2377 (diff)
Move special handling of DISPLAY environment variable from etc/config.fish to fish itself to reduce number of fork calls made at launch
-rw-r--r--env.cpp32
-rw-r--r--env.h2
-rw-r--r--etc/config.fish.in11
-rw-r--r--exec.cpp3
-rw-r--r--fish.cpp6
5 files changed, 29 insertions, 25 deletions
diff --git a/env.cpp b/env.cpp
index db7ddfd9..b5e76ce2 100644
--- a/env.cpp
+++ b/env.cpp
@@ -94,6 +94,9 @@ struct var_entry_t
typedef std::map<wcstring, var_entry_t*> var_table_t;
+bool g_log_forks = true;
+
+
/**
Struct representing one level in the function variable stack
*/
@@ -498,6 +501,15 @@ static void env_set_defaults()
}
+// Some variables should not be arrays. This used to be handled by a startup script, but we'd like to get down to 0 forks for startup, so handle it here.
+static bool variable_can_be_array(const wchar_t *key) {
+ if (! wcscmp(key, L"DISPLAY")) {
+ return false;
+ } else {
+ return true;
+ }
+}
+
void env_init()
{
char **p;
@@ -555,7 +567,6 @@ void env_init()
for( p=environ?environ:__environ; p && *p; p++ )
{
wchar_t *key, *val;
- wchar_t *pos;
key = str2wcs(*p);
@@ -574,16 +585,15 @@ void env_init()
{
*val = L'\0';
val++;
- pos=val;
- //fwprintf( stderr, L"Set $%ls to %ls\n", key, val );
- while( *pos )
- {
- if( *pos == L':' )
- {
- *pos = ARRAY_SEP;
- }
- pos++;
- }
+
+ //fwprintf( stderr, L"Set $%ls to %ls\n", key, val );
+ if (variable_can_be_array(val)) {
+ for (size_t i=0; val[i] != L'\0'; i++) {
+ if( val[i] == L':' ) {
+ val[i] = ARRAY_SEP;
+ }
+ }
+ }
env_set( key, val, ENV_EXPORT | ENV_GLOBAL );
}
diff --git a/env.h b/env.h
index c43efba1..16c274ed 100644
--- a/env.h
+++ b/env.h
@@ -183,5 +183,7 @@ public:
static const wchar_t * const highlighting_keys[];
};
+extern bool g_log_forks;
+
#endif
diff --git a/etc/config.fish.in b/etc/config.fish.in
index e32dc8bc..5e4ed67b 100644
--- a/etc/config.fish.in
+++ b/etc/config.fish.in
@@ -39,17 +39,6 @@ if status --is-login
end
#
-# There are variables that contain colons that are not arrays. This
-# reverts them back to regular strings.
-#
-
-for i in DISPLAY
- if set -q $i
- set -- $i (printf ":%s" $$i|cut -c 2-)
- end
-end
-
-#
# Load additional initialization files
#
diff --git a/exec.cpp b/exec.cpp
index f96fcf3f..a9fff767 100644
--- a/exec.cpp
+++ b/exec.cpp
@@ -1238,7 +1238,8 @@ void exec( parser_t &parser, job_t *j )
const char *actual_cmd = actual_cmd_str.c_str();
const wchar_t *reader_current_filename();
- printf("forking for '%s' in '%ls'\n", actual_cmd, reader_current_filename());
+ if (g_log_forks)
+ printf("forking for '%s' in '%ls'\n", actual_cmd, reader_current_filename());
pid = execute_fork(true /* must drain threads */);
if( pid == 0 )
{
diff --git a/fish.cpp b/fish.cpp
index bf278423..24424e5b 100644
--- a/fish.cpp
+++ b/fish.cpp
@@ -305,7 +305,8 @@ int main( int argc, char **argv )
parser_t &parser = parser_t::principal_parser();
- printf("%d: g_fork_count: %d\n", __LINE__, g_fork_count);
+ if (g_log_forks)
+ printf("%d: g_fork_count: %d\n", __LINE__, g_fork_count);
if( read_init() )
{
@@ -390,7 +391,8 @@ int main( int argc, char **argv )
env_destroy();
- printf("%d: g_fork_count: %d\n", __LINE__, g_fork_count);
+ if (g_log_forks)
+ printf("%d: g_fork_count: %d\n", __LINE__, g_fork_count);
return res?STATUS_UNKNOWN_COMMAND:proc_get_last_status();
}