diff options
-rw-r--r-- | pseudo.h | 3 | ||||
-rw-r--r-- | pseudo_client.c | 42 | ||||
-rw-r--r-- | pseudo_util.c | 21 |
3 files changed, 49 insertions, 17 deletions
@@ -61,6 +61,9 @@ extern ssize_t pseudo_path_max(void); extern int pseudo_etc_file(const char *filename, char *realname, int flags, char **search, int dircount); #define PSEUDO_ETC_FILE(name, realname, flags) pseudo_etc_file((name), (realname), (flags), (char *[]) { pseudo_chroot, pseudo_passwd }, 2) +/* refresh environment variables from internals */ +extern void pseudo_reinit_environment(void); + extern char *pseudo_version; #ifndef PSEUDO_BINDIR diff --git a/pseudo_client.c b/pseudo_client.c index b63c7e7..e30d3e7 100644 --- a/pseudo_client.c +++ b/pseudo_client.c @@ -313,6 +313,8 @@ pseudo_client_close(int fd) { void pseudo_client_reset() { + char *env_disabled = NULL; + pseudo_antimagic(); pseudo_new_pid(); if (connect_fd != -1) { @@ -320,21 +322,39 @@ pseudo_client_reset() { connect_fd = -1; } - /* in child processes, PSEUDO_DISABLED may have come - * into existence, in which case we'd disable pseudo, + /* in child processes, PSEUDO_DISABLED may have become set to + * some truthy value, in which case we'd disable pseudo, * or it may have gone away, in which case we'd enable * pseudo. */ - if (getenv("PSEUDO_DISABLED")) { - if (!pseudo_disabled) { - pseudo_antimagic(); - pseudo_disabled = 1; + env_disabled = getenv("PSEUDO_DISABLED"); + if (env_disabled) { + int actually_disabled = 1; + switch (*env_disabled) { + case 'f': + case 'F': + case 'n': + case 'N': + actually_disabled = 0; + break; + case '0': + actually_disabled = atoi(env_disabled); + break; } - } else { - if (pseudo_disabled) { - pseudo_magic(); - pseudo_disabled = 0; + if (actually_disabled) { + if (!pseudo_disabled) { + pseudo_antimagic(); + pseudo_disabled = 1; + } + env_disabled = "1"; + } else { + if (pseudo_disabled) { + pseudo_magic(); + pseudo_disabled = 0; + } + env_disabled = "0"; } + pseudo_set_value("PSEUDO_DISABLED", env_disabled); } if (!pseudo_inited) { @@ -374,6 +394,8 @@ pseudo_client_reset() { pseudo_inited = 1; } pseudo_client_getcwd(); + /* make sure environment variables are back in sync */ + pseudo_reinit_environment(); pseudo_magic(); } diff --git a/pseudo_util.c b/pseudo_util.c index 774e387..97c9911 100644 --- a/pseudo_util.c +++ b/pseudo_util.c @@ -64,6 +64,7 @@ static struct pseudo_variables pseudo_env[] = { { "PSEUDO_ENOSYS_ABORT", 19, NULL }, { "PSEUDO_NOSYMLINKEXP", 19, NULL }, { "PSEUDO_RELOADED", 15, NULL }, + { "PSEUDO_DISABLED", 15, NULL }, { NULL, 0, NULL } /* Magic terminator */ }; @@ -75,7 +76,7 @@ static struct pseudo_variables pseudo_env[] = { * program starts playing with things, so we need to do our * best to handle that case. */ -int _in_init = -1; /* Not yet run */ +static int _pseudo_in_init = -1; /* Not yet run */ static void _libpseudo_init(void) __attribute__ ((constructor)); @@ -91,17 +92,23 @@ dump_env(char **envp) { pseudo_debug(0,"dump_envp: {%d}%s=%s\n", (int) i, pseudo_env[i].key, pseudo_env[i].value); } - pseudo_debug(0, "dump_envp: _in_init %d\n", _in_init); + pseudo_debug(0, "dump_envp: _in_init %d\n", _pseudo_in_init); } #endif +void +pseudo_reinit_environment(void) { + _pseudo_in_init = 0; + _libpseudo_init(); +} + /* Caller must free memory! */ char * pseudo_get_value(const char *key) { size_t i = 0; char * value; - if (_in_init == -1) + if (_pseudo_in_init == -1) _libpseudo_init(); for (i = 0; pseudo_env[i].key && memcmp(pseudo_env[i].key, key, pseudo_env[i].key_len + 1); i++) @@ -130,7 +137,7 @@ pseudo_set_value(const char *key, const char *value) { int rc = 0; size_t i = 0; - if (_in_init == -1) + if (_pseudo_in_init == -1) _libpseudo_init(); for (i = 0; pseudo_env[i].key && memcmp(pseudo_env[i].key, key, pseudo_env[i].key_len + 1); i++) @@ -149,7 +156,7 @@ pseudo_set_value(const char *key, const char *value) { } else pseudo_env[i].value = NULL; } else { - if (!_in_init) pseudo_diag("Unknown variable %s.\n", key); + if (!_pseudo_in_init) pseudo_diag("Unknown variable %s.\n", key); rc = -EINVAL; } @@ -160,14 +167,14 @@ static void _libpseudo_init(void) { size_t i = 0; - _in_init = 1; + _pseudo_in_init = 1; for (i = 0; pseudo_env[i].key; i++) { if (getenv(pseudo_env[i].key)) pseudo_set_value(pseudo_env[i].key, getenv(pseudo_env[i].key)); } - _in_init = 0; + _pseudo_in_init = 0; } /* 5 = ridiculous levels of duplication |