diff --git a/Makefile b/Makefile index 6c9ffeb6..f36cfdef 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,39 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF # THE POSSIBILITY OF SUCH DAMAGE. +DESTDIR=/usr/local +ifeq "$(DESTDIR)" "/usr/local" +SBINDIR=${DESTDIR}/usr/sbin +INCLUDEDIR=${DESTDIR}/usr/include/openais +INCLUDEDIR_TOTEM=${DESTDIR}/usr/include/openais/totem +MANDIR=/usr/share/man +else +SBINDIR=${DESTDIR}/sbin +INCLUDEDIR=${DESTDIR}/include/openais +INCLUDEDIR_TOTEM=${DESTDIR}/include/openais/totem +MANDIR=$(DESTDIR)/man +endif +ETCDIR=/etc + +ifeq "$(DESTDIR)" "/" +ifeq "" "$(findstring 64,$(ARCH))" +LIBDIR=${DESTDIR}/usr/lib64/openais +LCRSODIR=$(DESTDIR)/usr/lib64/openais/lcrso +else +LIBDIR=${DESTDIR}/usr/lib/openais +LCRSODIR=$(DESTDIR)/usr/lib/openais/lcrso +endif +else +ifeq "" "$(findstring 64,$(ARCH))" +LIBDIR=${DESTDIR}/lib64/openais +LCRSODIR=$(DESTDIR)/lib64/openais/lcrso +else +LIBDIR=${DESTDIR}/lib/openais +LCRSODIR=$(DESTDIR)/lib/openais/lcrso +endif +endif + + all: (cd lcr; echo ==== `pwd` ===; $(MAKE) all); (cd lib; echo ==== `pwd` ===; $(MAKE) all); @@ -41,30 +74,43 @@ clean: (cd test; echo ==== `pwd` ===; $(MAKE) clean); install: - mkdir -p $(DESTDIR)/sbin - mkdir -p $(DESTDIR)/usr/include - mkdir -p $(DESTDIR)/usr/lib - mkdir -p $(DESTDIR)/etc/ais + mkdir -p $(SBINDIR) + mkdir -p $(INCLUDEDIR) + mkdir -p $(INCLUDEDIR_TOTEM) + mkdir -p $(LIBDIR) + mkdir -p $(LCRSODIR) + mkdir -p $(ETCDIR) + mkdir -p /etc/ld.so.conf.d - cp lib/libais.a $(DESTDIR)/usr/lib - cp lib/libais.so* $(DESTDIR)/usr/lib - cp lib/libSa*.a $(DESTDIR)/usr/lib - cp lib/libSa*.so* $(DESTDIR)/usr/lib - cp lib/libevs.a $(DESTDIR)/usr/lib - cp lib/libevs.so* $(DESTDIR)/usr/lib - cp lib/libcpg.a $(DESTDIR)/usr/lib - cp lib/libcpg.so* $(DESTDIR)/usr/lib - cp exec/libtotem_pg* $(DESTDIR)/usr/lib + install -m 755 lib/libais.a $(LIBDIR) + install -m 755 lib/libais.so* $(LIBDIR) + install -m 755 lib/libSa*.a $(LIBDIR) + install -m 755 lib/libSa*.so* $(LIBDIR) + install -m 755 lib/libevs.a $(LIBDIR) + install -m 755 lib/libevs.so* $(LIBDIR) + install -m 755 lib/libcpg.a $(LIBDIR) + install -m 755 lib/libcpg.so* $(LIBDIR) + echo $(LIBDIR) > /etc/ld.so.conf.d/"openais-`uname -p`.conf" + echo $(LCRSODIR) >> /etc/ld.so.conf.d/"openais-`uname -p`.conf" - install -m 755 exec/aisexec $(DESTDIR)/sbin - install -m 755 exec/keygen $(DESTDIR)/sbin/ais-keygen - install -m 755 conf/openais.conf $(DESTDIR)/etc - install -m 755 conf/groups.conf $(DESTDIR)/etc + cp exec/libtotem_pg* $(LIBDIR) + cp exec/*lcrso $(LCRSODIR) - cp include/saAis.h $(DESTDIR)/usr/include - cp include/ais_amf.h $(DESTDIR)/usr/include - cp include/saClm.h $(DESTDIR)/usr/include - cp include/saCkpt.h $(DESTDIR)/usr/include - cp include/saEvt.h $(DESTDIR)/usr/include - cp include/evs.h $(DESTDIR)/usr/include - cp exec/totem.h $(DESTDIR)/usr/include + install -m 755 exec/aisexec $(SBINDIR) + install -m 755 exec/keygen $(SBINDIR)/ais-keygen + install -m 755 conf/openais.conf $(ETCDIR) + install -m 755 conf/groups.conf $(ETCDIR) + + install -m 644 include/saAis.h $(INCLUDEDIR) + install -m 644 include/saAmf.h $(INCLUDEDIR) + install -m 644 include/saClm.h $(INCLUDEDIR) + install -m 644 include/saCkpt.h $(INCLUDEDIR) + install -m 644 include/saEvt.h $(INCLUDEDIR) + install -m 644 include/saEvt.h $(INCLUDEDIR) + install -m 644 include/saLck.h $(INCLUDEDIR) + install -m 644 include/saMsg.h $(INCLUDEDIR) + install -m 644 include/cpg.h $(INCLUDEDIR) + install -m 644 include/evs.h $(INCLUDEDIR) + install -m 644 exec/totem.h $(INCLUDEDIR_TOTEM) + install -m 644 exec/totemip.h $(INCLUDEDIR_TOTEM) + /sbin/ldconfig diff --git a/exec/Makefile b/exec/Makefile index f0e8e397..4134f910 100644 --- a/exec/Makefile +++ b/exec/Makefile @@ -168,17 +168,11 @@ ifeq (${OPENAIS_COMPAT}, DARWIN) libtotem_pg.so.1.0: $(TOTEM_OBJS) $(CC) $(LDFLAGS) -bundle -bind_at_load $(TOTEM_OBJS) -o $@ - rm -f libtotem_pg.so.1 libtotem_pg.so - ln -s libtotem_pg.so.1.0 libtotem_pg.so.1 - ln -s libtotem_pg.so.1.0 libtotem_pg.so else libtotem_pg.so.1.0: $(TOTEM_OBJS) $(CC) $(LDFLAGS) -shared -Wl,-soname,libtotem_pg.so.1 $(TOTEM_OBJS) -o $@ - rm -f libtotem_pg.so.1 libtotem_pg.so - ln -s libtotem_pg.so.1.0 libtotem_pg.so.1 - ln -s libtotem_pg.so.1.0 libtotem_pg.so endif diff --git a/lcr/Makefile b/lcr/Makefile index ef4fc742..3ae4aaa6 100755 --- a/lcr/Makefile +++ b/lcr/Makefile @@ -33,7 +33,7 @@ ifeq (${OPENAIS_COMPAT}, LINUX) LDFLAGS += -ldl endif -all:liblcr.a test test_static uic libtest_a.lcrso libtest_b.lcrso +all:liblcr.a test test2 test_static uic libtest_a.lcrso libtest_b.lcrso liblcr.a: lcr_ifact.o $(AR) -rc liblcr.a lcr_ifact.o @@ -58,6 +58,9 @@ endif test: test.o uis.o lcr_ifact.o $(CC) $(LDFLAGS) test.o lcr_ifact.o uis.o -lpthread -o test + +test2: test2.o uis.o lcr_ifact.o + $(CC) $(LDFLAGS) test2.o lcr_ifact.o uis.o -lpthread -o test2 test_static: test.o libtest_a.o libtest_b.o uis.o lcr_ifact.o $(CC) $(LDFLAGS) test.o libtest_a.o libtest_b.o lcr_ifact.o -o test_static diff --git a/lcr/lcr_ifact.c b/lcr/lcr_ifact.c index 6624efa7..e450ac03 100644 --- a/lcr/lcr_ifact.c +++ b/lcr/lcr_ifact.c @@ -33,6 +33,7 @@ #include #include #include +#include #include "lcr_comp.h" #include "lcr_ifact.h" #include "../include/hdb.h" @@ -83,6 +84,19 @@ static int lcr_select_so (struct dirent *dirent) return (0); } +#ifdef OPENAIS_LINUX +static int pathlist_select (const struct dirent *dirent) +#else +static int pathlist_select (struct dirent *dirent) +#endif +{ + if (fnmatch ("*.conf", dirent->d_name, 0) == 0) { + return (1); + } + + return (0); +} + static inline struct lcr_component_instance *lcr_comp_find ( char *iface_name, unsigned int version, @@ -142,39 +156,121 @@ static inline int lcr_lib_loaded ( return (0); } -int lcr_ifact_reference ( - unsigned int *iface_handle, - char *iface_name, - int version, - void **iface, - void *context) +unsigned char *path_list[128]; +unsigned int path_list_entries = 0; + +static void defaults_path_build (void) { - void *dl_handle; - struct lcr_iface_instance *iface_instance; - struct lcr_component_instance *instance; - int iface_number; - struct dirent **scandir_list; - int scandir_entries; - unsigned int libs_to_scan; - char cwd[512]; - char dl_name[1024]; + char cwd[1024]; getcwd (cwd, sizeof (cwd)); strcat (cwd, "/"); - /* - * Determine if the component is already loaded - */ - instance = lcr_comp_find (iface_name, version, &iface_number); - if (instance) { - goto found; + path_list[0] = strdup (cwd); + path_list[1] = "/lib"; + path_list[2] = "/usr/lib"; + path_list[3] = "/lib64"; + path_list[4] = "/usr/lib64"; + path_list_entries = 5; +} + +static void ld_library_path_build (void) +{ + char *ld_library_path; + char *my_ld_library_path; + char *p_s; + unsigned int i; + unsigned int len; + + ld_library_path = getenv ("LD_LIBRARY_PATH"); + if (ld_library_path == NULL) { + return; + } + my_ld_library_path = strdup (ld_library_path); + if (my_ld_library_path == 0) { + return; } -// TODO error checking in this code is weak - /* - * Find all *.lcrso files in the cwd - */ - scandir_entries = scandir(".", &scandir_list, lcr_select_so, alphasort); + len = strlen (my_ld_library_path) + 1; + + for (i = 0, p_s = my_ld_library_path, i = 0; i < len; i++) { + if (my_ld_library_path[i] == ':' || my_ld_library_path[i] == '\0') { + my_ld_library_path[i]='\0'; + path_list[path_list_entries++] = strdup (p_s); + p_s = &my_ld_library_path[i]; + } + } + + free (ld_library_path); +} + +static int ldso_path_build (char *path, char *filename) +{ + FILE *fp; + char string[1024]; + char filename_cat[1024]; + char *newpath; + char newpath_cat[1024]; + char *new_filename; + int j; + struct dirent **scandir_list; + unsigned int scandir_entries; + + sprintf (filename_cat, "%s/%s", path, filename); + if (filename[0] == '*') { + scandir_entries = scandir ( + path, + &scandir_list, + pathlist_select, alphasort); + for (j = 0; j < scandir_entries; j++) { + ldso_path_build (path, scandir_list[j]->d_name); + } + } + + fp = fopen (filename_cat, "r"); + if (fp == NULL) { + return (-1); + } + + while (fgets (string, sizeof (string), fp)) { + string[strlen(string) - 1] = '\0'; + if (strncmp (string, "include", strlen ("include")) == 0) { + newpath = string + strlen ("include") + 1; + for (j = strlen (string); + string[j] != ' ' && + string[j] != '/' && + j > 0; + j--) { + } + string[j] = '\0'; + new_filename = &string[j] + 1; + if ((string[strlen ("include ") + 1]) != '/') { + sprintf (newpath_cat, "%s/%s", path, newpath); + newpath = newpath_cat; + } + ldso_path_build (newpath, new_filename); + continue; + } + path_list[path_list_entries++] = strdup (string); + } + return (0); +} + +static int interface_find_and_load ( + char *path, + char *iface_name, + int version, + struct lcr_component_instance **instance_ret, + unsigned int *iface_number) +{ + struct lcr_component_instance *instance; + void *dl_handle; + struct dirent **scandir_list; + int scandir_entries; + unsigned int libs_to_scan; + char dl_name[1024]; + + scandir_entries = scandir (path, &scandir_list, lcr_select_so, alphasort); if (scandir_entries < 0) printf ("scandir error reason=%s\n", strerror (errno)); else @@ -185,19 +281,18 @@ int lcr_ifact_reference ( /* * Load objects, scan them, unload them if they are not a match */ - sprintf (dl_name, "%s%s", cwd, scandir_list[libs_to_scan]->d_name); + sprintf (dl_name, "%s/%s", path, scandir_list[libs_to_scan]->d_name); /* * Don't reload already loaded libraries */ if (lcr_lib_loaded (dl_name)) { continue; } - dl_handle = dlopen (dl_name, RTLD_NOW); + dl_handle = dlopen (dl_name, RTLD_LAZY); if (dl_handle == NULL) { - printf ("Error loading interface %s reason=%s\n", dl_name, dlerror()); - return (-1); + continue; } - instance = lcr_comp_find (iface_name, version, &iface_number); + instance = lcr_comp_find (iface_name, version, iface_number); if (instance) { instance->dl_handle = dl_handle; strcpy (instance->library_name, dl_name); @@ -214,12 +309,64 @@ int lcr_ifact_reference ( } dlclose (dl_handle); } /* scanning for lcrso loop */ + return (-1); + +found: + *instance_ret = instance; + return (0); +} + + +int lcr_ifact_reference ( + unsigned int *iface_handle, + char *iface_name, + int version, + void **iface, + void *context) +{ + struct lcr_iface_instance *iface_instance; + struct lcr_component_instance *instance; + int iface_number; + unsigned int res; + unsigned int i; + + defaults_path_build (); + ld_library_path_build (); + ldso_path_build ("/etc", "ld.so.conf"); + + + /* + * Determine if the component is already loaded + */ + instance = lcr_comp_find (iface_name, version, &iface_number); + if (instance) { + goto found; + } + +// TODO error checking in this code is weak + /* + * Find all *.lcrso files in the cwd + */ + //path = getenv ("LD_LIBRARY_PATH"); + for (i = 0; i < path_list_entries; i++) { + res = interface_find_and_load ( + path_list[i], + iface_name, + version, + &instance, + &iface_number); + + if (res == 0) { + goto found; + } + } /* * No matching interfaces found in all shared objects */ return (-1); found: +printf ("iface number %d\n", iface_number); *iface = instance->ifaces[iface_number].interfaces; if (instance->ifaces[iface_number].constructor) { instance->ifaces[iface_number].constructor (context); @@ -232,7 +379,6 @@ found: iface_instance->component_handle = g_component_handle; iface_instance->context = context; iface_instance->destructor = instance->ifaces[iface_number].destructor; - return (0); } diff --git a/lcr/test.c b/lcr/test.c index 73a09d1f..3e80c585 100644 --- a/lcr/test.c +++ b/lcr/test.c @@ -27,6 +27,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include "lcr_ifact.h" @@ -51,42 +52,48 @@ int main (void) { void *b_iface_ver0_p; void *b_iface_ver1_p; + unsigned int res; + /* * Reference version 0 and 1 of A and B interfaces */ - lcr_ifact_reference ( + res = lcr_ifact_reference ( &a_ifact_handle_ver0, "A_iface1", 0, /* version 0 */ &a_iface_ver0_p, (void *)0xaaaa0000); + assert (res == 0); a_iface_ver0 = (struct iface *)a_iface_ver0_p; - lcr_ifact_reference ( + res = lcr_ifact_reference ( &b_ifact_handle_ver0, "B_iface1", 0, /* version 0 */ &b_iface_ver0_p, (void *)0xbbbb0000); + assert (res == 0); b_iface_ver0 = (struct iface *)b_iface_ver0_p; - lcr_ifact_reference ( + res = lcr_ifact_reference ( &a_ifact_handle_ver1, "A_iface1", 1, /* version 1 */ &a_iface_ver1_p, (void *)0xaaaa1111); + assert (res == 0); a_iface_ver1 = (struct iface *)a_iface_ver0_p; - lcr_ifact_reference ( + res = lcr_ifact_reference ( &b_ifact_handle_ver1, "B_iface1", 1, /* version 1 */ &b_iface_ver1_p, (void *)0xbbbb1111); + assert (res == 0); b_iface_ver1 = (struct iface *)b_iface_ver0_p; diff --git a/lib/Makefile b/lib/Makefile index a731574c..7ff4bd62 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -51,113 +51,59 @@ ifeq (${OPENAIS_COMPAT}, DARWIN) libSaClm.so.1.0: util.o clm.o $(CC) $(LDFLAGS) -bundle -bind_at_load util.o clm.o -o $@ - rm -f libSaClm.so.1 libSaClm.so - ln -s libSaClm.so.1.0 libSaClm.so.1 - ln -s libSaClm.so.1.0 libSaClm.so libSaAmf.so.1.0: util.o amf.o $(CC) $(LDFLAGS) -bundle -bind_at_load util.o amf.o -o $@ - rm -f libSaAmf.so.1 libSaAmf.so - ln -s libSaAmf.so.1.0 libSaAmf.so.1 - ln -s libSaAmf.so.1.0 libSaAmf.so libSaCkpt.so.1.0: util.o ckpt.o $(CC) $(LDFLAGS) -bundle -bind_at_load util.o ckpt.o -o $@ - rm -f libSaCkpt.so.1 libSaCkpt.so - ln -s libSaCkpt.so.1.0 libSaCkpt.so.1 - ln -s libSaCkpt.so.1.0 libSaCkpt.so libSaEvt.so.1.0: util.o evt.o $(CC) $(LDFLAGS) -bundle -bind_at_load util.o evt.o -o $@ - rm -f libSaEvt.so.1 libSaEvt.so - ln -s libSaEvt.so.1.0 libSaEvt.so.1 - ln -s libSaEvt.so.1.0 libSaEvt.so libSaLck.so.1.0: util.o lck.o $(CC) $(LDFLAGS) -bundle -bind_at_load util.o lck.o -o $@ - rm -f libSaLck.so.1 libSaLck.so - ln -s libSaLck.so.1.0 libSaLck.so.1 - ln -s libSaLck.so.1.0 libSaLck.so libSaMsg.so.1.0: util.o msg.o $(CC) $(LDFLAGS) -bundle -bind_at_load util.o msg.o -o $@ - rm -f libSaMsg.so.1 libSaMsg.so - ln -s libSaMsg.so.1.0 libSaMsg.so.1 - ln -s libSaMsg.so.1.0 libSaMsg.so libais.so.1.0: util.o amf.o clm.o ckpt.o evt.o lck.o msg.o $(CC) $(LDFLAGS) -bundle -bind_at_load util.o amf.o clm.o ckpt.o evt.o -o $@ - rm -f libais.so.1 libais.so - ln -s libais.so.1.0 libais.so.1 - ln -s libais.so.1.0 libais.so libevs.so.1.0: util.o evs.o $(CC) $(LDFLAGS) -bundle -bind_at_load util.o evs.o -o $@ - rm -f libevs.so.1 libevs.so - ln -s libevs.so.1.0 libevs.so.1 - ln -s libevs.so.1.0 libevs.so libcpg.so.1.0: util.o cpg.o $(CC) -bundle -bind_at_load util.o cpg.o -o $@ - rm -f libcpg.so.1 libcpg.so - ln -s libcpg.so.1.0 libcpg.so.1 - ln -s libcpg.so.1.0 libcpg.so else libSaClm.so.1.0: util.o clm.o $(CC) $(LDFLAGS) -shared -Wl,-soname,libSaClm.so.1,-version-script=libSaClm.versions util.o clm.o -o $@ - rm -f libSaClm.so.1 libSaClm.so - ln -s libSaClm.so.1.0 libSaClm.so.1 - ln -s libSaClm.so.1.0 libSaClm.so libSaAmf.so.1.0: util.o amf.o $(CC) $(LDFLAGS) -shared -Wl,-soname,libSaAmf.so.1,-version-script=libSaAmf.versions util.o amf.o -o $@ - rm -f libSaAmf.so.1 libSaAmf.so - ln -s libSaAmf.so.1.0 libSaAmf.so.1 - ln -s libSaAmf.so.1.0 libSaAmf.so libSaCkpt.so.1.0: util.o ckpt.o $(CC) $(LDFLAGS) -shared -Wl,-soname,libSaCkpt.so.1,-version-script=libSaCkpt.versions util.o ckpt.o -o $@ - rm -f libSaCkpt.so.1 libSaCkpt.so - ln -s libSaCkpt.so.1.0 libSaCkpt.so.1 - ln -s libSaCkpt.so.1.0 libSaCkpt.so libSaEvt.so.1.0: util.o evt.o $(CC) $(LDFLAGS) -shared -Wl,-soname,libSaEvt.so.1,-version-script=libSaEvt.versions util.o evt.o -o $@ - rm -f libSaEvt.so.1 libSaEvt.so - ln -s libSaEvt.so.1.0 libSaEvt.so.1 - ln -s libSaEvt.so.1.0 libSaEvt.so libSaLck.so.1.0: util.o lck.o - $(CC) $(LDFLAGS) -shared -Wl,-soname,libSaLCK.so.1,-version-script=libSaLck.versions util.o lck.o -o $@ - rm -f libSaLck.so.1 libSaLck.so - ln -s libSaLck.so.1.0 libSaLck.so.1 - ln -s libSaLck.so.1.0 libSaLck.so + $(CC) $(LDFLAGS) -shared -Wl,-soname,libSaLck.so.1,-version-script=libSaLck.versions util.o lck.o -o $@ libSaMsg.so.1.0: util.o msg.o $(CC) $(LDFLAGS) -shared -Wl,-soname,libSaMsg.so.1,-version-script=libSaMsg.versions util.o msg.o -o $@ - rm -f libSaMsg.so.1 libSaMsg.so - ln -s libSaMsg.so.1.0 libSaMsg.so.1 - ln -s libSaMsg.so.1.0 libSaMsg.so libais.so.1.0: util.o amf.o clm.o ckpt.o evt.o lck.o msg.o $(CC) $(LDFLAGS) -shared -Wl,-soname,libais.so.1,-version-script=libSaAis.versions util.o amf.o clm.o ckpt.o evt.o -o $@ - rm -f libais.so.1 libais.so - ln -s libais.so.1.0 libais.so.1 - ln -s libais.so.1.0 libais.so libevs.so.1.0: util.o evs.o $(CC) $(LDFLAGS) -shared -Wl,-soname,libevs.so.1,-version-script=libevs.versions util.o evs.o -o $@ - rm -f libevs.so.1 libevs.so - ln -s libevs.so.1.0 libevs.so.1 - ln -s libevs.so.1.0 libevs.so libcpg.so.1.0: util.o cpg.o $(CC) -shared -Wl,-soname,libcpg.so.1,-version-script=libcpg.versions util.o cpg.o -o $@ - rm -f libcpg.so.1 libcpg.so - ln -s libcpg.so.1.0 libcpg.so.1 - ln -s libcpg.so.1.0 libcpg.so endif