aboutsummaryrefslogtreecommitdiffstats
path: root/pseudo_util.c
diff options
context:
space:
mode:
authorPeter Seebach <peter.seebach@windriver.com>2014-05-16 15:43:55 -0500
committerPeter Seebach <peter.seebach@windriver.com>2014-05-16 15:43:55 -0500
commitc9890aca3a3045e53bb9b7754c80f7ded51e65f6 (patch)
tree367fd4e3e34aefb36a1b188def698244ba83b0d0 /pseudo_util.c
parentbec11654de69611ae6088d3aaa4a8d6f40265603 (diff)
downloadpseudo-c9890aca3a3045e53bb9b7754c80f7ded51e65f6.tar.gz
pseudo-c9890aca3a3045e53bb9b7754c80f7ded51e65f6.tar.bz2
pseudo-c9890aca3a3045e53bb9b7754c80f7ded51e65f6.zip
pseudo_has_unload: add function
Various wrappers checked for a non-null pseudo_get_value("PSEUDO_UNLOAD") to determine whether the environment should include the pseudo variables. None of those checks freed the returned value when it was not null. The new check function does. The new check function also sees whether PSEUDO_UNLOAD was defined in the environment that should be used in the wrapped system call. This allows pkg_postinst scripts to strip out the LD_PRELOAD setting, for example before invoking qemu to execute commands in an environment that does not have libpseudo.so. [YOCTO #4843] Signed-off-by: Peter A. Bigot <pab@pabigot.com> Signed-off-by: Peter Seebach <peter.seebach@windriver.com>
Diffstat (limited to 'pseudo_util.c')
-rw-r--r--pseudo_util.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/pseudo_util.c b/pseudo_util.c
index f20dbec..325cabf 100644
--- a/pseudo_util.c
+++ b/pseudo_util.c
@@ -95,6 +95,33 @@ dump_env(char **envp) {
}
#endif
+int
+pseudo_has_unload(char * const *envp) {
+ static const char unload[] = "PSEUDO_UNLOAD";
+ static size_t unload_len = strlen(unload);
+ size_t i = 0;
+
+ /* Is it in the caller environment? */
+ if (NULL != getenv(unload))
+ return 1;
+
+ /* Is it in the environment cache? */
+ if (pseudo_util_initted == -1)
+ pseudo_init_util();
+ while (pseudo_env[i].key && strcmp(pseudo_env[i].key, unload))
+ ++i;
+ if (pseudo_env[i].key && pseudo_env[i].value)
+ return 1;
+
+ /* Is it in the operational environment? */
+ while (envp && *envp) {
+ if ((!strncmp(*envp, unload, unload_len)) && ('=' == (*envp)[unload_len]))
+ return 1;
+ ++envp;
+ }
+ return 0;
+}
+
/* Caller must free memory! */
char *
pseudo_get_value(const char *key) {