[lxc-devel] [lxcfs/master] 2016 02 08/privlib

hallyn on Github lxc-bot at linuxcontainers.org
Mon Feb 8 18:11:27 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 345 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160208/f3ebb56d/attachment.bin>
-------------- next part --------------
From 2e7cd2944856568dc1d8f2c8a721003516c75e36 Mon Sep 17 00:00:00 2001
From: Serge Hallyn <serge.hallyn at ubuntu.com>
Date: Mon, 8 Feb 2016 09:23:38 -0800
Subject: [PATCH 1/4] Makefile: make testlib build optional, and drop the
 soname

Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
---
 Makefile.am | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 734fa3b..855c61c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3,10 +3,6 @@ ACLOCAL_AMFLAGS = -I m4
 SUBDIRS = tests share
 DIST_SUBDIRS = tests share
 
-VERSION_CURRENT  = 0
-VERSION_REVISION = 0
-VERSION_AGE      = 0
-
 AM_CFLAGS = -Wall -ggdb -D_GNU_SOURCE -DSBINDIR=\"$(SBINDIR)\" -pthread
 AM_CFLAGS += $(FUSE_CFLAGS)
 AM_LDFLAGS = $(FUSE_LIBS) -pthread
@@ -16,18 +12,17 @@ AM_CFLAGS += -DRUNTIME_PATH=\"$(RUNTIME_PATH)\"
 
 liblxcfs_la_SOURCES = bindings.c cpuset.c bindings.h
 liblxcfs_la_CFLAGS = $(AM_CFLAGS)
-liblxcfs_la_LDFLAGS = $(AM_CFLAGS) -shared \
-	-Wl,-soname,liblxcfs.so.$(firstword $(subst ., , at LXCFS_VERSION_ABI@))
+liblxcfs_la_LDFLAGS = $(AM_CFLAGS) -shared
 
 liblxcfstest_la_SOURCES = bindings.c cpuset.c bindings.h
 liblxcfstest_la_CFLAGS = $(AM_CFLAGS) -DRELOADTEST
-liblxcfstest_la_LDFLAGS = $(AM_CFLAGS) -shared \
-	-Wl,-soname,liblxcfs.so.$(firstword $(subst ., , at LXCFS_VERSION_ABI@))
+liblxcfstest_la_LDFLAGS = $(AM_CFLAGS) -shared
 
 noinst_HEADERS = bindings.h
 
 sodir=$(libdir)
-lib_LTLIBRARIES = liblxcfs.la liblxcfstest.la
+lib_LTLIBRARIES = liblxcfs.la
+EXTRA_LTLIBRARIES = liblxcfstest.la
 
 lxcfs_SOURCES = lxcfs.c
 lxcfs_LDADD = liblxcfs.la -ldl

From c59347295b3ab7eedf3f2f5ebf3a205566564ba8 Mon Sep 17 00:00:00 2001
From: Serge Hallyn <serge.hallyn at ubuntu.com>
Date: Mon, 8 Feb 2016 09:36:18 -0800
Subject: [PATCH 2/4] Look for liblxcfs under LIBDIR/lxcfs

If LXCFS_TESTSUITE environment variable is set, always
use relative path so we can specify the location with LD_LIBRARY_PATH.

If LIBDIR/lxcfs/liblxcfs.so does not exist, fall back to relative
path so that 'make; ./lxcfs' still works.

Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
---
 Makefile.am |  1 +
 lxcfs.c     | 23 +++++++++++++++++------
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 855c61c..017b812 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -5,6 +5,7 @@ DIST_SUBDIRS = tests share
 
 AM_CFLAGS = -Wall -ggdb -D_GNU_SOURCE -DSBINDIR=\"$(SBINDIR)\" -pthread
 AM_CFLAGS += $(FUSE_CFLAGS)
+AM_CFLAGS += -DLIBDIR=\"$(LIBDIR)\"
 AM_LDFLAGS = $(FUSE_LIBS) -pthread
 #AM_CFLAGS += -DDEBUG
 
diff --git a/lxcfs.c b/lxcfs.c
index 1d1016c..1332fc7 100644
--- a/lxcfs.c
+++ b/lxcfs.c
@@ -68,6 +68,7 @@ static void users_unlock(void)
 }
 
 static int need_reload;
+
 /* do_reload - reload the dynamic library.  Done under
  * lock and when we know the user_count was 0 */
 static void do_reload(void)
@@ -75,13 +76,27 @@ static void do_reload(void)
 	if (dlopen_handle)
 		dlclose(dlopen_handle);
 
