aboutsummaryrefslogtreecommitdiffstats
path: root/pseudo_util.c
diff options
context:
space:
mode:
authorMark Hatle <mark.hatle@windriver.com>2010-12-08 15:33:30 -0600
committerPeter Seebach <peter.seebach@windriver.com>2010-12-13 15:01:49 -0600
commiteba97c46608e776088a86d9d8db25d07e8de09ac (patch)
treeb04c5c61dd4ed181adf0f3810d13de75b37dea09 /pseudo_util.c
parent048cd003f3330f0811a48f79cd9d65bf022757a9 (diff)
downloadpseudo-eba97c46608e776088a86d9d8db25d07e8de09ac.tar.gz
pseudo-eba97c46608e776088a86d9d8db25d07e8de09ac.tar.bz2
pseudo-eba97c46608e776088a86d9d8db25d07e8de09ac.zip
Further amend the system to enable/disable sudo during fork/exec.
2010-12-09: * (mhatle) Add doc/program_flow to attempt to explain startup/running * (mhatle) guts/* minor cleanup * (mhatle) Reorganize into a new constructor for libpseudo ONLY pseudo main() now manually calls the util init new / revised init for client, wrappers and utils * (mhatle) Add central "reinit" function * (mhatle) Add manul execv* functions * (mhatle) rename pseudo_populate_wrappers to pseudo_check_wrappers Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
Diffstat (limited to 'pseudo_util.c')
-rw-r--r--pseudo_util.c44
1 files changed, 24 insertions, 20 deletions
diff --git a/pseudo_util.c b/pseudo_util.c
index 97c9911..dc55b0c 100644
--- a/pseudo_util.c
+++ b/pseudo_util.c
@@ -76,9 +76,7 @@ static struct pseudo_variables pseudo_env[] = {
* program starts playing with things, so we need to do our
* best to handle that case.
*/
-static int _pseudo_in_init = -1; /* Not yet run */
-
-static void _libpseudo_init(void) __attribute__ ((constructor));
+static int pseudo_util_initted = -1; /* Not yet run */
#if 0
static void
@@ -92,24 +90,18 @@ 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", _pseudo_in_init);
+ pseudo_debug(0, "dump_envp: _in_init %d\n", pseudo_util_initted);
}
#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 (_pseudo_in_init == -1)
- _libpseudo_init();
+ if (pseudo_util_initted == -1)
+ pseudo_init_util();
for (i = 0; pseudo_env[i].key && memcmp(pseudo_env[i].key, key, pseudo_env[i].key_len + 1); i++)
;
@@ -118,7 +110,7 @@ pseudo_get_value(const char *key) {
* if so, something went wrong... so we'll attempt to recover
*/
if (pseudo_env[i].key && !pseudo_env[i].value && getenv(pseudo_env[i].key))
- _libpseudo_init();
+ pseudo_init_util();
if (pseudo_env[i].value)
value = strdup(pseudo_env[i].value);
@@ -137,8 +129,8 @@ pseudo_set_value(const char *key, const char *value) {
int rc = 0;
size_t i = 0;
- if (_pseudo_in_init == -1)
- _libpseudo_init();
+ if (pseudo_util_initted == -1)
+ pseudo_init_util();
for (i = 0; pseudo_env[i].key && memcmp(pseudo_env[i].key, key, pseudo_env[i].key_len + 1); i++)
;
@@ -156,25 +148,37 @@ pseudo_set_value(const char *key, const char *value) {
} else
pseudo_env[i].value = NULL;
} else {
- if (!_pseudo_in_init) pseudo_diag("Unknown variable %s.\n", key);
+ if (!pseudo_util_initted) pseudo_diag("Unknown variable %s.\n", key);
rc = -EINVAL;
}
return rc;
}
-static void
-_libpseudo_init(void) {
+void
+pseudo_init_util(void) {
size_t i = 0;
+ char * env;
- _pseudo_in_init = 1;
+ pseudo_util_initted = 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));
}
- _pseudo_in_init = 0;
+ pseudo_util_initted = 0;
+
+ /* Somewhere we have to set the debug level.. */
+ env = pseudo_get_value("PSEUDO_DEBUG");
+ if (env) {
+ int i;
+ int level = atoi(env);
+ for (i = 0; i < level; ++i) {
+ pseudo_debug_verbose();
+ }
+ }
+ free(env);
}
/* 5 = ridiculous levels of duplication