aboutsummaryrefslogtreecommitdiffstats
path: root/pseudo_util.c
diff options
context:
space:
mode:
authorPeter Seebach <peter.seebach@windriver.com>2010-12-07 20:43:45 -0600
committerPeter Seebach <peter.seebach@windriver.com>2010-12-07 20:47:19 -0600
commit98f16482f1e5c4b9c9d3b0803d41565a350af53d (patch)
tree4af00226b5b0b3b79ff26b51aedb2c5af15f58fe /pseudo_util.c
parent7b2dd4c7a6e20a8fe78cb892a8406d6d119c415b (diff)
downloadpseudo-98f16482f1e5c4b9c9d3b0803d41565a350af53d.tar.gz
pseudo-98f16482f1e5c4b9c9d3b0803d41565a350af53d.tar.bz2
pseudo-98f16482f1e5c4b9c9d3b0803d41565a350af53d.zip
This is a merge of several commits from a tree which turned out to
be out of sync in a very inconvenient way. Changes include: * Some whitespace fixes, also move the pseudo_variables definition into pseudo_util.c since it's not used anywhere else. * Further improvements in the fork() support: We now recognize both positive and negative forms of PSEUDO_DISABLED, so we can distinguish between "it was removed from the environment by env -i" (restore the old value) and "it was intentionally turned off" (the new value wins). * clone(2) support. This is a little primitive, and programs might still fail horribly due to clone's semantics, but at least it's there and passes easy test cases. Plus a big patch from Mark Hatle: Cleanup fork/clone and PSEUDO_DISABLED guts/fork.c: * cleanup function and make it more robust * be sure to call pseudo_setupenv prior to pseudo_client_reset to match exec behavior pseudo_wrappers.c: * fix mismatched type in execl_to_v call via typecast * Simplify fork call via single call to wrap_fork() * be sure to save pseudo_disabled * be sure to call pseudo_setupenv prior to pseudo_client_reset to match exec behavior tests: * Add a test of whether pseudo can be disabled/enabled on a fork. Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
Diffstat (limited to 'pseudo_util.c')
-rw-r--r--pseudo_util.c58
1 files changed, 40 insertions, 18 deletions
diff --git a/pseudo_util.c b/pseudo_util.c
index 2e75e69..97c9911 100644
--- a/pseudo_util.c
+++ b/pseudo_util.c
@@ -39,6 +39,12 @@
#include "pseudo_ipc.h"
#include "pseudo_db.h"
+struct pseudo_variables {
+ char *key;
+ size_t key_len;
+ char *value;
+};
+
/* The order below is not arbitrary, but based on an assumption
* of how often things will be used.
*/
@@ -58,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 */
};
@@ -69,12 +76,13 @@ 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));
#if 0
-static void dump_env(char **envp) {
+static void
+dump_env(char **envp) {
size_t i = 0;
for (i = 0; envp[i]; i++) {
pseudo_debug(0,"dump_envp: [%d]%s\n", (int) i, envp[i]);
@@ -84,18 +92,27 @@ static void 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) {
+char *
+pseudo_get_value(const char *key) {
size_t i = 0;
char * value;
- if (_in_init == -1) _libpseudo_init();
+ 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++) ;
+ for (i = 0; pseudo_env[i].key && memcmp(pseudo_env[i].key, key, pseudo_env[i].key_len + 1); i++)
+ ;
/* Check if the environment has it and we don't ...
* if so, something went wrong... so we'll attempt to recover
@@ -103,8 +120,10 @@ char * pseudo_get_value(const char * key) {
if (pseudo_env[i].key && !pseudo_env[i].value && getenv(pseudo_env[i].key))
_libpseudo_init();
- if (pseudo_env[i].value) value = strdup(pseudo_env[i].value);
- else value = NULL;
+ if (pseudo_env[i].value)
+ value = strdup(pseudo_env[i].value);
+ else
+ value = NULL;
if (!pseudo_env[i].key)
pseudo_diag("Unknown variable %s.\n", key);
@@ -113,17 +132,20 @@ char * pseudo_get_value(const char * key) {
}
/* We make a copy, so the original values should be freed. */
-int pseudo_set_value(const char * key, const char * value) {
+int
+pseudo_set_value(const char *key, const char *value) {
int rc = 0;
size_t i = 0;
- if (_in_init == -1) _libpseudo_init();
+ 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++)
;
if (pseudo_env[i].key) {
- if (pseudo_env[i].value) free(pseudo_env[i].value);
+ if (pseudo_env[i].value)
+ free(pseudo_env[i].value);
if (value) {
char *new = strdup(value);
if (new)
@@ -134,25 +156,25 @@ int 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;
}
return rc;
}
-static void _libpseudo_init(void) {
+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 (pseudo_env[i].key)
- if (getenv(pseudo_env[i].key))
- pseudo_set_value(pseudo_env[i].key, getenv(pseudo_env[i].key));
+ 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