diff --git a/doc/apk.8.scd b/doc/apk.8.scd index 2a096f7..7b104a5 100644 --- a/doc/apk.8.scd +++ b/doc/apk.8.scd @@ -150,6 +150,9 @@ The following options are available for all commands. *--no-progress* Disable progress bar even for TTYs. +*--preserve-env* + Pass user environment down to scripts. + *--print-arch* Print default arch and exit. 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);