summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/apk.c4
-rw-r--r--src/apk_context.h1
-rw-r--r--src/database.c4
3 files changed, 7 insertions, 2 deletions
diff --git a/src/apk.c b/src/apk.c
index da5fdd7..34f5c72 100644
--- a/src/apk.c
+++ b/src/apk.c
@@ -74,6 +74,7 @@ static void version(struct apk_out *out, const char *prefix)
OPT(OPT_GLOBAL_no_logfile, "no-logfile") \
OPT(OPT_GLOBAL_no_network, "no-network") \
OPT(OPT_GLOBAL_no_progress, "no-progress") \
+ OPT(OPT_GLOBAL_preserve_env, "preserve-env") \
OPT(OPT_GLOBAL_print_arch, "print-arch") \
OPT(OPT_GLOBAL_progress, "progress") \
OPT(OPT_GLOBAL_progress_fd, APK_OPT_ARG "progress-fd") \
@@ -155,6 +156,9 @@ static int option_parse_global(void *ctx, struct apk_ctx *ac, int opt, const cha
case OPT_GLOBAL_interactive:
ac->flags |= APK_INTERACTIVE;
break;
+ case OPT_GLOBAL_preserve_env:
+ ac->flags |= APK_PRESERVE_ENV;
+ break;
case OPT_GLOBAL_progress:
ac->progress.out = &ac->out;
break;
diff --git a/src/apk_context.h b/src/apk_context.h
index 5071404..ac0d3d3 100644
--- a/src/apk_context.h
+++ b/src/apk_context.h
@@ -29,6 +29,7 @@
#define APK_NO_COMMIT_HOOKS BIT(10)
#define APK_NO_CHROOT BIT(11)
#define APK_NO_LOGFILE BIT(12)
+#define APK_PRESERVE_ENV BIT(13)
#define APK_FORCE_OVERWRITE BIT(0)
#define APK_FORCE_OLD_APK BIT(1)
diff --git a/src/database.c b/src/database.c
index be7a0a1..b0c00aa 100644
--- a/src/database.c
+++ b/src/database.c
@@ -1873,7 +1873,7 @@ int apk_db_run_script(struct apk_database *db, char *fn, char **argv)
struct apk_out *out = &db->ctx->out;
int status;
pid_t pid;
- static char * const environment[] = {
+ static char * const clean_environment[] = {
"PATH=/usr/sbin:/usr/bin:/sbin:/bin",
NULL
};
@@ -1896,7 +1896,7 @@ int apk_db_run_script(struct apk_database *db, char *fn, char **argv)
exit(127);
}
- execve(fn, argv, environment);
+ execve(fn, argv, (db->ctx->flags & APK_PRESERVE_ENV) ? environ : clean_environment);
exit(127); /* should not get here */
}
while (waitpid(pid, &status, 0) < 0 && errno == EINTR);