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

Allan McRae allan at archlinux.org
Mon Feb 22 03:44:15 UTC 2016


On 22/02/16 00:40, Thomas Bächler wrote:
> 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.

This just makes install scriptlets more complicated... The alternative
approach is for stupid distribution packagers to not start using hooks
while (1) there is a major bug in them and (2) it has not been announced
by the distribution that everyone should update to pacman-5.0 because we
now require its features.

> ---
>  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();

A whole function for one line...

>  		/* 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));
>


More information about the pacman-dev mailing list