From a91baa2fff69354dc5f626a7570ff05b4cc75db3 Mon Sep 17 00:00:00 2001 From: Mykola Malkov Date: Thu, 6 Sep 2018 15:28:33 +0200 Subject: [PATCH] TT#48647 Ship fake_uname lib in package Instead of runtime compiling during the installation compile this lib in package building and deliver as part of the package. Change-Id: Ic97adb0c958c57976ac5d23974b0efc306ccb326 --- .gitignore | 1 + Makefile | 3 ++ debian/install | 1 + src/Makefile | 15 ++++++ src/fake-uname.c | 44 +++++++++++++++ templates/scripts/includes/deployment.sh | 68 +++--------------------- 6 files changed, 71 insertions(+), 61 deletions(-) create mode 100644 src/Makefile create mode 100644 src/fake-uname.c diff --git a/.gitignore b/.gitignore index e3af6bc..0fb73d9 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ grml_build/grml_chroot/ grml_build/grml_isos/ grml_build/grml_logs/ grml_build/netboot/ +*.so diff --git a/Makefile b/Makefile index dc81788..5c14638 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ NGCP_VERSION := $(strip $(NGCP_VERSION)) all: build build: + $(MAKE) -C src syntaxcheck: shellcheck @@ -27,6 +28,7 @@ clean: rm -f templates/boot/isolinux/syslinux.cfg rm -f templates/boot/grub/grub.cfg rm -f templates/boot/isolinux/isolinux.cfg + $(MAKE) -C src $@ dist-clean: clean rm -rf artifacts @@ -37,5 +39,6 @@ dist-clean: clean rm -rf grml_build/grml_isos rm -rf grml_build/grml_logs rm -rf grml_build/netboot + rm -f fake-uname.so .PHONY: clean dist-clean syntaxcheck shellcheck build all script_version diff --git a/debian/install b/debian/install index ff4145f..cfb28c0 100644 --- a/debian/install +++ b/debian/install @@ -1 +1,2 @@ +src/fake-uname.so usr/lib/ngcp-deployment-scripts/ templates/scripts/* usr/share/ngcp-deployment-scripts/ diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..6878977 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,15 @@ +PACKAGE_VERSION := $(shell dpkg-parsechangelog -SVersion -l../debian/changelog) + +CPPFLAGS ?= +CPPFLAGS += -DPACKAGE_VERSION="\"$(PACKAGE_VERSION)\"" + +CFLAGS ?= -ggdb -O2 -Wall -Wextra -Wno-unused-parameter +CFLAGS += -fPIC -ldl + +PLUGIN = fake-uname.so + +$(PLUGIN): fake-uname.c + $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ -shared $< + +clean: + $(RM) *.o *.so diff --git a/src/fake-uname.c b/src/fake-uname.c new file mode 100644 index 0000000..cad9850 --- /dev/null +++ b/src/fake-uname.c @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef UTS_RELEASE +#define UTS_RELEASE "0.0.0" +#endif + +#ifndef RTLD_NEXT +#define RTLD_NEXT ((void *) -1l) +#endif + +typedef int (*uname_t) (struct utsname * buf); + +static void *get_libc_func(const char *funcname) +{ + void *func; + char *error; + + func = dlsym(RTLD_NEXT, funcname); + if ((error = dlerror()) != NULL) { + fprintf(stderr, "Can't locate libc function '%s' error: %s", funcname, error); + _exit(EXIT_FAILURE); + } + return func; +} + +int uname(struct utsname *buf) +{ + int ret; + char *env = NULL; + uname_t real_uname = (uname_t) get_libc_func("uname"); + + ret = real_uname((struct utsname *) buf); + strncpy(buf->release, ((env = getenv("UTS_RELEASE")) == NULL) ? UTS_RELEASE : env, 65); + return ret; +} diff --git a/templates/scripts/includes/deployment.sh b/templates/scripts/includes/deployment.sh index e58b01b..8ec28c4 100755 --- a/templates/scripts/includes/deployment.sh +++ b/templates/scripts/includes/deployment.sh @@ -1780,61 +1780,6 @@ case "$DEBIAN_RELEASE" in ;; esac -fake_uname() { - cat > "${TARGET}/tmp/uname.c" << EOF -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifndef UTS_RELEASE -#define UTS_RELEASE "0.0.0" -#endif - -#ifndef RTLD_NEXT -#define RTLD_NEXT ((void *) -1l) -#endif - -typedef int (*uname_t) (struct utsname * buf); - -static void *get_libc_func(const char *funcname) -{ - void *func; - char *error; - - func = dlsym(RTLD_NEXT, funcname); - if ((error = dlerror()) != NULL) { - fprintf(stderr, "Can't locate libc function \`%s' error: %s", funcname, error); - _exit(EXIT_FAILURE); - } - return func; -} - -int uname(struct utsname *buf) -{ - int ret; - char *env = NULL; - uname_t real_uname = (uname_t) get_libc_func("uname"); - - ret = real_uname((struct utsname *) buf); - strncpy(buf->release, ((env = getenv("UTS_RELEASE")) == NULL) ? UTS_RELEASE : env, 65); - return ret; -} -EOF - - grml-chroot "$TARGET" gcc -shared -fPIC -ldl /tmp/uname.c -o /tmp/fake-uname.so || die 'Failed to build fake-uname.so' - - # avoid "ERROR: ld.so: object '/tmp/fake-uname.so' from LD_PRELOAD cannot be preloaded: ignored." - # messages caused by the host system when running grml-chroot process - cp "$TARGET"/tmp/fake-uname.so /tmp/fake-uname.so -} - vagrant_configuration() { # bzip2, linux-headers-amd64 and make are required for VirtualBox Guest Additions installer # less + sudo are required for Vagrant itself @@ -1885,10 +1830,6 @@ vagrant_configuration() { install_vbox_iso - # required for fake_uname and VBoxLinuxAdditions.run - grml-chroot $TARGET apt-get -y install libc6-dev gcc - fake_uname - # shellcheck disable=SC2010 KERNELHEADERS=$(basename "$(ls -d ${TARGET}/usr/src/linux-headers*amd64 | grep -v -- -rt-amd64 | sort -u -r -V | head -1)") if [ -z "$KERNELHEADERS" ] ; then @@ -1906,8 +1847,13 @@ vagrant_configuration() { mkdir -p "${TARGET}/media/cdrom" mountpoint "${TARGET}/media/cdrom" >/dev/null && umount "${TARGET}/media/cdrom" mount -t iso9660 "${vbox_isofile}" "${TARGET}/media/cdrom/" - UTS_RELEASE=$KERNELVERSION LD_PRELOAD=/tmp/fake-uname.so grml-chroot "$TARGET" /media/cdrom/VBoxLinuxAdditions.run --nox11 - tail -10 "${TARGET}/var/log/VBoxGuestAdditions.log" + # avoid "ERROR: ld.so: object '/usr/lib/ngcp-deployment-scripts/fake-uname.so' from LD_PRELOAD cannot be preloaded: ignored." + # messages caused by the host system when running grml-chroot process + mkdir -p /usr/lib/ngcp-deployment-scripts/ + cp /mnt/usr/lib/ngcp-deployment-scripts/fake-uname.so /usr/lib/ngcp-deployment-scripts/ + UTS_RELEASE="${KERNELVERSION}" LD_PRELOAD="/usr/lib/ngcp-deployment-scripts/fake-uname.so" \ + grml-chroot "${TARGET}" /media/cdrom/VBoxLinuxAdditions.run --nox11 + tail -10 "${TARGET}/var/log/vboxadd-install.log" umount "${TARGET}/media/cdrom/" # VBoxLinuxAdditions.run chooses /usr/lib64 as soon as this directory exists, which