commit: 404bfb9774d367207164c3a2a10b43754c83259c
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Mon Nov 17 01:35:39 2014 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Mon Nov 17 01:35:39 2014 +0000
URL:
http://sources.gentoo.org/gitweb/?p=proj/hardened-dev.git;a=commit;h=404bfb97
sys-apps/ldconfig: add musl ldconfig script
Package-Manager: portage-2.2.8-r2
Manifest-Sign-Key: 0xF52D4BBA
---
sys-apps/ldconfig/files/ldconfig-0.1 | 136 ++++++++++++++++++++++++++++++++++
sys-apps/ldconfig/ldconfig-0.1.ebuild | 31 ++++++++
sys-apps/ldconfig/metadata.xml | 8 ++
3 files changed, 175 insertions(+)
diff --git a/sys-apps/ldconfig/files/ldconfig-0.1
b/sys-apps/ldconfig/files/ldconfig-0.1
new file mode 100644
index 0000000..c5ec1df
--- /dev/null
+++ b/sys-apps/ldconfig/files/ldconfig-0.1
@@ -0,0 +1,136 @@
+#!/bin/bash -e
+
+ROOT="/"
+
+LDSO_CONF="/etc/ld.so.conf"
+if [[ ! -e $LDSO_CONF ]]; then
+ echo "$LDSO_CONF not found" >&2
+ exit 1
+fi
+
+LDSO_CONF_DIR=$(dirname $LDSO_CONF)
+
+LDSO_PATH=$(ls /lib/ld-musl-*.so.1)
+if [[ ! -e $LDSO_PATH ]]; then
+ echo "$LDSO_PATH not found" >&2
+ exit 1
+fi
+
+LDSO_ARCH=$(basename $LDSO_PATH)
+LDSO_NAME=${LDSO_ARCH%.so.1}
+ETC_LDSO_PATH=/etc/${LDSO_NAME}.path
+
+VERBOSE=0
+
+get_options() {
+ while getopts "vnNXf:C:r:p" opt "$@"; do
+ case $opt in
+ v)
+ echo "ldconfig for musl in Gentoo"
+ VERBOSE=1
+ ;;
+ r)
+ ROOT=$OPTARG
+ ;;
+ f)
+ LDSOCONF=$OPTARG
+ ;;
+ \?)
+ echo "Invalid option: -$opt" >&2
+ exit 1
+ ;;
+ n|N|X|C)
+ echo "Unimplemented option: -$opt" >&2
+ exit 1
+ ;;
+ esac
+ done
+}
+
+repeated() {
+ local l=$1
+ local drs="${@:2}"
+ for m in $drs; do
+ [[ $m == $l ]] && return 0
+ done
+ return 1
+}
+
+expand() {
+ # We are assuming the ld.so.conf's 'include' is not recursive
+ local f line l
+ local glob="$LDSO_CONF_DIR/$1"
+ local drs="${@:2} "
+
+ for f in $glob; do
+ [[ ! -f $f ]] && continue
+ while read line; do
+ line=${line%%#*}
+ line=${line//:/ }
+ line=${line//,/ }
+ for l in $line; do
+ if [[ -d $l ]]; then
+ repeated $l $drs && continue
+ drs+=" $l "
+ fi
+ done
+ done < $f
+ done
+
+ echo $drs
+}
+
+read_ldso_conf() {
+ local drs=" "
+
+ while read line; do
+ # Sanitize the line - see ldconfig(8) for delimiters
+ # Note: bash read turns tabs into spaces and read already
+ # delimits on newlines with the default $IFS
+ line=${line%%#*} # Remove comments
+ line=${line//:/ } # Change colon delimiter to space
+ line=${line//,/ } # Change comma delimiter to space
+
+ next=0
+ for l in $line; do
+ if [[ $next == 1 ]]; then
+ next=0
+ drs=$(expand $l $drs)
+ elif [[ $l == "include" ]]; then
+ next=1
+ else
+ # glibc's ldconfig silently skips non
directories
+ if [[ -d $l ]]; then
+ repeated $l $drs && continue
+ drs+=" $l "
+ fi
+ fi
+ done
+ done < $LDSO_CONF
+
+ echo $drs
+}
+
+sanitize() {
+ local drs=$@
+
+ repeated "/lib" $drs || drs="/lib $drs"
+ repeated "/usr/lib" $drs || drs="/usr/lib $drs"
+
+ echo $drs
+}
+
+get_options "$@"
+drs=$(read_ldso_conf)
+drs=$(sanitize $drs)
+
+X=$(mktemp --tmpdir=/tmp ${LDSO_NAME}.XXXXXX)
+cat << EOF > $X
+# $ETC_LDSO_PATH autogenerated by env-update; make all changes to
+# contents of /etc/env.d directory
+EOF
+for d in $drs; do
+ echo $d >> $X
+done
+mv $X $ETC_LDSO_PATH
+
diff --git a/sys-apps/ldconfig/ldconfig-0.1.ebuild
b/sys-apps/ldconfig/ldconfig-0.1.ebuild
new file mode 100644
index 0000000..bbbc42d
--- /dev/null
+++ b/sys-apps/ldconfig/ldconfig-0.1.ebuild
@@ -0,0 +1,31 @@
+# Copyright 1999-2014 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: $
+
+EAPI=5
+
+DESCRIPTION="ldconfig for musl in Gentoo"
+HOMEPAGE="http://dev.gentoo.org/~blueness"
+SRC_URI=""
+
+LICENSE="GPL-2"
+SLOT="0"
+KEYWORDS="~amd64"
+IUSE=""
+
+DEPEND=""
+RDEPEND="${DEPEND}"
+
+pkg_preinst () {
+ use elibc_musl || die "This package only works on a musl system"
+}
+
+src_unpack () {
+ mkdir -p ${P}
+ cp "${FILESDIR}"/${P} ${P}/${PN}
+}
+
+src_install () {
+ into /
+ dosbin ${PN}
+}
diff --git a/sys-apps/ldconfig/metadata.xml b/sys-apps/ldconfig/metadata.xml
new file mode 100644
index 0000000..1e75873
--- /dev/null
+++ b/sys-apps/ldconfig/metadata.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+ <maintainer>
+ <email>[email protected]</email>
+ <name>Anthony G. Basile</name>
+ </maintainer>
+</pkgmetadata>