+	/* Testsuite never wants to use /usr/lib/lxcfs/liblxcfs.so */
+	if (getenv("LXCFS_TESTSUITE") != NULL)
+		goto relpath;
+
+	/* First try to load from /usr/lib/lxcfs/liblxcfs.so */
+	dlopen_handle = dlopen(LIBDIR "lxcfs/liblxcfs.so", RTLD_LAZY);
+	if (dlopen_handle)
+		goto good;
+
+relpath:
+	/* Fall back to looking under LD_LIBRARY_PATH */
 	dlopen_handle = dlopen("liblxcfs.so", RTLD_LAZY);
 	if (!dlopen_handle) {
 		fprintf(stderr, "Failed to open liblxcfs\n");
 		_exit(1);
 	}
+
+good:
+	if (need_reload)
+		fprintf(stderr, "lxcfs: reloaded\n");
 	need_reload = 0;
-	fprintf(stderr, "lxcfs: reloaded\n");
 }
 
 static void up_users(void)
@@ -904,11 +919,7 @@ int main(int argc, char *argv[])
 	if (argc != 2 || is_help(argv[1]))
 		usage(argv[0]);
 
-	dlopen_handle = dlopen("liblxcfs.so", RTLD_LAZY);
-	if (!dlopen_handle) {
-		fprintf(stderr, "Failed to open liblxcfs\n");
-		exit(1);
-	}
+	do_reload();
 	signal(SIGUSR1, reload_handler);
 
 	newargv[cnt++] = argv[0];

From ea58dd6c6315567f2de538a7e7fa5c4fc31897c2 Mon Sep 17 00:00:00 2001
From: Serge Hallyn <serge.hallyn at ubuntu.com>
Date: Mon, 8 Feb 2016 09:39:21 -0800
Subject: [PATCH 3/4] test_reload: actually time out

Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
---
 tests/test_reload.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tests/test_reload.sh b/tests/test_reload.sh
index 4560ba2..fc05ea0 100755
--- a/tests/test_reload.sh
+++ b/tests/test_reload.sh
@@ -46,6 +46,7 @@ count=1
 while [ ! -d ${testdir}/proc ]; do
   [ $count -lt 5 ]
   sleep 1
+  count=$((count+1))
 done
 
 rm -f iwashere

From ebfc237cb1a66753c1b3eb8b201b5a9409ea2ecb Mon Sep 17 00:00:00 2001
From: Serge Hallyn <serge.hallyn at ubuntu.com>
Date: Mon, 8 Feb 2016 09:59:26 -0800
Subject: [PATCH 4/4] testsuite: handle liblxcfs changes

Export LXCFS_TESTSUITE so that lxcfs will use relative path to load
liblxcfs.  And have test_reload.sh build liblxcfstest by hand since it
is no longer automatically built.

Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
---
 tests/main.sh        |  2 ++
 tests/test_reload.sh | 11 +++++++++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/tests/main.sh b/tests/main.sh
index 01a900b..54ad055 100755
--- a/tests/main.sh
+++ b/tests/main.sh
@@ -4,6 +4,8 @@ set -ex
 
 [ $(id -u) -eq 0 ]
 
+export LXCFS_TESTSUITE=1
+
 # Run lxcfs testsuite
 export LXCFSDIR=$(mktemp -d)
 pidfile=$(mktemp)
diff --git a/tests/test_reload.sh b/tests/test_reload.sh
index fc05ea0..ae8217b 100755
--- a/tests/test_reload.sh
+++ b/tests/test_reload.sh
@@ -39,8 +39,10 @@ trap cleanup EXIT SIGHUP SIGINT SIGTERM
 
 ( cd ${topdir}; DESTDIR=${installdir} make install )
 export LD_LIBRARY_PATH=${libdir}
+export LXCFS_TESTSUITE=1
 
 ${bindir}/lxcfs -p ${pidfile} ${testdir} &
+
 lxcfspid=$!
 count=1
 while [ ! -d ${testdir}/proc ]; do
@@ -52,9 +54,14 @@ done
 rm -f iwashere
 cat ${testdir}/proc/uptime
 [ ! -f iwashere ]
+(
+  cd ${topdir};
+  make liblxcfstest.la
+  gcc -shared -fPIC -DPIC .libs/liblxcfstest_la-bindings.o .libs/liblxcfstest_la-cpuset.o -lpthread -pthread -o .libs/liblxcfstest.so
+  cp .libs/liblxcfstest.* "${libdir}"
+)
 rm -f ${libdir}/liblxcfs.so* ${libdir}/liblxcfs.la
-ln -s liblxcfstest.so.0.0.0 ${libdir}/liblxcfs.so
-cp ${libdir}/liblxcfstest.la ${libdir}/liblxcfs.la
+cp ${libdir}/liblxcfstest.so ${libdir}/liblxcfs.so
 
 kill -USR1 ${lxcfspid}
 


More information about the lxc-devel mailing list