We have always had this problem and worked around it by coping code or using inline functions. Both not good IMO. Signed-off-by: Angus Salkeld <asalkeld@xxxxxxxxxx> --- Makefile.am | 2 +- common_lib/Makefile.am | 93 +++++++++++++++++++++++++++++++++++++++++ common_lib/error_conversion.c | 80 +++++++++++++++++++++++++++++++++++ configure.ac | 1 + cts/agents/Makefile.am | 12 +++--- exec/Makefile.am | 6 +- include/corosync/corotypes.h | 77 +--------------------------------- lib/Makefile.am | 2 +- pkgconfig/libtemplate.pc.in | 2 +- test/Makefile.am | 73 ++++++++++++++++---------------- tools/Makefile.am | 27 ++++++------ 11 files changed, 238 insertions(+), 137 deletions(-) create mode 100644 common_lib/Makefile.am create mode 100644 common_lib/error_conversion.c diff --git a/Makefile.am b/Makefile.am index 178b34d..b16eae6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -47,7 +47,7 @@ MAINTAINERCLEANFILES = Makefile.in aclocal.m4 configure depcomp \ dist_doc_DATA = LICENSE INSTALL README.recovery SECURITY TODO AUTHORS -SUBDIRS = include lib exec tools test cts pkgconfig \ +SUBDIRS = include common_lib lib exec tools test cts pkgconfig \ man init conf coverity: diff --git a/common_lib/Makefile.am b/common_lib/Makefile.am new file mode 100644 index 0000000..b1fa62e --- /dev/null +++ b/common_lib/Makefile.am @@ -0,0 +1,93 @@ +# +# Copyright (c) 2009 Red Hat, Inc. +# +# Authors: Angus Salkeld +# +# This software licensed under BSD license, the text of which follows: +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# - Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# - Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# - Neither the name of the MontaVista Software, Inc. nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +# THE POSSIBILITY OF SUCH DAMAGE. + +# Functions +uc=$(shell echo $1 | tr a-z A-Z) +get_soname=$(if $($(call uc,$1)_SONAME),$($(call uc,$1)_SONAME),$(SONAME)) +get_major=$(firstword $(subst ., ,$(call get_soname,$1))) +get_sharedlibs=$(foreach lib,$(SHARED_LIBS_SO:lib%.so=%),lib$(lib).so.$(call get_soname,$(lib))) +get_sharedlibs_two=$(foreach lib,$(SHARED_LIBS_SO:lib%.so=%),lib$(lib).so.$(call get_major,$(lib))) +get_linker_add=$(if $($(call uc,$1)_LINKER_ADD),$($(call uc,$1)_LINKER_ADD)) + +MAINTAINERCLEANFILES = Makefile.in + +AM_CFLAGS = -fPIC + +INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include + +lib_LIBRARIES = libcorosync_common.a +SHARED_LIBS_SO = $(lib_LIBRARIES:%.a=%.so) + +libcorosync_common_a_SOURCES = error_conversion.c + +if BUILD_DARWIN + +lib%.so: lib%.a $(LIBQB_LIBS) + $(CC) $(DARWIN_OPTS) $(call get_linker_add,$*) -Wl,-whole-archive $^ -Wl,-no-whole-archive -o $@ + ln -sf lib$*.so.$(call get_soname,$*) lib$*.so + ln -sf lib$*.so.$(call get_soname,$*) lib$*.so.$(call get_major,$*) + +else + +if BUILD_SOLARIS + +lib%.so.$(SONAME): lib%.a + $(LD) $(SOLARIS_OPTS) $(call get_linker_add,$*) -G -whole-archive $^ -no-whole-archive -o $@ + ln -sf lib$*.so.$(call get_soname,$*) lib$*.so + ln -sf lib$*.so.$(call get_soname,$*) lib$*.so.$(call get_major,$*) + +else + +lib%.so: lib%.a + $(CC) -shared -o $@.$(call get_soname,$*) \ + -Wl,-soname=lib$*.so.$(call get_major,$*) \ + -Wl,-whole-archive $^ -Wl,-no-whole-archive $(LDFLAGS) $(LIBQB_LIBS) $(AM_LDFLAGS) $(call get_linker_add,$*) + ln -sf lib$*.so.$(call get_soname,$*) lib$*.so + ln -sf lib$*.so.$(call get_soname,$*) lib$*.so.$(call get_major,$*) + +endif + +endif + +all-local: $(get_explicit_sharedlibs) $(SHARED_LIBS_SO) + @echo Built shared libs + +install-exec-local: + $(INSTALL) -d $(DESTDIR)/$(libdir) + $(INSTALL) -m 755 $(get_sharedlibs) $(DESTDIR)/$(libdir) + $(CP) -a $(SHARED_LIBS_SO) $(get_sharedlibs_two) $(DESTDIR)/$(libdir) + +uninstall-local: + cd $(DESTDIR)/$(libdir)/ && \ + rm -f $(get_sharedlibs) $(SHARED_LIBS_SO) $(get_sharedlibs_two) + +clean-local: + rm -f *.o *.a *.so* *.da *.bb *.bbg diff --git a/common_lib/error_conversion.c b/common_lib/error_conversion.c new file mode 100644 index 0000000..7b2b6ef --- /dev/null +++ b/common_lib/error_conversion.c @@ -0,0 +1,80 @@ + +#include <corosync/corotypes.h> + +cs_error_t qb_to_cs_error (int result) +{ + int32_t res; + cs_error_t err = CS_ERR_LIBRARY; + + if (result >= 0) { + return CS_OK; + } + res = -result; + + switch (res) { + case EBADF: + err = CS_ERR_BAD_HANDLE; + break; + case ENOMEM: + err = CS_ERR_NO_MEMORY; + break; + case ETIMEDOUT: + case EAGAIN: + err = CS_ERR_TRY_AGAIN; + break; + case EBADE: + err = CS_ERR_FAILED_OPERATION; + break; + case ETIME: + err = CS_ERR_TIMEOUT; + break; + case EINVAL: + err = CS_ERR_INVALID_PARAM; + break; + case EBUSY: + err = CS_ERR_BUSY; + break; + case EACCES: + err = CS_ERR_ACCESS; + break; + case EOVERFLOW: + err = CS_ERR_NAME_TOO_LONG; + break; + case EEXIST: + err = CS_ERR_EXIST; + break; + case ENOBUFS: + err = CS_ERR_QUEUE_FULL; + break; + case ENOSPC: + err = CS_ERR_NO_SPACE; + break; + case EINTR: + err = CS_ERR_INTERRUPT; + break; + case ENOENT: + case ENODEV: + err = CS_ERR_NOT_EXIST; + break; + case ENOSYS: + case ENOTSUP: + err = CS_ERR_NOT_SUPPORTED; + break; + case EBADMSG: + err = CS_ERR_MESSAGE_ERROR; + break; + case EMSGSIZE: + case E2BIG: + err = CS_ERR_TOO_BIG; + break; + case ECONNREFUSED: + case ENOTCONN: + default: + err = CS_ERR_LIBRARY; + break; + } + + return err; +} + + diff --git a/configure.ac b/configure.ac index d03c91b..65abfae 100644 --- a/configure.ac +++ b/configure.ac @@ -131,6 +131,7 @@ AC_CONFIG_FILES([Makefile include/Makefile init/Makefile lib/Makefile + common_lib/Makefile man/Makefile pkgconfig/Makefile test/Makefile diff --git a/cts/agents/Makefile.am b/cts/agents/Makefile.am index 5848b02..d9aaa84 100644 --- a/cts/agents/Makefile.am +++ b/cts/agents/Makefile.am @@ -49,16 +49,16 @@ endif noinst_HEADERS = common_test_agent.h cpg_test_agent_SOURCES = cpg_test_agent.c common_test_agent.c -cpg_test_agent_LDADD = -lcpg -lcfg ../../exec/crypto.o $(LIBQB_LIBS) -cpg_test_agent_LDFLAGS = -L../../lib -L. +cpg_test_agent_LDADD = -lcpg -lcfg ../../exec/crypto.o -lcorosync_common $(LIBQB_LIBS) +cpg_test_agent_LDFLAGS = -L../../lib -L. -L../../common_lib sam_test_agent_SOURCES = sam_test_agent.c common_test_agent.c -sam_test_agent_LDADD = -lsam -lquorum -lcmap $(LIBQB_LIBS) -sam_test_agent_LDFLAGS = -L../../lib +sam_test_agent_LDADD = -lsam -lquorum -lcmap -lcorosync_common $(LIBQB_LIBS) +sam_test_agent_LDFLAGS = -L../../lib -L../../common_lib votequorum_test_agent_SOURCES = votequorum_test_agent.c common_test_agent.c -votequorum_test_agent_LDADD = -lvotequorum -lquorum $(LIBQB_LIBS) -votequorum_test_agent_LDFLAGS = -L../../lib +votequorum_test_agent_LDADD = -lvotequorum -lquorum -lcorosync_common $(LIBQB_LIBS) +votequorum_test_agent_LDFLAGS = -L../../lib -L../../common_lib clean-local: rm -f *.o *.a *.so* *.da *.bb *.bbg diff --git a/exec/Makefile.am b/exec/Makefile.am index 3b6f201..07a77c5 100644 --- a/exec/Makefile.am +++ b/exec/Makefile.am @@ -52,9 +52,9 @@ corosync_SOURCES = evil.c vsf_ykd.c coroparse.c vsf_quorum.c syncv2.c \ votequorum.c wd.c util.c schedwrk.c main.c \ apidef.c quorum.c sync.c icmap.c timer.c \ ipc_glue.c service.c mainconfig.c totemconfig.c -corosync_LDADD = -ltotem_pg $(LIBQB_LIBS) $(statgrab_LIBS) -corosync_DEPENDENCIES = libtotem_pg.so.$(SONAME) -corosync_LDFLAGS = $(OS_DYFLAGS) -L./ +corosync_LDADD = -ltotem_pg -lcorosync_common $(LIBQB_LIBS) $(statgrab_LIBS) +corosync_DEPENDENCIES = libtotem_pg.so.$(SONAME) ../common_lib/libcorosync_common.so +corosync_LDFLAGS = $(OS_DYFLAGS) -L./ -L../common_lib TOTEM_OBJS = $(TOTEM_SRC:%.c=%.o) LOGSYS_OBJS = $(LOGSYS_SRC:%.c=%.o) diff --git a/include/corosync/corotypes.h b/include/corosync/corotypes.h index c67bf29..dcd78f3 100644 --- a/include/corosync/corotypes.h +++ b/include/corosync/corotypes.h @@ -134,82 +134,7 @@ static inline uint64_t cs_timestamp_get(void) return result; } -static inline cs_error_t qb_to_cs_error (int result) -{ - int32_t res; - cs_error_t err = CS_ERR_LIBRARY; - - if (result >= 0) { - return CS_OK; - } - res = -result; - - switch (res) { - case EBADF: - err = CS_ERR_BAD_HANDLE; - break; - case ENOMEM: - err = CS_ERR_NO_MEMORY; - break; - case ETIMEDOUT: - case EAGAIN: - err = CS_ERR_TRY_AGAIN; - break; - case EBADE: - err = CS_ERR_FAILED_OPERATION; - break; - case ETIME: - err = CS_ERR_TIMEOUT; - break; - case EINVAL: - err = CS_ERR_INVALID_PARAM; - break; - case EBUSY: - err = CS_ERR_BUSY; - break; - case EACCES: - err = CS_ERR_ACCESS; - break; - case EOVERFLOW: - err = CS_ERR_NAME_TOO_LONG; - break; - case EEXIST: - err = CS_ERR_EXIST; - break; - case ENOBUFS: - err = CS_ERR_QUEUE_FULL; - break; - case ENOSPC: - err = CS_ERR_NO_SPACE; - break; - case EINTR: - err = CS_ERR_INTERRUPT; - break; - case ENOENT: - case ENODEV: - err = CS_ERR_NOT_EXIST; - break; - case ENOSYS: - case ENOTSUP: - err = CS_ERR_NOT_SUPPORTED; - break; - case EBADMSG: - err = CS_ERR_MESSAGE_ERROR; - break; - case EMSGSIZE: - case E2BIG: - err = CS_ERR_TOO_BIG; - break; - case ECONNREFUSED: - case ENOTCONN: - default: - err = CS_ERR_LIBRARY; - break; - } - - return err; -} - +cs_error_t qb_to_cs_error (int result); /* * DEPRECATED diff --git a/lib/Makefile.am b/lib/Makefile.am index d2dd8ed..6ded330 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -42,7 +42,7 @@ MAINTAINERCLEANFILES = Makefile.in AM_CFLAGS = -fPIC -AM_LDFLAGS = -lpthread +AM_LDFLAGS = -lpthread -L../common_lib -lcorosync_common INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include diff --git a/pkgconfig/libtemplate.pc.in b/pkgconfig/libtemplate.pc.in index 4a8a7e0..967adf9 100644 --- a/pkgconfig/libtemplate.pc.in +++ b/pkgconfig/libtemplate.pc.in @@ -7,5 +7,5 @@ Name: @LIB@ Version: @LIBVERSION@ Description: @LIB@ Requires: -Libs: -L${libdir} -l@LIB@ +Libs: -L${libdir} -l@LIB@ -lcorosync_common Cflags: -I${includedir} diff --git a/test/Makefile.am b/test/Makefile.am index 178e711..93475b1 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -38,42 +38,43 @@ noinst_PROGRAMS = testevs evsbench evsverify cpgverify testcpg testcpg2 cpgbenc stress_cpgfdget stress_cpgcontext cpgbound testsam \ testcpgzc cpgbenchzc testzcgc stress_cpgzc -testevs_LDADD = -levs $(LIBQB_LIBS) -testevs_LDFLAGS = -L../lib -testcpg_LDADD = -lcpg $(LIBQB_LIBS) -testcpg_LDFLAGS = -L../lib -testcpg2_LDADD = -lcpg $(LIBQB_LIBS) -testcpg2_LDFLAGS = -L../lib -testcpgzc_LDADD = -lcpg $(LIBQB_LIBS) -testcpgzc_LDFLAGS = -L../lib -testzcgc_LDADD = -lcpg $(LIBQB_LIBS) -testzcgc_LDFLAGS = -L../lib -stress_cpgzc_LDADD = -lcpg $(LIBQB_LIBS) -stress_cpgzc_LDFLAGS = -L../lib -stress_cpgfdget_LDADD = -lcpg $(LIBQB_LIBS) -stress_cpgfdget_LDFLAGS = -L../lib -stress_cpgcontext_LDADD = -lcpg $(LIBQB_LIBS) -stress_cpgcontext_LDFLAGS = -L../lib -testquorum_LDADD = -lquorum $(LIBQB_LIBS) -testquorum_LDFLAGS = -L../lib -testvotequorum1_LDADD = -lvotequorum $(LIBQB_LIBS) -testvotequorum1_LDFLAGS = -L../lib -testvotequorum2_LDADD = -lvotequorum $(LIBQB_LIBS) -testvotequorum2_LDFLAGS = -L../lib -evsverify_LDADD = -levs -ltotem_pg $(LIBQB_LIBS) -evsverify_LDFLAGS = -L../lib -L../exec -cpgverify_LDADD = -lcpg -ltotem_pg $(LIBQB_LIBS) -cpgverify_LDFLAGS = -L../lib -L../exec -cpgbound_LDADD = -lcpg $(LIBQB_LIBS) -cpgbound_LDFLAGS = -L../lib -evsbench_LDADD = -levs $(LIBQB_LIBS) -evsbench_LDFLAGS = -L../lib -cpgbench_LDADD = -lcpg $(LIBQB_LIBS) -cpgbench_LDFLAGS = -L../lib -cpgbenchzc_LDADD = -lcpg $(LIBQB_LIBS) -cpgbenchzc_LDFLAGS = -L../lib -testsam_LDADD = -lsam -lcmap -lquorum $(LIBQB_LIBS) -testsam_LDFLAGS = -L../lib + +testevs_LDADD = -levs -lcorosync_common $(LIBQB_LIBS) +testevs_LDFLAGS = -L../lib -L../common_lib +testcpg_LDADD = -lcpg -lcorosync_common $(LIBQB_LIBS) +testcpg_LDFLAGS = -L../lib -L../common_lib +testcpg2_LDADD = -lcpg -lcorosync_common $(LIBQB_LIBS) +testcpg2_LDFLAGS = -L../lib -L../common_lib +testcpgzc_LDADD = -lcpg -lcorosync_common $(LIBQB_LIBS) +testcpgzc_LDFLAGS = -L../lib -L../common_lib +testzcgc_LDADD = -lcpg -lcorosync_common $(LIBQB_LIBS) +testzcgc_LDFLAGS = -L../lib -L../common_lib +stress_cpgzc_LDADD = -lcpg -lcorosync_common $(LIBQB_LIBS) +stress_cpgzc_LDFLAGS = -L../lib -L../common_lib +stress_cpgfdget_LDADD = -lcpg -lcorosync_common $(LIBQB_LIBS) +stress_cpgfdget_LDFLAGS = -L../lib -L../common_lib +stress_cpgcontext_LDADD = -lcpg -lcorosync_common $(LIBQB_LIBS) +stress_cpgcontext_LDFLAGS = -L../lib -L../common_lib +testquorum_LDADD = -lquorum -lcorosync_common $(LIBQB_LIBS) +testquorum_LDFLAGS = -L../lib -L../common_lib +testvotequorum1_LDADD = -lvotequorum -lcorosync_common $(LIBQB_LIBS) +testvotequorum1_LDFLAGS = -L../lib -L../common_lib +testvotequorum2_LDADD = -lvotequorum -lcorosync_common $(LIBQB_LIBS) +testvotequorum2_LDFLAGS = -L../lib -L../common_lib +evsverify_LDADD = -levs -ltotem_pg -lcorosync_common $(LIBQB_LIBS) +evsverify_LDFLAGS = -L../lib -L../exec -L../common_lib +cpgverify_LDADD = -lcpg -ltotem_pg -lcorosync_common $(LIBQB_LIBS) +cpgverify_LDFLAGS = -L../lib -L../exec -L../common_lib +cpgbound_LDADD = -lcpg -lcorosync_common $(LIBQB_LIBS) +cpgbound_LDFLAGS = -L../lib -L../common_lib +evsbench_LDADD = -levs -lcorosync_common $(LIBQB_LIBS) +evsbench_LDFLAGS = -L../lib -L../common_lib +cpgbench_LDADD = -lcpg -lcorosync_common $(LIBQB_LIBS) +cpgbench_LDFLAGS = -L../lib -L../common_lib +cpgbenchzc_LDADD = -lcpg -lcorosync_common $(LIBQB_LIBS) +cpgbenchzc_LDFLAGS = -L../lib -L../common_lib +testsam_LDADD = -lsam -lcmap -lquorum -lcorosync_common $(LIBQB_LIBS) +testsam_LDFLAGS = -L../lib -L../common_lib LINT_FILES1:=$(filter-out sa_error.c, $(wildcard *.c)) LINT_FILES2:=$(filter-out testevsth.c, $(LINT_FILES1)) diff --git a/tools/Makefile.am b/tools/Makefile.am index 921cd26..a5d10f7 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -49,23 +49,24 @@ corosync-xmlproc: corosync-xmlproc.sh EXTRA_DIST = $(bin_SCRIPTS) corosync-xmlproc.sh corosync-notifyd.sysconfig.example -corosync_fplay_LDADD = $(LIBQB_LIBS) -corosync_pload_LDADD = -lpload $(LIBQB_LIBS) -corosync_pload_LDFLAGS = -L../lib -corosync_cmapctl_LDADD = -lcmap $(LIBQB_LIBS) -corosync_cmapctl_LDFLAGS= -L../lib -corosync_cfgtool_LDADD = -lcfg $(LIBQB_LIBS) -corosync_cfgtool_LDFLAGS= -L../lib -corosync_cpgtool_LDADD = -lcfg -lcpg $(LIBQB_LIBS) -corosync_cpgtool_LDFLAGS= -L../lib -corosync_quorumtool_LDADD = -lcmap -lcfg -lquorum \ +corosync_fplay_LDADD = -lcorosync_common $(LIBQB_LIBS) +corosync_fplay_LDFLAGS = -L../common_lib +corosync_pload_LDADD = -lcorosync_common -lpload $(LIBQB_LIBS) +corosync_pload_LDFLAGS = -L../lib -L../common_lib +corosync_cmapctl_LDADD = -lcorosync_common -lcmap $(LIBQB_LIBS) +corosync_cmapctl_LDFLAGS= -L../lib -L../common_lib +corosync_cfgtool_LDADD = -lcorosync_common -lcfg $(LIBQB_LIBS) +corosync_cfgtool_LDFLAGS= -L../lib -L../common_lib +corosync_cpgtool_LDADD = -lcorosync_common -lcfg -lcpg $(LIBQB_LIBS) +corosync_cpgtool_LDFLAGS= -L../lib -L../common_lib +corosync_quorumtool_LDADD = -lcorosync_common -lcmap -lcfg -lquorum \ -lvotequorum $(LIBQB_LIBS) -corosync_quorumtool_LDFLAGS = -L../lib +corosync_quorumtool_LDFLAGS = -L../lib -L../common_lib -corosync_notifyd_LDADD = -lcfg -lcmap \ +corosync_notifyd_LDADD = -lcorosync_common -lcfg -lcmap \ $(LIBQB_LIBS) $(DBUS_LIBS) $(SNMPLIBS) \ -lquorum -corosync_notifyd_LDFLAGS = -L../lib +corosync_notifyd_LDFLAGS = -L../lib -L../common_lib corosync_notifyd_CPPFLAGS = $(DBUS_CFLAGS) -- 1.7.7.6 _______________________________________________ discuss mailing list discuss@xxxxxxxxxxxx http://lists.corosync.org/mailman/listinfo/discuss