[pacman-dev] [PATCH] Set an environment variable to indicate hooks support

Thomas Bächler thomas at archlinux.org
Sun Feb 21 14:40:58 UTC 2016


When replacing existing post_install and post_upgrade functionality with hooks, it
is necessary to ensure that pacman has already been upgraded. To allow a smooth
transition, export the ALPM_FEATURE_HOOKS variable with the value 1 in all processes
spawned by pacman.

An install scriptlet can fall back to old behaviour if this variable is not set,
but rely on pacman hooks if it is not set.
---
 lib/libalpm/util.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index 001c042..86e3943 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -545,6 +545,11 @@ static int _alpm_chroot_read_from_child(alpm_handle_t *handle, int fd,
 	return 0;
 }
 
+void _alpm_setup_child_environment()
+{
+	setenv("ALPM_FEATURE_HOOKS", "1", 1);
+}
+
 /** Execute a command with arguments in a chroot.
  * @param handle the context handle
  * @param cmd command to execute
@@ -618,6 +623,8 @@ int _alpm_run_chroot(alpm_handle_t *handle, const char *cmd, char *const argv[],
 			close(cwdfd);
 		}
 
+		/* set up the child environment */
+		_alpm_setup_child_environment();
 		/* use fprintf instead of _alpm_log to send output through the parent */
 		if(chroot(handle->root) != 0) {
 			fprintf(stderr, _("could not change the root directory (%s)\n"), strerror(errno));
-- 
2.7.1


More information about the pacman-dev mailing list