aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-04-12 17:51:54 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-04-12 17:51:54 +0000
commit438cd3c783936cbb2814637a5c90c6a44f9d4fa9 (patch)
tree57717caa0f7d54c02e1fe3022f834e673f7ac2fa
parentd88fcf09f2c0616acd0d1c8c09fbc1ef4efe2eed (diff)
downloadpaludis-438cd3c783936cbb2814637a5c90c6a44f9d4fa9.tar.gz
paludis-438cd3c783936cbb2814637a5c90c6a44f9d4fa9.tar.xz
More ebin work
-rw-r--r--paludis/repositories/gentoo/ebin.cc85
-rw-r--r--paludis/repositories/gentoo/ebin.hh1
-rw-r--r--paludis/repositories/gentoo/ebin.se9
-rw-r--r--paludis/repositories/gentoo/ebin.sr1
-rw-r--r--paludis/repositories/gentoo/ebin_entries.cc56
-rw-r--r--paludis/repositories/gentoo/ebuild/builtin_initbin.bash27
-rw-r--r--paludis/repositories/gentoo/ebuild/builtin_unpackbin.bash7
-rwxr-xr-xpaludis/repositories/gentoo/ebuild/utils/dounpack24
8 files changed, 156 insertions, 54 deletions
diff --git a/paludis/repositories/gentoo/ebin.cc b/paludis/repositories/gentoo/ebin.cc
index bbd5796..99164db 100644
--- a/paludis/repositories/gentoo/ebin.cc
+++ b/paludis/repositories/gentoo/ebin.cc
@@ -24,6 +24,9 @@
#include <paludis/util/log.hh>
#include <paludis/util/strip.hh>
#include <paludis/about.hh>
+#include <sys/resource.h>
+#include <sys/time.h>
+#include <unistd.h>
using namespace paludis;
@@ -117,20 +120,36 @@ EbinCommand::operator() ()
.with_setenv("PALUDIS_FETCHERS_DIRS", params.environment->fetchers_dirs())
.with_setenv("PALUDIS_SYNCERS_DIRS", params.environment->syncers_dirs())
.with_setenv("PALUDIS_COMMAND", params.environment->paludis_command())
+ .with_setenv("PALUDIS_REDUCED_GID", stringify(params.environment->reduced_gid()))
+ .with_setenv("PALUDIS_REDUCED_UID", stringify(params.environment->reduced_uid()))
.with_setenv("KV", kernel_version())
.with_setenv("PALUDIS_EBUILD_LOG_LEVEL", stringify(Log::get_instance()->log_level()))
.with_setenv("PALUDIS_EBUILD_DIR", getenv_with_default("PALUDIS_EBUILD_DIR", LIBEXECDIR "/paludis")));
- if (do_run_command(cmd))
+ if (do_run_command(add_portage_vars(cmd)))
return success();
else
return failure();
}
-EbinFetchCommand::EbinFetchCommand(const EbinCommandParams & p, const EbinFetchCommandParams & f) :
- EbinCommand(p),
- fetch_params(f)
+Command
+EbinCommand::add_portage_vars(const Command & cmd) const
{
+ return Command(cmd)
+ .with_setenv("PORTAGE_BASHRC", "/dev/null")
+ .with_setenv("PORTAGE_BUILDDIR", stringify(params.buildroot) + "/" +
+ stringify(params.db_entry->name.category) + "/" +
+ stringify(params.db_entry->name.package) + "-" +
+ stringify(params.db_entry->version))
+ .with_setenv("PORTAGE_CALLER", params.environment->paludis_command())
+ .with_setenv("PORTAGE_GID", "0")
+ .with_setenv("PORTAGE_INST_GID", "0")
+ .with_setenv("PORTAGE_INST_UID", "0")
+ .with_setenv("PORTAGE_MASTER_PID", stringify(::getpid()))
+ .with_setenv("PORTAGE_NICENCESS", stringify(::getpriority(PRIO_PROCESS, 0)))
+ .with_setenv("PORTAGE_TMPDIR", stringify(params.buildroot))
+ .with_setenv("PORTAGE_TMPFS", "/dev/shm")
+ .with_setenv("PORTAGE_WORKDIR_MODE", "0700");
}
std::string
@@ -149,11 +168,24 @@ EbinFetchCommand::failure()
Command
EbinFetchCommand::extend_command(const Command & cmd)
{
- return Command(cmd)
- .with_setenv("B", fetch_params.b)
- .with_setenv("FLAT_BIN_URI", fetch_params.flat_bin_uri)
- .with_setenv("ROOT", fetch_params.root)
- .with_setenv("PALUDIS_USE_SAFE_RESUME", fetch_params.safe_resume ? "oohyesplease" : "");
+ Command result(Command(cmd)
+ .with_setenv("B", fetch_params.b)
+ .with_setenv("FLAT_BIN_URI", fetch_params.flat_bin_uri)
+ .with_setenv("ROOT", fetch_params.root)
+ .with_setenv("PALUDIS_USE_SAFE_RESUME", fetch_params.safe_resume ? "oohyesplease" : "")
+ .with_setenv("ROOT", fetch_params.root)
+ .with_setenv("PALUDIS_USE_SAFE_RESUME", fetch_params.safe_resume ? "oohyesplease" : ""));
+
+ if (fetch_params.userpriv)
+ result.with_uid_gid(params.environment->reduced_uid(), params.environment->reduced_gid());
+
+ return result;
+}
+
+EbinFetchCommand::EbinFetchCommand(const EbinCommandParams & p, const EbinFetchCommandParams & f) :
+ EbinCommand(p),
+ fetch_params(f)
+{
}
std::string
@@ -161,14 +193,23 @@ EbinInstallCommand::commands() const
{
switch (install_params.phase)
{
- case ebin_ip_unpack:
- return "initbin unpackbin";
+ case ebin_ip_prepare:
+ return "prepare";
+
+ case ebin_ip_initbinenv:
+ return "initbin saveenv";
+
+ case ebin_ip_setup:
+ return "loadenv setup saveenv";
+
+ case ebin_ip_unpackbin:
+ return "loadenv unpackbin saveenv";
case ebin_ip_preinstall:
- return "preinst saveenv";
+ return "loadenv strip preinst saveenv";
case ebin_ip_postinstall:
- return "loadenv postinst";
+ return "loadenv postinst saveenv";
case ebin_ip_tidyup:
return "tidyup";
@@ -223,24 +264,6 @@ EbinInstallCommand::extend_command(const Command & cmd)
.with_setenv("PALUDIS_DEBUG_BUILD", debug_build)
.with_setenv("SLOT", stringify(install_params.slot)));
- switch (install_params.phase)
- {
- case ebin_ip_preinstall:
- case ebin_ip_postinstall:
- result
- .with_setenv("PALUDIS_LOAD_ENVIRONMENT", stringify(params.buildroot /
- stringify(params.db_entry->name.category) / (
- stringify(params.db_entry->name.package) + "-" + stringify(params.db_entry->version)) / "temp"
- / "binpkgenv"))
- .with_setenv("PALUDIS_SKIP_INHERIT", "yes");
- break;
-
- case ebin_ip_unpack:
- case ebin_ip_tidyup:
- case last_ebin_ip:
- ;
- };
-
return result;
}
diff --git a/paludis/repositories/gentoo/ebin.hh b/paludis/repositories/gentoo/ebin.hh
index 1ebacd0..f59c1f4 100644
--- a/paludis/repositories/gentoo/ebin.hh
+++ b/paludis/repositories/gentoo/ebin.hh
@@ -67,6 +67,7 @@ namespace paludis
virtual bool failure() = 0;
virtual bool do_run_command(const Command &);
virtual Command extend_command(const Command &) = 0;
+ virtual Command add_portage_vars(const Command &) const;
public:
virtual ~EbinCommand();
diff --git a/paludis/repositories/gentoo/ebin.se b/paludis/repositories/gentoo/ebin.se
index cd5f8b2..0bfb079 100644
--- a/paludis/repositories/gentoo/ebin.se
+++ b/paludis/repositories/gentoo/ebin.se
@@ -5,9 +5,12 @@ make_enum_EbinInstallCommandPhase()
{
prefix ebin_ip
- key ebin_ip_unpack "Initialise and unpack."
- key ebin_ip_preinstall "Preinstall to a live system."
- key ebin_ip_postinstall "Postinstall to a live system."
+ key ebin_ip_prepare "Prepare the working directory"
+ key ebin_ip_initbinenv "Extract and load the binary environment"
+ key ebin_ip_setup "Perform pre-unpack setup phases"
+ key ebin_ip_unpackbin "Extract the binary"
+ key ebin_ip_preinstall "Preinstall to a live system"
+ key ebin_ip_postinstall "Postinstall to a live system"
key ebin_ip_tidyup "Tidy up work."
doxygen_comment << "END"
diff --git a/paludis/repositories/gentoo/ebin.sr b/paludis/repositories/gentoo/ebin.sr
index a1bb6a2..9246fbf 100644
--- a/paludis/repositories/gentoo/ebin.sr
+++ b/paludis/repositories/gentoo/ebin.sr
@@ -28,6 +28,7 @@ make_class_EbinFetchCommandParams()
key flat_bin_uri std::string
key root std::string
key safe_resume bool
+ key userpriv bool
doxygen_comment << "END"
/**
diff --git a/paludis/repositories/gentoo/ebin_entries.cc b/paludis/repositories/gentoo/ebin_entries.cc
index 46719c8..b9ea1f0 100644
--- a/paludis/repositories/gentoo/ebin_entries.cc
+++ b/paludis/repositories/gentoo/ebin_entries.cc
@@ -25,6 +25,8 @@
#include <paludis/dep_spec_flattener.hh>
#include <paludis/environment.hh>
#include <paludis/util/strip.hh>
+#include <paludis/util/log.hh>
+#include <paludis/util/system.hh>
#include <set>
#include <fstream>
@@ -218,12 +220,40 @@ EbinEntries::install(const QualifiedPackageName & q, const VersionSpec & v,
.pkgdir(_imp->params.pkgdir)
.buildroot(_imp->params.buildroot));
+ bool fetch_userpriv_ok(_imp->environment->reduced_gid() != getgid());
+ if (fetch_userpriv_ok)
+ {
+ FSEntry f(_imp->params.pkgdir);
+ Context c("When checking permissions on '" + stringify(f) + "' for userpriv:");
+
+ if (f.exists())
+ {
+ if (f.group() != _imp->environment->reduced_gid())
+ {
+ Log::get_instance()->message(ll_warning, lc_context, "Directory '" +
+ stringify(f) + "' owned by group '" +
+ stringify(get_group_name(f.group())) + "', not '" +
+ stringify(get_group_name(_imp->environment->reduced_gid())) +
+ "', so cannot enable userpriv");
+ fetch_userpriv_ok = false;
+ }
+ else if (! f.has_permission(fs_ug_group, fs_perm_write))
+ {
+ Log::get_instance()->message(ll_warning, lc_context, "Directory '" +
+ stringify(f) + "' does not group write permission," +
+ "cannot enable userpriv");
+ fetch_userpriv_ok = false;
+ }
+ }
+ }
+
EbinFetchCommand fetch_cmd(command_params,
EbinFetchCommandParams::create()
.b(binaries)
.flat_bin_uri(flat_bin_uri)
.root(stringify(get_root(o.destinations)))
- .safe_resume(o.safe_resume));
+ .safe_resume(o.safe_resume)
+ .userpriv(false));
fetch_cmd();
@@ -239,7 +269,7 @@ EbinEntries::install(const QualifiedPackageName & q, const VersionSpec & v,
.b(binaries)
.root(stringify(get_root(o.destinations)))
.debug_build(o.debug_build)
- .phase(ebin_ip_unpack)
+ .phase(ebin_ip_prepare)
.disable_cfgpro(o.no_config_protect)
.config_protect(_imp->portage_repository->profile_variable("CONFIG_PROTECT"))
.config_protect_mask(_imp->portage_repository->profile_variable("CONFIG_PROTECT_MASK"))
@@ -247,9 +277,20 @@ EbinEntries::install(const QualifiedPackageName & q, const VersionSpec & v,
stringify(q.package) + "-" + stringify(v)) / "temp")
.slot(SlotName(metadata->slot)));
- EbinInstallCommand build_cmd(command_params, install_params);
- build_cmd();
+ EbinInstallCommand prepare_cmd(command_params, install_params);
+ prepare_cmd();
+ install_params.phase = ebin_ip_initbinenv;
+ EbinInstallCommand initbinenv_cmd(command_params, install_params);
+ initbinenv_cmd();
+
+ install_params.phase = ebin_ip_setup;
+ EbinInstallCommand setup_cmd(command_params, install_params);
+ setup_cmd();
+
+ install_params.phase = ebin_ip_unpackbin;
+ EbinInstallCommand unpackbin_cmd(command_params, install_params);
+ unpackbin_cmd();
for (DestinationsCollection::Iterator d(o.destinations->begin()),
d_end(o.destinations->end()) ; d != d_end ; ++d)
@@ -324,7 +365,7 @@ EbinEntries::merge(const MergeOptions & m)
ebin_dir /= stringify(m.package.name.package);
ebin_dir.mkdir();
- FSEntry ebin_file_name(ebin_dir / (stringify(m.package.name.package) + "-" + stringify(m.package.version) + ".ebin"));
+ FSEntry ebin_file_name(ebin_dir / (stringify(m.package.name.package) + "-" + stringify(m.package.version) + ".ebin.incomplete"));
std::ofstream ebin_file(stringify(ebin_file_name).c_str());
if (! ebin_file)
throw PackageInstallActionError("Cannot write to '" + stringify(ebin_file_name) + "'");
@@ -385,5 +426,10 @@ EbinEntries::merge(const MergeOptions & m)
.environment_file(m.environment_file));
merge_cmd();
+
+ FSEntry real_ebin_file_name(ebin_dir / (stringify(m.package.name.package) + "-" + stringify(m.package.version) + ".ebin"));
+ if (real_ebin_file_name.exists())
+ real_ebin_file_name.unlink();
+ ebin_file_name.rename(real_ebin_file_name);
}
diff --git a/paludis/repositories/gentoo/ebuild/builtin_initbin.bash b/paludis/repositories/gentoo/ebuild/builtin_initbin.bash
index e3fb370..5e7075c 100644
--- a/paludis/repositories/gentoo/ebuild/builtin_initbin.bash
+++ b/paludis/repositories/gentoo/ebuild/builtin_initbin.bash
@@ -23,9 +23,8 @@ builtin_initbin()
local a
for a in P PV PR PN PVR PF CATEGORY PORTDIR \
PKGDIR KV PALUDIS_TMPDIR PALUDIS_EBUILD_LOG_LEVEL PALUDIS_EBUILD_DIR \
- CHOST PALUDIS_COMMAND ROOT ; do
+ CHOST PALUDIS_COMMAND ROOT PALUDIS_LOADSAVEENV_DIR ; do
[[ -z "${!a}" ]] && die "\$${a} unset or empty"
- declare -r ${a}="${!a}"
done
for a in PKGDIR ; do
@@ -41,22 +40,38 @@ builtin_initbin()
export WORKDIR="${PALUDIS_TMPDIR}/${CATEGORY}/${PF}/work"
mkdir -p "${WORKDIR}" || die "Couldn't create \$WORKDIR (\"${WORKDIR}\")"
- declare -r WORKDIR="${WORKDIR}"
export T="${PALUDIS_TMPDIR}/${CATEGORY}/${PF}/temp/"
mkdir -p "${T}" || die "Couldn't create \$T (\"${T}\")"
- declare -r T="${T}"
export HOME="${T}"
export D="${PALUDIS_TMPDIR}/${CATEGORY}/${PF}/image/"
export D="${D//+(\/)//}"
mkdir -p "${D}" || die "Couldn't create \$D (\"${D}\")"
- declare -r D="${D}"
export IMAGE="${D}"
- declare -r IMAGE="${IMAGE}"
export S="${WORKDIR}/${P}"
+
+ [[ -n "${B}" ]] && unpack --binary --only .paludis-binpkg-environment ${B}
+
+ [[ -f "${IMAGE}/.paludis-binpkg-environment" ]] || \
+ die "No saved environment in binary tarball"
+
+ local save_PALUDIS_EXTRA_DIE_MESSAGE="${PALUDIS_EXTRA_DIE_MESSAGE}"
+
+ echo ebuild_scrub_environment "${IMAGE}/.paludis-binpkg-environment" 1>&2
+ ebuild_scrub_environment "${IMAGE}/.paludis-binpkg-environment" \
+ || die "Can't load saved environment for cleaning"
+
+ echo source "${IMAGE}/.paludis-binpkg-environment" 1>&2
+ source "${IMAGE}/.paludis-binpkg-environment" \
+ || die "Can't load saved environment"
+
+ export PALUDIS_EXTRA_DIE_MESSAGE="${save_PALUDIS_EXTRA_DIE_MESSAGE}"
+
+ echo rm "${IMAGE}/.paludis-binpkg-environment" 1>&2
+ rm "${IMAGE}/.paludis-binpkg-environment"
}
ebuild_f_initbin()
diff --git a/paludis/repositories/gentoo/ebuild/builtin_unpackbin.bash b/paludis/repositories/gentoo/ebuild/builtin_unpackbin.bash
index 2ed7c28..975af78 100644
--- a/paludis/repositories/gentoo/ebuild/builtin_unpackbin.bash
+++ b/paludis/repositories/gentoo/ebuild/builtin_unpackbin.bash
@@ -19,12 +19,7 @@
builtin_unpackbin()
{
[[ -n "${B}" ]] && unpack --binary ${B}
-
- [[ -f "${IMAGE}/.paludis-binpkg-environment" ]] || \
- die "No saved environment in binary tarball"
-
- mv "${IMAGE}"/.paludis-binpkg-environment ${T}/binpkgenv \
- || die "Couldn't extract saved environment"
+ rm -f ${D}/.paludis-binpkg-environment
}
ebuild_f_unpackbin()
diff --git a/paludis/repositories/gentoo/ebuild/utils/dounpack b/paludis/repositories/gentoo/ebuild/utils/dounpack
index 0b1aebd..10bc86d 100755
--- a/paludis/repositories/gentoo/ebuild/utils/dounpack
+++ b/paludis/repositories/gentoo/ebuild/utils/dounpack
@@ -1,7 +1,7 @@
#!/bin/bash
# vim: set sw=4 sts=4 et :
-# Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
+# Copyright (c) 2006, 2007 Ciaran McCreesh <ciaranm@ciaranm.org>
#
# Based in part upon ebuild.sh from Portage, which is Copyright 1995-2005
# Gentoo Foundation and distributed under the terms of the GNU General
@@ -32,6 +32,17 @@ unpack_one()
[[ -z "$1" ]] && die "Bad argument for unpack_one"
[[ -e "$1" ]] || die "${1} doesn't exist"
+ if [[ -n "${UNPACKONLY}" ]] ; then
+ case "${x}" in
+ *.tar.bz2|*.tbz2)
+ ;;
+
+ *)
+ die "Can't use --only with ${x}"
+ ;;
+ esac
+ fi
+
case "${x}" in
*.tar)
echo tar xf "${1}" --no-same-owner "${TAR_OPTIONS[@]}" 1>&2
@@ -44,8 +55,8 @@ unpack_one()
;;
*.tar.bz2|*.tbz2)
- echo tar jxf "${1}" --no-same-owner "${TAR_OPTIONS[@]}" 1>&2
- tar jxf "${1}" --no-same-owner "${TAR_OPTIONS[@]}" || die "Couldn't unpack ${1}"
+ echo tar jxf "${1}" --no-same-owner "${TAR_OPTIONS[@]}" ${UNPACKONLY} 1>&2
+ tar jxf "${1}" --no-same-owner "${TAR_OPTIONS[@]}" ${UNPACKONLY} || die "Couldn't unpack ${1}"
;;
*.zip|*.ZIP|*.jar)
@@ -94,6 +105,13 @@ if [[ "${1}" == "--binary" ]] ; then
shift
fi
+unset UNPACKONLY
+if [[ "${1}" == "--only" ]] ; then
+ shift
+ export UNPACKONLY="${1}"
+ shift
+fi
+
TAR_OPTIONS=( )
while [[ "${1}" == --tar-option=* ]] ; do
TAR_OPTIONS[${#TAR_OPTIONS[@]}]="${1#*=}"