diff --git a/Makefile b/Makefile index 3cbf535c..66e1ea4d 100644 --- a/Makefile +++ b/Makefile @@ -28,34 +28,11 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF # THE POSSIBILITY OF SUCH DAMAGE. -# BUILD_DYNAMIC can be defined to 1 to build for dynamic loading of service -# handler modules. If the developer intends to debug, building without -# dynamic modules should provide an easier route. -BUILD_DYNAMIC=0 - -# Production mode flags -CFLAGS = -O3 -Wall -LDFLAGS = -lpthread -ldl -DESTDIR=/usr/local/openais - -# Debug mode flags -#CFLAGS = -g -#LDFLAGS = -g -lpthread - -# Profile mode flags -#CFLAGS = -O3 -pg -#LDFLAGS = -pg - -ifeq (${BUILD_DYNAMIC}, 1) -CFLAGS += -fPIC -LDFLAGS += -rdynamic -endif - all: - (cd lcr; echo ==== `pwd` ===; $(MAKE) all CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)"); - (cd lib; echo ==== `pwd` ===; $(MAKE) all CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)"); - (cd exec; echo ==== `pwd` ===; $(MAKE) all CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" BUILD_DYNAMIC="$(BUILD_DYNAMIC)"); - (cd test; echo ==== `pwd` ===; $(MAKE) all CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)"); + (cd lcr; echo ==== `pwd` ===; $(MAKE) all); + (cd lib; echo ==== `pwd` ===; $(MAKE) all); + (cd exec; echo ==== `pwd` ===; $(MAKE) all); + (cd test; echo ==== `pwd` ===; $(MAKE) all); clean: (cd lcr; echo ==== `pwd` ===; $(MAKE) clean); @@ -69,23 +46,23 @@ install: mkdir -p $(DESTDIR)/usr/lib mkdir -p $(DESTDIR)/etc/ais - cp -a lib/libais.a $(DESTDIR)/usr/lib - cp -a lib/libais.so* $(DESTDIR)/usr/lib - cp -a lib/libSa*.a $(DESTDIR)/usr/lib - cp -a lib/libSa*.so* $(DESTDIR)/usr/lib - cp -a lib/libevs.a $(DESTDIR)/usr/lib - cp -a lib/libevs.so* $(DESTDIR)/usr/lib - cp -a exec/libtotem_pg* $(DESTDIR)/usr/lib + 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 exec/libtotem_pg* $(DESTDIR)/usr/lib 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 -a include/saAis.h $(DESTDIR)/usr/include - cp -a include/ais_amf.h $(DESTDIR)/usr/include - cp -a include/saClm.h $(DESTDIR)/usr/include - cp -a include/saCkpt.h $(DESTDIR)/usr/include - cp -a include/saEvt.h $(DESTDIR)/usr/include - cp -a include/evs.h $(DESTDIR)/usr/include - cp -a exec/totem.h $(DESTDIR)/usr/include + 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 diff --git a/Makefile.inc b/Makefile.inc new file mode 100644 index 00000000..3fbe3e87 --- /dev/null +++ b/Makefile.inc @@ -0,0 +1,83 @@ +# Basic OS detection +# +UNAME=$(shell uname) + +ifeq "$(UNAME)" "Linux" + OPENAIS_COMPAT=LINUX +endif +ifeq "$(UNAME)" "Darwin" + OPENAIS_COMPAT=DARWIN +endif +ifneq "" "$(findstring BSD,$(UNAME))" + OPENAIS_COMPAT=BSD +endif +ifndef OPENAIS_COMPAT +$(error "OPENAIS_COMPAT cannot be detected, it must be manually defined") +endif + +# BUILD_DYNAMIC can be defined to 1 to build for dynamic loading of service +# handler modules. If the developer intends to debug, building without +# dynamic modules should provide an easier route. +ifndef BUILD_DYNAMIC + BUILD_DYNAMIC=1 +endif + +# OPENAIS_BUILD can be defined as RELEASE or DEBUG +# +ifndef OPENAIS_BUILD + OPENAIS_BUILD=RELEASE +endif + +# OPENAIS_PROFILE +# OPENAIS_COVERAGE + +# OPENAIS_USER, OPENAIS_GROUP default to ais +# +ifndef OPENAIS_USER + OPENAIS_USER=ais +endif +ifndef OPENAIS_GROUP + OPENAIS_GROUP=ais +endif + +# default CFLAGS, LDFLAGS +# +CFLAGS = +LDFLAGS = +DYFLAGS = + +# build CFLAGS, LDFLAGS +# +ifeq (${OPENAIS_BUILD}, RELEASE) + CFLAGS += -O3 -Wall -fomit-frame-pointer + LDFLAGS += +endif +ifeq (${OPENAIS_BUILD}, DEBUG) + CFLAGS += -O0 -g -Wall + LDFLAGS += -g +endif + +ifdef OPENAIS_PROFILE + CFLAGS += -pg + LDFLAGS += -pg +endif +ifdef OPENAIS_COVERAGE + CFLAGS += -ftest-coverage -fprofile-arcs +endif + +# platform specific CFLAGS, LDFLAGS +# +ifeq (${OPENAIS_COMPAT}, LINUX) + CFLAGS += -DOPENAIS_LINUX + LDFLAGS += -ldl -lpthread + DYFLAGS += -rdynamic +endif +ifeq (${OPENAIS_COMPAT}, BSD) + CFLAGS += -DOPENAIS_BSD + LDFLAGS += -pthread + DYFLAGS += -export-dynamic +endif +ifeq (${OPENAIS_COMPAT}, DARWIN) + CFLAGS += -DOPENAIS_DARWIN + LDFLAGS += -lpthread +endif diff --git a/exec/Makefile b/exec/Makefile index de9548d8..c7439caa 100644 --- a/exec/Makefile +++ b/exec/Makefile @@ -28,26 +28,24 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF # THE POSSIBILITY OF SUCH DAMAGE. -# BUILD_DYNAMIC can be defined to 1 to build for dynamic loading of service -# handler modules. If the developer intends to debug, building without -# dynamic modules should provide an easier route. -BUILD_DYNAMIC=0 +# Include configuration +# +include ../Makefile.inc -# Production mode flags -CFLAGS = -O3 -Wall -fomit-frame-pointer -LDFLAGS = -lpthread -ldl +CFLAGS += -I../include +LDFLAGS += -L./ -# Debug mode flags -#CFLAGS = -g -Wall -#LDFLAGS = -g -lpthread -ldl +ifeq (${BUILD_DYNAMIC}, 1) + LDFLAGS += ${DYFLAGS} +endif -# Profile mode flags -#CFLAGS = -O3 -pg -#LDFLAGS = -pg -lpthread +ifeq (${OPENAIS_COMPAT}, LINUX) + LDFLAGS += -ldl +endif -# Code Coverage with lcov flgs -#CFLAGS = -ftest-coverage -fprofile-arcs -#LDFLAGS = -g +# OPENAIS_USER, OPENAISGROUP +# +CFLAGS += -DOPENAIS_USER=\"${OPENAIS_USER}\" -DOPENAIS_GROUP=\"${OPENAIS_GROUP}\" # Totem objects TOTEM_SRC = aispoll.c totemip.c totemnet.c totemrrp.c totemsrp.c totemmrp.c totempg.c totemconfig.c tlist.c crypto.c wthread.c @@ -67,19 +65,47 @@ MAIN_OBJS = main.o print.o mempool.o \ ifeq (${BUILD_DYNAMIC}, 1) EXEC_OBJS = $(TOTEM_OBJS) $(MAIN_OBJS) CFLAGS += -fPIC -LDFLAGS += -rdynamic all:libtotem_pg.a libtotem_pg.so.1.0 ../lcr/lcr_ifact.o \ + aisexec \ service_evs.lcrso service_clm.lcrso service_amf.lcrso \ service_ckpt.lcrso service_evt.lcrso service_lck.lcrso \ service_msg.lcrso service_cfg.lcrso \ - aisexec keygen openais-instantiate + keygen openais-instantiate else EXEC_OBJS = $(TOTEM_OBJS) $(MAIN_OBJS) $(SERV_OBJS) all: libtotem_pg.a aisexec keygen openais-instantiate endif +ifeq (${OPENAIS_COMPAT}, DARWIN) + +service_evs.lcrso: evs.o + $(CC) -bundle -bundle_loader ./aisexec -bind_at_load evs.o -o $@ + +service_clm.lcrso: clm.o + $(CC) -bundle -bundle_loader ./aisexec -bind_at_load clm.o -o $@ + +service_amf.lcrso: amf.o + $(CC) -bundle -bundle_loader ./aisexec -bind_at_load amf.o -o $@ + +service_ckpt.lcrso: ckpt.o + $(CC) -bundle -bundle_loader ./aisexec -bind_at_load ckpt.o -o $@ + +service_evt.lcrso: evt.o + $(CC) -bundle -bundle_loader ./aisexec -bind_at_load evt.o -o $@ + +service_lck.lcrso: lck.o + $(CC) -bundle -bundle_loader ./aisexec -bind_at_load lck.o -o $@ + +service_msg.lcrso: msg.o + $(CC) -bundle -bundle_loader ./aisexec -bind_at_load msg.o -o $@ + +service_cfg.lcrso: cfg.o + $(CC) -bundle -bundle_loader ./aisexec -bind_at_load cfg.o -o $@ + +else + service_evs.lcrso: evs.o $(CC) -shared -Wl,-soname,service_evs.lcrso evs.o -o $@ @@ -103,6 +129,8 @@ service_msg.lcrso: msg.o service_cfg.lcrso: cfg.o $(CC) -shared -Wl,-soname,service_cfg.lcrso cfg.o -o $@ + +endif aisexec: $(EXEC_OBJS) libtotem_pg.a $(CC) $(LDFLAGS) $(EXEC_OBJS) $(EXEC_LIBS) -o aisexec @@ -110,12 +138,24 @@ aisexec: $(EXEC_OBJS) libtotem_pg.a libtotem_pg.a: $(TOTEM_OBJS) $(AR) -rc libtotem_pg.a $(TOTEM_OBJS) +ifeq (${OPENAIS_COMPAT}, DARWIN) + +libtotem_pg.so.1.0: $(TOTEM_OBJS) + $(CC) -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) -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 + keygen: keygen.o $(CC) $(LDFLAGS) keygen.o -o keygen diff --git a/exec/amf.c b/exec/amf.c index e5a65562..fa80ecff 100644 --- a/exec/amf.c +++ b/exec/amf.c @@ -435,12 +435,10 @@ struct openais_service_handler *amf_get_handler_ver0 (void) return (&amf_service_handler); } -static void register_this_component (void) { +__attribute__ ((constructor)) static void register_this_component (void) { lcr_component_register (&amf_comp_ver0); } -void (*const __init_this_component[1]) (void) __attribute__ ((section(".ctors"))) = { register_this_component }; - enum clc_command_run_operation_type { CLC_COMMAND_RUN_OPERATION_TYPE_INSTANTIATE = 1, CLC_COMMAND_RUN_OPERATION_TYPE_TERMINATE = 2, @@ -4333,9 +4331,6 @@ static void message_handler_req_exec_amf_hastateset (void *message, struct in_ad static void message_handler_req_lib_amf_readinessstateget (struct conn_info *conn_info, void *message) { -<<<<<<< .mine - struct req_lib_amf_readinessstateget *req_lib_amf_readinessstateget = (struct req_lib_amf_readinessstateget *)message; -======= struct req_lib_amf_componentregister *req_lib_amf_componentregister = (struct req_lib_amf_componentregister *)message; struct req_exec_amf_componentregister req_exec_amf_componentregister; struct iovec iovec; @@ -4418,9 +4413,6 @@ static void message_handler_req_lib_amf_stoppingcomplete (struct conn_info *conn { struct req_lib_amf_stoppingcomplete *req_lib_amf_stoppingcomplete = (struct req_lib_amf_stoppingcomplete *)message; -<<<<<<< .mine - struct conn_info *inv_conn_info; -======= log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_protectiongrouptrackstart()\n"); amfProtectionGroup = protectiongroup_find (&req_amf_protectiongrouptrackstart->csiName); diff --git a/exec/cfg.c b/exec/cfg.c index 4bbc8587..a90a52de 100644 --- a/exec/cfg.c +++ b/exec/cfg.c @@ -177,12 +177,11 @@ struct openais_service_handler *cfg_get_handler_ver0 (void) { return (&cfg_service_handler); } -static void register_this_component (void) { + +__attribute__ ((constructor)) static void register_this_component (void) { lcr_component_register (&cfg_comp_ver0); } -void (*const __ctor_cfg_comp[1]) (void) __attribute__ ((section(".ctors"))) = { register_this_component }; - /* IMPL */ static int cfg_exec_init_fn (struct openais_config *openais_config) diff --git a/exec/ckpt.c b/exec/ckpt.c index b6d1fc45..d5041f31 100644 --- a/exec/ckpt.c +++ b/exec/ckpt.c @@ -532,12 +532,10 @@ struct openais_service_handler *ckpt_get_handler_ver0 (void) return (&ckpt_service_handler); } -static void register_this_component (void) { +__attribute__ ((constructor)) static void register_this_component (void) { lcr_component_register (&ckpt_comp_ver0); } -void (*const __ctor_ckpt_comp[1]) (void) __attribute__ ((section(".ctors"))) = { register_this_component }; - /* * All data types used for executive messages */ diff --git a/exec/clm.c b/exec/clm.c index c4a55462..7dcac2af 100644 --- a/exec/clm.c +++ b/exec/clm.c @@ -36,7 +36,12 @@ #include #include #include +#if defined(OPENAIS_LINUX) #include +#endif +#if defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN) +#include +#endif #include #include #include @@ -240,12 +245,10 @@ struct openais_service_handler *clm_get_service_handler_ver0 (void) return (&clm_service_handler); } -static void clm_comp_register (void) { +__attribute__ ((constructor)) static void clm_comp_register (void) { lcr_component_register (&clm_comp_ver0); } -void (*const __ctor_clm_comp[1]) (void) __attribute__ ((section(".ctors"))) = { clm_comp_register }; - struct req_exec_clm_nodejoin { struct req_header header; SaClmClusterNodeT clusterNode; @@ -275,12 +278,25 @@ static int clm_exec_init_fn (struct openais_config *openais_config) printf ("setting B to %x\n", this_ip->nodeid); thisClusterNode.member = 1; { +#if defined(OPENAIS_LINUX) struct sysinfo s_info; time_t current_time; sysinfo (&s_info); current_time = time (NULL); /* (currenttime (s) - uptime (s)) * 1 billion (ns) / 1 (s) */ thisClusterNode.bootTimestamp = ((SaTimeT)(current_time - s_info.uptime)) * 1000000000; +#elif defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN) + int mib[2] = { CTL_KERN, KERN_BOOTTIME }; + struct timeval boot_time; + size_t size = sizeof(boot_time); + + if ( sysctl(mib, 2, &boot_time, &size, NULL, 0) == -1 ) + boot_time.tv_sec = time (NULL); + /* (currenttime (s) - uptime (s)) * 1 billion (ns) / 1 (s) */ + thisClusterNode.bootTimestamp = ((SaTimeT)boot_time.tv_sec) * 1000000000; +#else /* defined(CTL_KERN) && defined(KERN_BOOTTIME) */ + #warning "no bootime support" +#endif } memcpy (&clusterNodes[0], &thisClusterNode, sizeof (SaClmClusterNodeT)); diff --git a/exec/crypto.c b/exec/crypto.c index 9769c694..1c1903ec 100644 --- a/exec/crypto.c +++ b/exec/crypto.c @@ -10,12 +10,14 @@ */ #include #include -#include #include #include #include #include #include +#if defined(OPENAIS_BSD) +#include +#endif #include #include @@ -28,16 +30,28 @@ typedef unsigned long long ulong64; #if __BYTE_ORDER == __LITTLE_ENDIAN #define ENDIAN_LITTLE -#endif -#if __BYTE_ORDER == __BIG_ENDIAN +#elif __BYTE_ORDER == __BIG_ENDIAN #define ENDIAN_BIG +#elif _BYTE_ORDER == _LITTLE_ENDIAN +#define ENDIAN_LITTLE +#elif _BYTE_ORDER == _BIG_ENDIAN +#define ENDIAN_BIG +#elif +#warning "cannot detect byte order" #endif + +#if defined(OPENAIS_LINUX) #if __WORDIZE == 64 #define ENDIAN_64BITWORD #endif #if __WORDIZE == 32 #define ENDIAN_32BITWORD #endif +#else +/* XXX need to find a better default + */ +#define ENDIAN_32BITWORD +#endif /* ---- HELPER MACROS ---- */ #ifdef ENDIAN_NEUTRAL @@ -1248,7 +1262,7 @@ static unsigned long rng_nix(unsigned char *buf, unsigned long len, } /* on ANSI C platforms with 100 < CLOCKS_PER_SEC < 10000 */ -#if defined(CLOCKS_PER_SEC) +#if defined(XCLOCKS_PER_SEC) #define ANSI_RNG diff --git a/exec/evs.c b/exec/evs.c index c327048e..c77f6bf5 100644 --- a/exec/evs.c +++ b/exec/evs.c @@ -36,7 +36,6 @@ #include #include #include -#include #include #include #include @@ -193,12 +192,10 @@ struct openais_service_handler *evs_get_service_handler_ver0 (void) return (&evs_service_handler); } -static void evs_comp_register (void) { +__attribute__ ((constructor)) static void evs_comp_register (void) { lcr_component_register (&evs_comp_ver0); } -void (*const __ctor_evs_comp[1]) (void) __attribute__ ((section(".ctors"))) = { evs_comp_register }; - struct res_evs_confchg_callback res_evs_confchg_callback; static void evs_confchg_fn ( diff --git a/exec/evt.c b/exec/evt.c index 99c4c0e6..076fb1c9 100644 --- a/exec/evt.c +++ b/exec/evt.c @@ -41,7 +41,7 @@ #define RETENTION_TIME_DEBUG LOG_LEVEL_DEBUG #include -#include +#include #include #include #include @@ -258,12 +258,10 @@ struct openais_service_handler *evt_get_handler_ver0(void) return (&evt_service_handler); } -static void evt_comp_register (void) { +__attribute__ ((constructor)) static void evt_comp_register (void) { lcr_component_register (&evt_comp_ver0); } -void (*const __ctor_evt_comp[1]) (void) __attribute__ ((section(".ctors"))) = { evt_comp_register }; - /* * list of all retained events * struct event_data diff --git a/exec/keygen.c b/exec/keygen.c index 106eba40..f8c51dfb 100644 --- a/exec/keygen.c +++ b/exec/keygen.c @@ -53,7 +53,7 @@ int main (void) { } mkdir ("/etc/ais", 0700); - printf ("Gathering %ld bits for key from /dev/random.\n", sizeof (key) * 8); + printf ("Gathering %lu bits for key from /dev/random.\n", sizeof (key) * 8); random_fd = open ("/dev/random", O_RDONLY); if (random_fd == -1) { perror ("Is /dev/random present? Opening /dev/random"); diff --git a/exec/lck.c b/exec/lck.c index 295893c5..16d0ff18 100644 --- a/exec/lck.c +++ b/exec/lck.c @@ -332,12 +332,10 @@ struct openais_service_handler *lck_get_handler_ver0 (void) return (&lck_service_handler); } -static void register_this_component (void) { +__attribute__ ((constructor)) static void register_this_component (void) { lcr_component_register (&lck_comp_ver0); } -void (*const __lck_ctor_comp[1]) (void) __attribute__ ((section(".ctors"))) = { register_this_component }; - /* * All data types used for executive messages */ diff --git a/exec/main.c b/exec/main.c index dcd110af..564af6b2 100644 --- a/exec/main.c +++ b/exec/main.c @@ -33,6 +33,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include @@ -42,7 +43,6 @@ #include #include #include -#include #include #include #include @@ -200,7 +200,17 @@ struct totem_ip_address *this_ip; struct totem_ip_address this_non_loopback_ip; #define LOCALHOST_IP inet_addr("127.0.0.1") +#if defined(OPENAIS_LINUX) +/* SUN_LEN is broken for abstract namespace + */ +#define AIS_SUN_LEN(a) sizeof(*(a)) + char *socketname = "libais.socket"; +#else +#define AIS_SUN_LEN(a) SUN_LEN(a) + +char *socketname = "/var/run/libais.socket"; +#endif totempg_groups_handle openais_group_handle; @@ -508,7 +518,9 @@ static int poll_handler_libais_accept ( struct conn_info *conn_info; struct sockaddr_un un_addr; int new_fd; +#ifdef OPENAIS_LINUX int on = 1; +#endif int res; addrlen = sizeof (struct sockaddr_un); @@ -524,12 +536,13 @@ retry_accept: return (0); /* This is an error, but -1 would indicate disconnect from poll loop */ } + totemip_nosigpipe(new_fd); res = fcntl (new_fd, F_SETFL, O_NONBLOCK); if (res == -1) { log_printf (LOG_LEVEL_ERROR, "Could not set non-blocking operation on library connection: %s\n", strerror (errno)); close (new_fd); return (0); /* This is an error, but -1 would indicate disconnect from poll loop */ - } + } /* * Valid accept @@ -538,7 +551,9 @@ retry_accept: /* * Request credentials of sender provided by kernel */ +#ifdef OPENAIS_LINUX setsockopt(new_fd, SOL_SOCKET, SO_PASSCRED, &on, sizeof (on)); +#endif log_printf (LOG_LEVEL_DEBUG, "connection received from libais client %d.\n", new_fd); @@ -665,10 +680,15 @@ static int poll_handler_libais_deliver (poll_handle handle, int fd, int revent, int service; struct msghdr msg_recv; struct iovec iov_recv; +#ifdef OPENAIS_LINUX struct cmsghdr *cmsg; char cmsg_cred[CMSG_SPACE (sizeof (struct ucred))]; struct ucred *cred; int on = 0; +#else + uid_t euid; + gid_t egid; +#endif int send_ok = 0; int send_ok_joined = 0; struct iovec send_ok_joined_iovec; @@ -709,8 +729,19 @@ static int poll_handler_libais_deliver (poll_handle handle, int fd, int revent, msg_recv.msg_control = 0; msg_recv.msg_controllen = 0; } else { +#ifdef OPENAIS_LINUX msg_recv.msg_control = (void *)cmsg_cred; msg_recv.msg_controllen = sizeof (cmsg_cred); +#else + euid = -1; egid = -1; + if (getpeereid(fd, &euid, &egid) != -1 && + (euid == 0 || egid == gid_valid)) { + conn_info->authenticated = 1; + } + if (conn_info->authenticated == 0) { + log_printf (LOG_LEVEL_SECURITY, "Connection not authenticated because gid is %d, expecting %d\n", egid, gid_valid); + } +#endif } iov_recv.iov_base = &conn_info->inb[conn_info->inb_start]; @@ -718,7 +749,7 @@ static int poll_handler_libais_deliver (poll_handle handle, int fd, int revent, assert (iov_recv.iov_len != 0); retry_recv: - res = recvmsg (fd, &msg_recv, MSG_NOSIGNAL); + res = recvmsg (fd, &msg_recv, MSG_NOSIGNAL | MSG_DONTWAIT); if (res == -1 && errno == EINTR) { goto retry_recv; } else @@ -733,6 +764,7 @@ retry_recv: /* * Authenticate if this connection has not been authenticated */ +#ifdef OPENAIS_LINUX if (conn_info->authenticated == 0) { cmsg = CMSG_FIRSTHDR (&msg_recv); cred = (struct ucred *)CMSG_DATA (cmsg); @@ -746,6 +778,7 @@ retry_recv: log_printf (LOG_LEVEL_SECURITY, "Connection not authenticated because gid is %d, expecting %d\n", cred->gid, gid_valid); } } +#endif /* * Dispatch all messages received in recvmsg that can be dispatched * sizeof (struct req_header) needed at minimum to do any processing @@ -862,9 +895,6 @@ void sigintr_handler (int signum) ais_done (AIS_DONE_EXIT); } -static struct sched_param sched_param = { - sched_priority: 99 -}; static int pool_sizes[] = { 0, 0, 0, 0, 0, 4096, 0, 1, 0, /* 256 */ 1024, 0, 1, 4096, 0, 0, 0, 0, /* 65536 */ @@ -972,9 +1002,9 @@ static void aisexec_uid_determine (void) { struct passwd *passwd; - passwd = getpwnam("ais"); + passwd = getpwnam(OPENAIS_USER); if (passwd == 0) { - log_printf (LOG_LEVEL_ERROR, "ERROR: The 'ais' user is not found in /etc/passwd, please read the documentation.\n"); + log_printf (LOG_LEVEL_ERROR, "ERROR: The '%s' user is not found in /etc/passwd, please read the documentation.\n", OPENAIS_USER); ais_done (AIS_DONE_UID_DETERMINE); } ais_uid = passwd->pw_uid; @@ -983,9 +1013,9 @@ static void aisexec_uid_determine (void) static void aisexec_gid_determine (void) { struct group *group; - group = getgrnam ("ais"); + group = getgrnam (OPENAIS_GROUP); if (group == 0) { - log_printf (LOG_LEVEL_ERROR, "ERROR: The 'ais' group is not found in /etc/group, please read the documentation.\n"); + log_printf (LOG_LEVEL_ERROR, "ERROR: The '%s' group is not found in /etc/group, please read the documentation.\n", OPENAIS_GROUP); ais_done (AIS_DONE_GID_DETERMINE); } gid_valid = group->gr_gid; @@ -1048,17 +1078,28 @@ static void aisexec_libais_bind (int *server_fd) ais_done (AIS_DONE_LIBAIS_SOCKET); }; + totemip_nosigpipe(libais_server_fd); res = fcntl (libais_server_fd, F_SETFL, O_NONBLOCK); if (res == -1) { log_printf (LOG_LEVEL_ERROR, "Could not set non-blocking operation on server socket: %s\n", strerror (errno)); ais_done (AIS_DONE_LIBAIS_SOCKET); } +#if !defined(OPENAIS_LINUX) + unlink(socketname); +#endif memset (&un_addr, 0, sizeof (struct sockaddr_un)); un_addr.sun_family = AF_UNIX; +#if defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN) + un_addr.sun_len = sizeof(struct sockaddr_un); +#endif +#if defined(OPENAIS_LINUX) strcpy (un_addr.sun_path + 1, socketname); +#else + strcpy (un_addr.sun_path, socketname); +#endif - res = bind (libais_server_fd, (struct sockaddr *)&un_addr, sizeof (struct sockaddr_un)); + res = bind (libais_server_fd, (struct sockaddr *)&un_addr, AIS_SUN_LEN(&un_addr)); if (res) { log_printf (LOG_LEVEL_ERROR, "ERROR: Could not bind AF_UNIX: %s.\n", strerror (errno)); ais_done (AIS_DONE_LIBAIS_BIND); @@ -1070,28 +1111,43 @@ static void aisexec_libais_bind (int *server_fd) static void aisexec_setscheduler (void) { +#if defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) + static struct sched_param sched_param = { + sched_priority: 99 + }; int res; -return; res = sched_setscheduler (0, SCHED_RR, &sched_param); if (res == -1) { log_printf (LOG_LEVEL_WARNING, "Could not set SCHED_RR at priority 99: %s\n", strerror (errno)); } +#else + log_printf(LOG_LEVEL_WARNING, "Scheduler priority left to default value (no OS support)\n"); +#endif } static void aisexec_mlockall (void) { +#if !defined(OPENAIS_BSD) int res; +#endif struct rlimit rlimit; rlimit.rlim_cur = RLIM_INFINITY; rlimit.rlim_max = RLIM_INFINITY; setrlimit (RLIMIT_MEMLOCK, &rlimit); +#if defined(OPENAIS_BSD) + /* under FreeBSD a process with locked page cannot call dlopen + * code disabled until FreeBSD bug i386/93396 was solved + */ + log_printf (LOG_LEVEL_WARNING, "Could not lock memory of service to avoid page faults\n"); +#else res = mlockall (MCL_CURRENT | MCL_FUTURE); if (res == -1) { log_printf (LOG_LEVEL_WARNING, "Could not lock memory of service to avoid page faults: %s\n", strerror (errno)); }; +#endif } int message_source_is_local(struct message_source *source) diff --git a/exec/msg.c b/exec/msg.c index eafd1c62..74a2e760 100644 --- a/exec/msg.c +++ b/exec/msg.c @@ -481,12 +481,10 @@ struct openais_service_handler *msg_get_handler_ver0 (void) return (&msg_service_handler); } -static void register_this_component (void) { +__attribute__ ((constructor)) static void register_this_component (void) { lcr_component_register (&msg_comp_ver0); } -void (*const __ctor_msg_comp[1]) (void) __attribute__ ((section(".ctors"))) = { register_this_component }; - /* * All data types used for executive messages */ diff --git a/exec/print.c b/exec/print.c index f9a5aab4..fe0b4dfd 100644 --- a/exec/print.c +++ b/exec/print.c @@ -39,10 +39,14 @@ #include #include #include +#if defined(OPENAIS_LINUX) #include - - +#endif +#if defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN) +#include +#endif #include "print.h" +#include "totemip.h" #include "../include/saAis.h" unsigned int logmode = LOG_MODE_STDERR | LOG_MODE_SYSLOG; @@ -138,7 +142,7 @@ void log_syslog (char *log_string) { msg_log.msg_controllen = 0; msg_log.msg_flags = 0; - res = sendmsg (log_syslog_fd, &msg_log, MSG_NOSIGNAL | MSG_DONTWAIT); + res = sendmsg (log_syslog_fd, &msg_log, MSG_NOSIGNAL); } void internal_log_printf (int logclass, char *string, ...) diff --git a/exec/sync.c b/exec/sync.c index 03e60478..5e0fccc2 100644 --- a/exec/sync.c +++ b/exec/sync.c @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include diff --git a/exec/totemconfig.c b/exec/totemconfig.c index ea8a8402..8602a4c9 100644 --- a/exec/totemconfig.c +++ b/exec/totemconfig.c @@ -53,6 +53,10 @@ #define LOG_SERVICE LOG_SERVICE_GMI +#if defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN) + #define HZ 100 /* 10ms */ +#endif + #define TOKEN_RETRANSMITS_BEFORE_LOSS_CONST 4 #define TOKEN_TIMEOUT 1000 #define TOKEN_RETRANSMIT_TIMEOUT (int)(TOKEN_TIMEOUT / (TOKEN_RETRANSMITS_BEFORE_LOSS_CONST + 0.2)) diff --git a/exec/totemip.c b/exec/totemip.c index 927a7d32..17a12fc0 100644 --- a/exec/totemip.c +++ b/exec/totemip.c @@ -34,21 +34,37 @@ /* IPv4/6 abstraction */ +#include +#include +#include +#include #include +#include +#include +#if defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN) +#include +#include +#include +#include +#endif #include #include #include #include #include #include -#include -#include -#include + +#if defined(OPENAIS_LINUX) #include /* ARGH!! I hate netlink */ #include #include +#endif + +#ifndef s6_addr16 +#define s6_addr16 __u6_addr.__u6_addr16 +#endif #include "totemip.h" #include "swab.h" @@ -58,6 +74,14 @@ #define NETLINK_BUFSIZE 16384 +#ifdef SO_NOSIGPIPE +void totemip_nosigpipe(int s) +{ + int on = 1; + setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, (void *)&on, sizeof(on)); +} +#endif + /* Compare two addresses */ int totemip_equal(struct totem_ip_address *addr1, struct totem_ip_address *addr2) { @@ -179,10 +203,12 @@ int totemip_totemip_to_sockaddr_convert(struct totem_ip_address *ip_addr, struct sockaddr_in *sin = (struct sockaddr_in *)saddr; memset(sin, 0, sizeof(struct sockaddr_in)); +#if defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN) + sin->sin_len = sizeof(struct sockaddr_in); +#endif sin->sin_family = ip_addr->family; sin->sin_port = port; memcpy(&sin->sin_addr, ip_addr->addr, sizeof(struct in_addr)); - *addrlen = sizeof(struct sockaddr_in); ret = 0; } @@ -191,6 +217,9 @@ int totemip_totemip_to_sockaddr_convert(struct totem_ip_address *ip_addr, struct sockaddr_in6 *sin = (struct sockaddr_in6 *)saddr; memset(sin, 0, sizeof(struct sockaddr_in6)); +#if defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN) + sin->sin6_len = sizeof(struct sockaddr_in6); +#endif sin->sin6_family = ip_addr->family; sin->sin6_port = port; sin->sin6_scope_id = 2; @@ -206,18 +235,18 @@ int totemip_totemip_to_sockaddr_convert(struct totem_ip_address *ip_addr, /* Converts an address string string into a totem_ip_address */ int totemip_parse(struct totem_ip_address *totemip, char *addr) { - struct addrinfo *ainfo; - struct addrinfo ahints; + struct addrinfo *ainfo; + struct addrinfo ahints; struct sockaddr_in *sa; struct sockaddr_in6 *sa6; int ret; - memset(&ahints, 0, sizeof(ahints)); - ahints.ai_socktype = SOCK_DGRAM; - ahints.ai_protocol = IPPROTO_UDP; + memset(&ahints, 0, sizeof(ahints)); + ahints.ai_socktype = SOCK_DGRAM; + ahints.ai_protocol = IPPROTO_UDP; - /* Lookup the nodename address */ - ret = getaddrinfo(addr, NULL, &ahints, &ainfo); + /* Lookup the nodename address */ + ret = getaddrinfo(addr, NULL, &ahints, &ainfo); if (ret) return -errno; @@ -258,6 +287,111 @@ int totemip_sockaddr_to_totemip_convert(struct sockaddr_storage *saddr, struct t return ret; } +#if defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN) +int totemip_iface_check(struct totem_ip_address *bindnet, + struct totem_ip_address *boundto, + int *interface_up, + int *interface_num) +{ +#define NEXT_IFR(a) ((struct ifreq *)((u_char *)&(a)->ifr_addr +\ + ((a)->ifr_addr.sa_len ? (a)->ifr_addr.sa_len : sizeof((a)->ifr_addr)))) + + struct sockaddr_in *intf_addr_mask; + struct sockaddr_storage bindnet_ss, intf_addr_ss; + struct sockaddr_in *intf_addr_sin = (struct sockaddr_in *)&intf_addr_ss; + struct sockaddr_in *bindnet_sin = (struct sockaddr_in *)&bindnet_ss; + struct ifreq *ifr, *lifr; + int id_fd; + struct ifconf ifc; + struct ifreq ifrb; + int numreqs = 0; + int res; + int addrlen; + + *interface_up = 0; + *interface_num = 0; + + totemip_totemip_to_sockaddr_convert(bindnet, + 0, &bindnet_ss, &addrlen); + + /* + * Generate list of local interfaces in ifc.ifc_req structure + */ + id_fd = socket (AF_INET, SOCK_DGRAM, 0); + ifc.ifc_buf = 0; + do { + numreqs += 32; + ifc.ifc_len = sizeof (struct ifreq) * numreqs; + ifc.ifc_buf = (void *)realloc(ifc.ifc_buf, ifc.ifc_len); + res = ioctl (id_fd, SIOCGIFCONF, &ifc); + if (res < 0) { + close (id_fd); + return -1; + } + } while (ifc.ifc_len == sizeof (struct ifreq) * numreqs); + res = -1; + + /* + * Find interface address to bind to + */ + lifr = (struct ifreq *)ifc.ifc_buf + (ifc.ifc_len / sizeof(*lifr)); + + for (ifr = ifc.ifc_req; ifr < lifr; ifr = NEXT_IFR(ifr)) { + strcpy(ifrb.ifr_name, ifr->ifr_name); + + /* Skip if no address set + */ + if (ioctl(id_fd, SIOCGIFADDR, &ifrb) < 0) + continue; + + memcpy(&intf_addr_ss, &ifrb.ifr_addr, sizeof(intf_addr_ss)); + if (intf_addr_sin->sin_family == AF_INET) { + /* Retrieve mask + */ + if (ioctl(id_fd, SIOCGIFNETMASK, &ifrb) < 0) { + printf ("couldn't do ioctl\n"); + break; + } + intf_addr_mask = (struct sockaddr_in *)&ifrb.ifr_addr; + + if ( bindnet_sin->sin_family == AF_INET && + (intf_addr_sin->sin_addr.s_addr & intf_addr_mask->sin_addr.s_addr) == + (bindnet_sin->sin_addr.s_addr & intf_addr_mask->sin_addr.s_addr)) { + + totemip_copy(boundto, bindnet); + memcpy(boundto->addr, &intf_addr_sin->sin_addr, sizeof(intf_addr_sin->sin_addr)); + + /* Get inteface state + */ + if (ioctl(id_fd, SIOCGIFFLAGS, &ifrb) < 0) { + printf ("couldn't do ioctl\n"); + break; + } + *interface_up = ifrb.ifr_flags & IFF_UP; + + /* Get interface index + */ +#ifdef SIOCGIFINDEX + if (ioctl(id_fd, SIOCGIFINDEX, &ifrb) < 0) { + printf ("couldn't do ioctl\n"); + break; + } + *interface_num = ifrb.ifr_index; +#else + *interface_num = if_nametoindex(ifrb.ifr_name); +#endif + res = 0; + break; /* for */ + } + } + } + free (ifc.ifc_buf); + close (id_fd); + + return (res); +} +#elif defined(OPENAIS_LINUX) + static void parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len) { while (RTA_OK(rta, len)) { @@ -411,3 +545,6 @@ finished: close(fd); return 0; } +#endif /* OPENAIS_LINUX */ + + diff --git a/exec/totemip.h b/exec/totemip.h index 1ba9f7d8..296936aa 100644 --- a/exec/totemip.h +++ b/exec/totemip.h @@ -37,6 +37,18 @@ #ifndef TOTEMIP_H_DEFINED #define TOTEMIP_H_DEFINED +#include +#include + +#ifdef SO_NOSIGPIPE +#ifndef MSG_NOSIGNAL +#define MSG_NOSIGNAL 0 +#endif +void totemip_nosigpipe(int s); +#else +#define totemip_nosigpipe(s) +#endif + #define TOTEMIP_ADDRLEN (sizeof(struct in6_addr)) /* These are the things that get passed around */ diff --git a/exec/totemmrp.c b/exec/totemmrp.c index 8ec2566e..5c24b2e1 100644 --- a/exec/totemmrp.c +++ b/exec/totemmrp.c @@ -38,13 +38,10 @@ #include #include #include -#include #include #include #include #include -#include -#include #include #include #include diff --git a/exec/totemnet.c b/exec/totemnet.c index c641220a..3dbc7baa 100644 --- a/exec/totemnet.c +++ b/exec/totemnet.c @@ -41,13 +41,10 @@ #include #include #include -#include #include #include #include #include -#include -#include #include #include #include @@ -649,7 +646,7 @@ static int net_deliver_fn ( msg_recv.msg_controllen = 0; msg_recv.msg_flags = 0; - bytes_received = recvmsg (fd, &msg_recv, MSG_NOSIGNAL); + bytes_received = recvmsg (fd, &msg_recv, MSG_NOSIGNAL | MSG_DONTWAIT); if (bytes_received == -1) { return (0); } else { @@ -807,12 +804,12 @@ static void timer_function_netif_check_timeout ( totemip_copy (&instance->my_id, &instance->totemnet_interface->boundto); /* - * This stuff depends on totemnet_build_sockets - */ + * This stuff depends on totemnet_build_sockets + */ if (interface_up) { if (instance->netif_state_report & NETIF_STATE_REPORT_UP) { instance->totemnet_log_printf (instance->totemnet_log_level_notice, - " The network interface [%s] is now up.\n", + "The network interface [%s] is now up.\n", totemip_print (&instance->totemnet_interface->boundto)); instance->netif_state_report = NETIF_STATE_REPORT_DOWN; instance->totemnet_iface_change_fn (instance->context, &instance->my_id); @@ -894,7 +891,14 @@ static int totemnet_build_sockets_loopback ( */ sockets->token = socket (bound_to->family, SOCK_DGRAM, 0); if (sockets->token == -1) { - perror ("socket2"); + perror ("cannot create socket"); + return (-1); + } + + totemip_nosigpipe (sockets->token); + res = fcntl (sockets->token, F_SETFL, O_NONBLOCK); + if (res == -1) { + instance->totemnet_log_printf (instance->totemnet_log_level_warning, "Could not set non-blocking operation on token socket: %s\n", strerror (errno)); return (-1); } @@ -905,7 +909,7 @@ static int totemnet_build_sockets_loopback ( totemip_totemip_to_sockaddr_convert(bound_to, instance->totem_config->ip_port, &sockaddr, &addrlen); res = bind (sockets->token, (struct sockaddr *)&sockaddr, addrlen); if (res == -1) { - perror ("bind2 failed"); + perror ("bind token socket failed"); return (-1); } @@ -918,146 +922,15 @@ static int totemnet_build_sockets_loopback ( that our messages don't get queued behind anything else */ static void totemnet_traffic_control_set(struct totemnet_instance *instance, int sock) { +#ifdef SO_PRIORITY int prio = 6; /* TC_PRIO_INTERACTIVE */ if (setsockopt(sock, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(int))) instance->totemnet_log_printf (instance->totemnet_log_level_warning, "Could not set traffic priority. (%s)\n", strerror (errno)); +#endif } -static int totemnet_build_sockets_ipv4 ( - struct totemnet_instance *instance, - struct totem_ip_address *mcast_address, - struct totem_ip_address *bindnet_address, - struct totemnet_socket *sockets, - struct totem_ip_address *bound_to, - int *interface_up) -{ - struct ip_mreq mreq; - struct sockaddr_storage bound_ss; - struct sockaddr_in *bound_sin = (struct sockaddr_in *)&bound_ss; - struct sockaddr_storage mcast_ss; - struct sockaddr_in *mcast_sin = (struct sockaddr_in *)&mcast_ss; - struct sockaddr_storage sockaddr; - unsigned int sendbuf_size; - unsigned int recvbuf_size; - unsigned int optlen = sizeof (sendbuf_size); - int flag; - int addrlen; - int res; - - /* - * Create multicast socket - */ - sockets->mcast_send = socket (AF_INET, SOCK_DGRAM, 0); - if (sockets->mcast_send == -1) { - perror ("socket"); - return (-1); - } - res = fcntl (sockets->mcast_send, F_SETFL, O_NONBLOCK); - if (res == -1) { - instance->totemnet_log_printf (instance->totemnet_log_level_warning, "Could not set non-blocking operation on multicast socket: %s\n", strerror (errno)); - } - - /* - * Bind to multicast socket used for multicast send/receives - */ - totemip_totemip_to_sockaddr_convert(mcast_address, instance->totem_config->ip_port, &sockaddr, &addrlen); - res = bind (sockets->mcast_send, (struct sockaddr *)&sockaddr, addrlen); - if (res == -1) { - instance->totemnet_log_printf (instance->totemnet_log_level_error, "Bind to mcast send socket failed (reason=%s)\n", strerror(errno)); - return (-1); - } - - /* - * Setup unicast socket - */ - sockets->token = socket (AF_INET, SOCK_DGRAM, 0); - if (sockets->token == -1) { - perror ("socket2"); - return (-1); - } - res = fcntl (sockets->mcast_send, F_SETFL, O_NONBLOCK); - if (res == -1) { - instance->totemnet_log_printf (instance->totemnet_log_level_warning, "Could not set non-blocking operation on token socket: %s\n", strerror (errno)); - } - - /* - * Bind to unicast socket used for token send/receives - * This has the side effect of binding to the correct interface - */ - totemip_totemip_to_sockaddr_convert(bound_to, instance->totem_config->ip_port, &sockaddr, &addrlen); - res = bind (sockets->token, (struct sockaddr *)&sockaddr, addrlen); - if (res == -1) { - perror ("bind2 failed"); - return (-1); - } - - totemip_totemip_to_sockaddr_convert(bound_to, instance->totem_config->ip_port, &bound_ss, &addrlen); - totemip_totemip_to_sockaddr_convert(mcast_address, instance->totem_config->ip_port, &mcast_ss, &addrlen); - memset (&mreq, 0, sizeof (struct ip_mreq)); - - if (setsockopt (sockets->mcast_send, SOL_IP, IP_MULTICAST_IF, - &bound_sin->sin_addr, sizeof (struct in_addr)) < 0) { - - instance->totemnet_log_printf (instance->totemnet_log_level_warning, "Could not bind to device for multicast, group messaging may not work properly. (%s)\n", strerror (errno)); - } - - recvbuf_size = MCAST_SOCKET_BUFFER_SIZE; - sendbuf_size = MCAST_SOCKET_BUFFER_SIZE; - /* - * Set buffer sizes to avoid overruns - */ - res = setsockopt (sockets->mcast_send, SOL_SOCKET, SO_RCVBUF, &recvbuf_size, optlen); - res = setsockopt (sockets->mcast_send, SOL_SOCKET, SO_SNDBUF, &sendbuf_size, optlen); - - res = getsockopt (sockets->mcast_send, SOL_SOCKET, SO_RCVBUF, &recvbuf_size, &optlen); - if (res == 0) { - instance->totemnet_log_printf (instance->totemnet_log_level_notice, - "Multicast socket send buffer size (%d bytes).\n", recvbuf_size); - } - - res = getsockopt (sockets->mcast_send, SOL_SOCKET, SO_SNDBUF, &sendbuf_size, - &optlen); - if (res == 0) { - instance->totemnet_log_printf (instance->totemnet_log_level_notice, - "Multicast socket send buffer size (%d bytes).\n", sendbuf_size); - } - - /* - * Join group membership - */ - mreq.imr_multiaddr.s_addr = mcast_sin->sin_addr.s_addr; - mreq.imr_interface.s_addr = bound_sin->sin_addr.s_addr; - - res = setsockopt (sockets->mcast_send, SOL_IP, IP_ADD_MEMBERSHIP, - &mreq, sizeof (mreq)); - if (res == -1) { - perror ("join ipv4 multicast group failed"); - return (-1); - } - - /* - * Turn on multicast loopback - */ - flag = 1; - res = setsockopt (sockets->mcast_send, IPPROTO_IP, IP_MULTICAST_LOOP, - &flag, sizeof (flag)); - if (res == -1) { - perror ("turn off loopback"); - return (-1); - } - - /* - * ipv4 binds to a network address, not a network interface like - * ipv6. So it is acceptable to utilize the same file descriptor - * for both send and receive since outgoing packets will be - * set with the correct source address - */ - sockets->mcast_recv = sockets->mcast_send; - return (0); -} - -static int totemnet_build_sockets_ipv6 ( +static int totemnet_build_sockets_ip ( struct totemnet_instance *instance, struct totem_ip_address *mcast_address, struct totem_ip_address *bindnet_address, @@ -1067,76 +940,112 @@ static int totemnet_build_sockets_ipv6 ( int interface_num) { struct sockaddr_storage sockaddr; - struct ipv6_mreq mreq; - struct sockaddr_storage mcast_ss; - struct sockaddr_in6 *mcast_sin = (struct sockaddr_in6 *)&mcast_ss; + struct ipv6_mreq mreq6; + struct ip_mreq mreq; + struct sockaddr_storage mcast_ss, boundto_ss; + struct sockaddr_in6 *mcast_sin6 = (struct sockaddr_in6 *)&mcast_ss; + struct sockaddr_in *mcast_sin = (struct sockaddr_in *)&mcast_ss; + struct sockaddr_in *boundto_sin = (struct sockaddr_in *)&boundto_ss; unsigned int sendbuf_size; unsigned int recvbuf_size; unsigned int optlen = sizeof (sendbuf_size); int addrlen; int res; int flag; - + /* * Create multicast recv socket */ - sockets->mcast_recv = socket (AF_INET6, SOCK_DGRAM, 0); + sockets->mcast_recv = socket (bindnet_address->family, SOCK_DGRAM, 0); if (sockets->mcast_recv == -1) { perror ("socket"); return (-1); } + + totemip_nosigpipe (sockets->mcast_recv); res = fcntl (sockets->mcast_recv, F_SETFL, O_NONBLOCK); if (res == -1) { - instance->totemnet_log_printf (instance->totemnet_log_level_warning, "Could not set non-blocking operation on multicast recv socket: %s\n", strerror (errno)); + instance->totemnet_log_printf (instance->totemnet_log_level_warning, "Could not set non-blocking operation on multicast socket: %s\n", strerror (errno)); + return (-1); } + /* + * Force reuse + */ + flag = 1; + if ( setsockopt(sockets->mcast_recv, SOL_SOCKET, SO_REUSEADDR, (char *)&flag, sizeof (flag)) < 0) { + perror("setsockopt reuseaddr"); + return (-1); + } /* * Bind to multicast socket used for multicast receives */ totemip_totemip_to_sockaddr_convert(mcast_address, instance->totem_config->ip_port, &sockaddr, &addrlen); - res = bind (sockets->mcast_recv, (struct sockaddr *)&sockaddr, addrlen); if (res == -1) { - instance->totemnet_log_printf (instance->totemnet_log_level_error, "Bind to mcast recv socket failed (reason=%s)\n", strerror(errno)); + perror ("bind mcast recv socket failed"); return (-1); } /* * Setup mcast send socket */ - sockets->mcast_send = socket (AF_INET6, SOCK_DGRAM, 0); + sockets->mcast_send = socket (bindnet_address->family, SOCK_DGRAM, 0); if (sockets->mcast_send == -1) { perror ("socket"); return (-1); } + + totemip_nosigpipe (sockets->mcast_send); res = fcntl (sockets->mcast_send, F_SETFL, O_NONBLOCK); if (res == -1) { - instance->totemnet_log_printf (instance->totemnet_log_level_warning, "Could not set non-blocking operation on multicast send socket: %s\n", strerror (errno)); + instance->totemnet_log_printf (instance->totemnet_log_level_warning, "Could not set non-blocking operation on multicast socket: %s\n", strerror (errno)); + return (-1); + } + + /* + * Force reuse + */ + flag = 1; + if ( setsockopt(sockets->mcast_send, SOL_SOCKET, SO_REUSEADDR, (char *)&flag, sizeof (flag)) < 0) { + perror("setsockopt reuseaddr"); + return (-1); } totemip_totemip_to_sockaddr_convert(bound_to, instance->totem_config->ip_port - 1, &sockaddr, &addrlen); res = bind (sockets->mcast_send, (struct sockaddr *)&sockaddr, addrlen); if (res == -1) { - perror ("bind2 failed"); + perror ("bind mcast send socket failed"); return (-1); } /* * Setup unicast socket */ - sockets->token = socket (AF_INET6, SOCK_DGRAM, 0); + sockets->token = socket (bindnet_address->family, SOCK_DGRAM, 0); if (sockets->token == -1) { perror ("socket2"); return (-1); } + + totemip_nosigpipe (sockets->token); res = fcntl (sockets->token, F_SETFL, O_NONBLOCK); if (res == -1) { instance->totemnet_log_printf (instance->totemnet_log_level_warning, "Could not set non-blocking operation on token socket: %s\n", strerror (errno)); + return (-1); } + /* + * Force reuse + */ + flag = 1; + if ( setsockopt(sockets->token, SOL_SOCKET, SO_REUSEADDR, (char *)&flag, sizeof (flag)) < 0) { + perror("setsockopt reuseaddr"); + return (-1); + } /* * Bind to unicast socket used for token send/receives @@ -1145,75 +1054,126 @@ static int totemnet_build_sockets_ipv6 ( totemip_totemip_to_sockaddr_convert(bound_to, instance->totem_config->ip_port, &sockaddr, &addrlen); res = bind (sockets->token, (struct sockaddr *)&sockaddr, addrlen); if (res == -1) { - perror ("bind2 failed"); + perror ("bind token socket failed"); return (-1); } - recvbuf_size = MCAST_SOCKET_BUFFER_SIZE; - sendbuf_size = MCAST_SOCKET_BUFFER_SIZE; - /* - * Set buffer sizes to avoid overruns - */ - res = setsockopt (sockets->mcast_recv, SOL_SOCKET, SO_RCVBUF, &recvbuf_size, optlen); - res = setsockopt (sockets->mcast_send, SOL_SOCKET, SO_SNDBUF, &sendbuf_size, optlen); + recvbuf_size = MCAST_SOCKET_BUFFER_SIZE; + sendbuf_size = MCAST_SOCKET_BUFFER_SIZE; + /* + * Set buffer sizes to avoid overruns + */ + res = setsockopt (sockets->mcast_recv, SOL_SOCKET, SO_RCVBUF, &recvbuf_size, optlen); + res = setsockopt (sockets->mcast_send, SOL_SOCKET, SO_SNDBUF, &sendbuf_size, optlen); - res = getsockopt (sockets->mcast_recv, SOL_SOCKET, SO_RCVBUF, &recvbuf_size, &optlen); - if (res == 0) { - instance->totemnet_log_printf (instance->totemnet_log_level_notice, - "Receive multicast socket recv buffer size (%d bytes).\n", recvbuf_size); -} + res = getsockopt (sockets->mcast_recv, SOL_SOCKET, SO_RCVBUF, &recvbuf_size, &optlen); + if (res == 0) { + instance->totemnet_log_printf (instance->totemnet_log_level_notice, + "Receive multicast socket recv buffer size (%d bytes).\n", recvbuf_size); + } - res = getsockopt (sockets->mcast_send, SOL_SOCKET, SO_SNDBUF, &sendbuf_size, &optlen); - if (res == 0) { - instance->totemnet_log_printf (instance->totemnet_log_level_notice, - "Transmit multicat socket send buffer size (%d bytes).\n", sendbuf_size); - } + res = getsockopt (sockets->mcast_send, SOL_SOCKET, SO_SNDBUF, &sendbuf_size, &optlen); + if (res == 0) { + instance->totemnet_log_printf (instance->totemnet_log_level_notice, + "Transmit multicat socket send buffer size (%d bytes).\n", sendbuf_size); + } /* * Join group membership on socket */ - totemip_totemip_to_sockaddr_convert(mcast_address, - instance->totem_config->ip_port, &mcast_ss, &addrlen); - memset(&mreq, 0, sizeof(mreq)); - memcpy(&mreq.ipv6mr_multiaddr, &mcast_sin->sin6_addr, sizeof(struct in6_addr)); - mreq.ipv6mr_interface = interface_num; + totemip_totemip_to_sockaddr_convert(mcast_address, instance->totem_config->ip_port, &mcast_ss, &addrlen); + totemip_totemip_to_sockaddr_convert(bound_to, instance->totem_config->ip_port, &boundto_ss, &addrlen); - res = setsockopt (sockets->mcast_recv, SOL_IPV6, IPV6_ADD_MEMBERSHIP, - &mreq, sizeof (mreq)); - if (res == -1) { - perror ("join ipv6 multicast group failed"); - return (-1); + switch ( bindnet_address->family ) { + case AF_INET: + memset(&mreq, 0, sizeof(mreq)); + mreq.imr_multiaddr.s_addr = mcast_sin->sin_addr.s_addr; + mreq.imr_interface.s_addr = boundto_sin->sin_addr.s_addr; + res = setsockopt (sockets->mcast_send, IPPROTO_IP, IP_ADD_MEMBERSHIP, + &mreq, sizeof (mreq)); + if (res == -1) { + perror ("join ipv4 multicast group failed"); + return (-1); + } + break; + case AF_INET6: + memset(&mreq6, 0, sizeof(mreq6)); + memcpy(&mreq6.ipv6mr_multiaddr, &mcast_sin6->sin6_addr, sizeof(struct in6_addr)); + mreq6.ipv6mr_interface = interface_num; + + res = setsockopt (sockets->mcast_recv, IPPROTO_IPV6, IPV6_JOIN_GROUP, + &mreq6, sizeof (mreq6)); + if (res == -1) { + perror ("join ipv6 multicast group failed"); + return (-1); + } + break; } - + /* * Turn on multicast loopback */ + flag = 1; - res = setsockopt (sockets->mcast_send, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, - &flag, sizeof (flag)); + switch ( bindnet_address->family ) { + case AF_INET: + res = setsockopt (sockets->mcast_send, IPPROTO_IP, IP_MULTICAST_LOOP, + &flag, sizeof (flag)); + break; + case AF_INET6: + res = setsockopt (sockets->mcast_send, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, + &flag, sizeof (flag)); + } if (res == -1) { perror ("turn off loopback"); return (-1); } - flag = 255; - res = setsockopt (sockets->mcast_send, SOL_IPV6, IPV6_MULTICAST_HOPS, - &flag, sizeof (flag)); - if (res == -1) { - perror ("setp mcast hops"); - return (-1); + /* + * Set multicast packets TTL + */ + + if ( bindnet_address->family == AF_INET6 ) + { + flag = 255; + res = setsockopt (sockets->mcast_send, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, + &flag, sizeof (flag)); + if (res == -1) { + perror ("setp mcast hops"); + return (-1); + } } /* * Bind to a specific interface for multicast send and receive */ - if (setsockopt (sockets->mcast_send, IPPROTO_IPV6, IPV6_MULTICAST_IF, - &interface_num, sizeof (interface_num)) < 0) { - } - - if (setsockopt (sockets->mcast_recv, IPPROTO_IPV6, IPV6_MULTICAST_IF, - &interface_num, sizeof (interface_num)) < 0) { + switch ( bindnet_address->family ) { + case AF_INET: + if (setsockopt (sockets->mcast_send, IPPROTO_IP, IP_MULTICAST_IF, + &boundto_sin->sin_addr, sizeof (boundto_sin->sin_addr)) < 0) { + perror ("cannot select interface"); + return (-1); + } + if (setsockopt (sockets->mcast_recv, IPPROTO_IP, IP_MULTICAST_IF, + &boundto_sin->sin_addr, sizeof (boundto_sin->sin_addr)) < 0) { + perror ("cannot select interface"); + return (-1); + } + break; + case AF_INET6: + if (setsockopt (sockets->mcast_send, IPPROTO_IPV6, IPV6_MULTICAST_IF, + &interface_num, sizeof (interface_num)) < 0) { + perror ("cannot select interface"); + return (-1); + } + if (setsockopt (sockets->mcast_recv, IPPROTO_IPV6, IPV6_MULTICAST_IF, + &interface_num, sizeof (interface_num)) < 0) { + perror ("cannot select interface"); + return (-1); + } + break; } + return 0; } @@ -1234,7 +1194,7 @@ static int totemnet_build_sockets ( res = netif_determine (instance, bindnet_address, bound_to, - interface_up, + interface_up, &interface_num); if (res == -1) { @@ -1243,13 +1203,8 @@ static int totemnet_build_sockets ( totemip_copy(&instance->my_id, bound_to); - if (mcast_address->family== AF_INET) - res = totemnet_build_sockets_ipv4 (instance, mcast_address, - bindnet_address, sockets, bound_to, interface_up); - else { - res = totemnet_build_sockets_ipv6 (instance, mcast_address, + res = totemnet_build_sockets_ip (instance, mcast_address, bindnet_address, sockets, bound_to, interface_up, interface_num); - } /* We only send out of the token socket */ totemnet_traffic_control_set(instance, sockets->token); diff --git a/exec/totemrrp.c b/exec/totemrrp.c index 8746c104..dc3b2828 100644 --- a/exec/totemrrp.c +++ b/exec/totemrrp.c @@ -41,13 +41,10 @@ #include #include #include -#include #include #include #include #include -#include -#include #include #include #include diff --git a/exec/totemsrp.c b/exec/totemsrp.c index d90629ce..a8019bcb 100644 --- a/exec/totemsrp.c +++ b/exec/totemsrp.c @@ -55,13 +55,10 @@ #include #include #include -#include #include #include #include #include -#include -#include #include #include #include diff --git a/exec/ykd.c b/exec/ykd.c index e87b44bb..2d83f07b 100644 --- a/exec/ykd.c +++ b/exec/ykd.c @@ -42,7 +42,6 @@ #include #include #include -#include #include #include #include diff --git a/include/evs.h b/include/evs.h index d0b30092..01cb6846 100644 --- a/include/evs.h +++ b/include/evs.h @@ -34,9 +34,10 @@ #ifndef OPENAIS_EVS_H_DEFINED #define OPENAIS_EVS_H_DEFINED +#include #include -typedef uint64_t evs_handle_t; +typedef u_int64_t evs_handle_t; typedef enum { EVS_DISPATCH_ONE, diff --git a/lcr/Makefile b/lcr/Makefile index e03ecf0f..09473950 100755 --- a/lcr/Makefile +++ b/lcr/Makefile @@ -21,37 +21,43 @@ # 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. -# Production mode flags -CFLAGS = -O3 -Wall -fomit-frame-pointer -LDFLAGS = -rdynamic -# Debug mode flags -#CFLAGS = -g -Wall -#LDFLAGS = -g -L./ -rdynamic +# Include configuration +# +include ../Makefile.inc -# Profile mode flags -#CFLAGS = -O3 -pg -DDEBUG -#LDFLAGS = -pg +CFLAGS += -I../include +LDFLAGS += -L./ ${DYFLAGS} -# Code Coverage with lcov flgs -#CFLAGS = -ftest-coverage -fprofile-arcs -#LDFLAGS = -g - -LDFLAGS += -ldl +ifeq (${OPENAIS_COMPAT}, LINUX) + LDFLAGS += -ldl +endif all:liblcr.a test test_static uic libtest_a.lcrso libtest_b.lcrso liblcr.a: lcr_ifact.o $(AR) -rc liblcr.a lcr_ifact.o +ifeq (${OPENAIS_COMPAT}, DARWIN) + +libtest_a.lcrso: libtest_a.o + $(CC) $(CFLAGS) -bundle -bundle_loader ./test libtest_a.o -o $@ + +libtest_b.lcrso: libtest_b.o + $(CC) $(CFLAGS) -bundle -bundle_loader ./test libtest_b.o -o $@ + +else + libtest_a.lcrso: libtest_a.o $(CC) $(CFLAGS) -shared -Wl,-soname,libtest_b.lcrso libtest_a.o -o $@ libtest_b.lcrso: libtest_b.o $(CC) $(CFLAGS) -shared -Wl,-soname,libtest_b.lcrso libtest_b.o -o $@ + +endif test: test.o uis.o lcr_ifact.o - $(CC) $(LDFLAGS) test.o lcr_ifact.o uis.o -lpthread -ldl -o test + $(CC) $(LDFLAGS) test.o lcr_ifact.o uis.o -lpthread -o test 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 237f457a..0331d6f8 100644 --- a/lcr/lcr_ifact.c +++ b/lcr/lcr_ifact.c @@ -166,7 +166,7 @@ int lcr_ifact_reference ( */ scandir_entries = scandir(".", &scandir_list, lcr_select_so, alphasort); if (scandir_entries < 0) - printf ("scandir error reason=%d\n", strerror (errno)); + printf ("scandir error reason=%s\n", strerror (errno)); else /* * no error so load the object diff --git a/lcr/libtest_a.c b/lcr/libtest_a.c index 498e159c..bdf8ddf4 100644 --- a/lcr/libtest_a.c +++ b/lcr/libtest_a.c @@ -156,8 +156,7 @@ static void iface1_ver1_func3 (void) { printf ("A - version 1 func3\n"); } -static void register_this_component (void) { +__attribute__ ((constructor)) static void register_this_component (void) { lcr_component_register (&test_comp); } -void (*const __init_libtest_a[1]) (void) __attribute__ ((section(".ctors"))) = { register_this_component }; diff --git a/lcr/libtest_b.c b/lcr/libtest_b.c index c9d54d64..6a3591a6 100644 --- a/lcr/libtest_b.c +++ b/lcr/libtest_b.c @@ -162,10 +162,8 @@ static void iface1_ver1_func3 (void) { printf ("B - version 1 func3\n"); } -static void register_this_component (void) +__attribute__ ((constructor)) static void register_this_component (void) { lcr_component_register (&test_comp); } -void (*const __init_libtest_b[1]) (void) __attribute__ ((section(".ctors"))) = { register_this_component }; - diff --git a/lcr/uic.c b/lcr/uic.c index 9919a980..93b22094 100755 --- a/lcr/uic.c +++ b/lcr/uic.c @@ -29,9 +29,9 @@ */ #include #include +#include #include #include -#include #include #include #include @@ -46,8 +46,19 @@ #include #include #include +#include -char *socketname = "lcr.uis.socket"; +#if defined(OPENAIS_LINUX) +/* SUN_LEN is broken for abstract namespace + */ +#define AIS_SUN_LEN(a) sizeof(*(a)) + +static char *socketname = "lcr.socket"; +#else +#define AIS_SUN_LEN(a) SUN_LEN(a) + +static char *socketname = "/var/run/lcr.socket"; +#endif int uic_connect (int *fd) { @@ -55,13 +66,20 @@ int uic_connect (int *fd) struct sockaddr_un addr; memset (&addr, 0, sizeof (struct sockaddr_un)); +#if defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN) + addr.sun_len = sizeof(struct sockaddr_un); +#endif addr.sun_family = PF_UNIX; - strcpy (addr.sun_path + 1, "lcr.socket"); +#if defined(OPENAIS_LINUX) + strcpy (addr.sun_path + 1, socketname); +#else + strcpy (addr.sun_path, socketname); +#endif *fd = socket (PF_UNIX, SOCK_STREAM, 0); if (*fd == -1) { return -errno; } - res = connect (*fd, (struct sockaddr *)&addr, sizeof (addr)); + res = connect (*fd, (struct sockaddr *)&addr, AIS_SUN_LEN(&addr)); if (res == -1) { return -errno; } diff --git a/lcr/uis.c b/lcr/uis.c index 6620bb47..d4e728f9 100755 --- a/lcr/uis.c +++ b/lcr/uis.c @@ -29,9 +29,9 @@ */ #include #include +#include #include #include -#include #include #include #include @@ -46,10 +46,21 @@ #include #include #include +#include #define SERVER_BACKLOG 5 -char *socketname = "lcr.socket"; +#if defined(OPENAIS_LINUX) +/* SUN_LEN is broken for abstract namespace + */ +#define AIS_SUN_LEN(a) sizeof(*(a)) + +static char *socketname = "lcr.socket"; +#else +#define AIS_SUN_LEN(a) SUN_LEN(a) + +static char *socketname = "/var/run/lcr.socket"; +#endif static void uis_lcr_bind (int *server_fd) { @@ -65,11 +76,21 @@ static void uis_lcr_bind (int *server_fd) printf ("lcr_bind failed\n"); }; +#if !defined(OPENAIS_LINUX) + unlink(socketname); +#endif memset (&un_addr, 0, sizeof (struct sockaddr_un)); +#if defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN) + un_addr.sun_len = sizeof(struct sockaddr_un); +#endif un_addr.sun_family = AF_UNIX; +#if defined(OPENAIS_LINUX) strcpy (un_addr.sun_path + 1, socketname); +#else + strcpy (un_addr.sun_path, socketname); +#endif - res = bind (fd, (struct sockaddr *)&un_addr, sizeof (struct sockaddr_un)); + res = bind (fd, (struct sockaddr *)&un_addr, AIS_SUN_LEN(&un_addr)); if (res) { printf ("Could not bind AF_UNIX: %s\n", strerror (errno)); } @@ -114,7 +135,9 @@ static void *lcr_uis_server (void *data) struct sockaddr_un un_addr; socklen_t addrlen; int nfds = 1; +#ifdef OPENAIS_LINUX int on = 1; +#endif int res; /* @@ -129,8 +152,10 @@ static void *lcr_uis_server (void *data) if (nfds == 1 && ufds[0].revents & POLLIN) { ufds[1].fd = accept (ufds[0].fd, (struct sockaddr *)&un_addr, &addrlen); +#ifdef OPENAIS_LINUX setsockopt(ufds[1].fd, SOL_SOCKET, SO_PASSCRED, &on, sizeof (on)); +#endif nfds = 2; } if (ufds[0].revents & POLLIN) { @@ -142,7 +167,7 @@ static void *lcr_uis_server (void *data) return 0; } -static int lcr_uis_ctors (void) +__attribute__ ((constructor)) static int lcr_uis_ctors (void) { pthread_t thread; @@ -151,5 +176,3 @@ static int lcr_uis_ctors (void) return (0); } -static int (*const __init_uis[1]) (void) __attribute__ ((section(".ctors"))) = - { lcr_uis_ctors }; diff --git a/lib/Makefile b/lib/Makefile index 21afccb5..a099d26b 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -27,21 +27,13 @@ # 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. -# Production mode flags -#CFLAGS = -O3 -Wall -#LDFLAGS = -# Debug mode flags -CFLAGS = -g -DDEBUG -Wall -LDFLAGS = -g +# Include configuration +# +include ../Makefile.inc -# Profile mode flags -#CFLAGS = -O3 -pg -DDEBUG -#LDFLAGS = -pg - -# Code Coverage with lcov flgs -#CFLAGS = -ftest-coverage -fprofile-arcs -#LDFLAGS = -g +CFLAGS += -I../include +LDFLAGS += -L./ all:libSaClm.a libSaClm.so.1.0 libSaAmf.a libSaAmf.so.1.0 libSaCkpt.a \ libSaCkpt.so.1.0 libSaEvt.a libSaEvt.so.1.0 libSaLck.a libSaLck.so.1.0 libSaMsg.a libSaMsg.so.1.0 \ @@ -54,69 +46,99 @@ LIBEVS_SRC = util.c evs.c libSaClm.a: util.o clm.o $(AR) -rc libSaClm.a util.o clm.o +ifeq (${OPENAIS_COMPAT}, DARWIN) + +libSaClm.so.1.0: util.o clm.o + $(CC) -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) -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) -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) -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) -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) -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) -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) -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 + +else + libSaClm.so.1.0: util.o clm.o $(CC) -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.a: util.o amf.o - $(AR) -rc libSaAmf.a util.o amf.o - libSaAmf.so.1.0: util.o amf.o $(CC) -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.a: util.o ckpt.o - $(AR) -rc libSaCkpt.a util.o ckpt.o - libSaCkpt.so.1.0: util.o ckpt.o $(CC) -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.a: util.o evt.o - $(AR) -rc libSaEvt.a util.o evt.o - libSaEvt.so.1.0: util.o evt.o $(CC) -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.a: util.o lck.o - $(AR) -rc libSaLck.a util.o lck.o - libSaLck.so.1.0: util.o lck.o $(CC) -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 -libSaMsg.a: util.o msg.o - $(AR) -rc libSaMsg.a util.o msg.o - libSaMsg.so.1.0: util.o msg.o $(CC) -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.a: util.o amf.o clm.o ckpt.o evt.o msg.o - $(AR) -rc libais.a util.o amf.o clm.o ckpt.o evt.o msg.o - libais.so.1.0: util.o amf.o clm.o ckpt.o evt.o lck.o msg.o - $(CC) -shared -Wl,-soname,libais.so.1,-version-script=libSaAis.versions util.o amf.o clm.o ckpt.o \ - evt.o -o $@ + $(CC) -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.a: util.o evs.o - $(AR) -rc libevs.a util.o evs.o libevs.so.1.0: util.o evs.o $(CC) -shared -Wl,-soname,libevs.so.1,-version-script=libevs.versions util.o evs.o -o $@ @@ -124,6 +146,30 @@ libevs.so.1.0: util.o evs.o ln -s libevs.so.1.0 libevs.so.1 ln -s libevs.so.1.0 libevs.so +endif + +libSaAmf.a: util.o amf.o + $(AR) -rc libSaAmf.a util.o amf.o + +libSaCkpt.a: util.o ckpt.o + $(AR) -rc libSaCkpt.a util.o ckpt.o + +libSaEvt.a: util.o evt.o + $(AR) -rc libSaEvt.a util.o evt.o + +libSaLck.a: util.o lck.o + $(AR) -rc libSaLck.a util.o lck.o + +libSaMsg.a: util.o msg.o + $(AR) -rc libSaMsg.a util.o msg.o + +libais.a: util.o amf.o clm.o ckpt.o evt.o msg.o + $(AR) -rc libais.a util.o amf.o clm.o ckpt.o evt.o msg.o + +libevs.a: util.o evs.o + $(AR) -rc libevs.a util.o evs.o + + clean: rm -f *.o libais.so* libais.a libSaClm.so* libSaClm.a* libSaAmf.so* libSaAmf.a \ libSaCkpt.so* libSaCkpt.a* libSaEvt.so* libSaEvt.a libSaLck.so* libSaLck.a \ diff --git a/lib/ckpt.c b/lib/ckpt.c index 5e35f0bf..7db4fc60 100644 --- a/lib/ckpt.c +++ b/lib/ckpt.c @@ -622,7 +622,7 @@ saCkptCheckpointOpen ( req_lib_ckpt_checkpointopen.checkpointOpenFlags = checkpointOpenFlags; error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_checkpointopen, - sizeof (struct req_lib_ckpt_checkpointopen), MSG_NOSIGNAL); + sizeof (struct req_lib_ckpt_checkpointopen)); if (error != SA_AIS_OK) { goto error_put_destroy; } @@ -749,7 +749,7 @@ saCkptCheckpointOpenAsync ( req_lib_ckpt_checkpointopenasync.checkpointHandle = checkpointHandle; error = saSendRetry (ckptInstance->response_fd, &req_lib_ckpt_checkpointopenasync, - sizeof (struct req_lib_ckpt_checkpointopenasync), MSG_NOSIGNAL); + sizeof (struct req_lib_ckpt_checkpointopenasync)); if (error != SA_AIS_OK) { goto error_put_destroy; @@ -806,7 +806,7 @@ saCkptCheckpointClose ( &ckptCheckpointInstance->checkpointName, sizeof (SaNameT)); error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_checkpointclose, - sizeof (struct req_lib_ckpt_checkpointclose), MSG_NOSIGNAL); + sizeof (struct req_lib_ckpt_checkpointclose)); if (error != SA_AIS_OK) { goto exit_put; } @@ -853,7 +853,7 @@ saCkptCheckpointUnlink ( error = saSendRetry (ckptInstance->response_fd, &req_lib_ckpt_checkpointunlink, - sizeof (struct req_lib_ckpt_checkpointunlink), MSG_NOSIGNAL); + sizeof (struct req_lib_ckpt_checkpointunlink)); if (error != SA_AIS_OK) { goto exit_put; } @@ -895,7 +895,7 @@ saCkptCheckpointRetentionDurationSet ( pthread_mutex_lock (&ckptCheckpointInstance->response_mutex); - error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_checkpointretentiondurationset, sizeof (struct req_lib_ckpt_checkpointretentiondurationset), MSG_NOSIGNAL); + error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_checkpointretentiondurationset, sizeof (struct req_lib_ckpt_checkpointretentiondurationset)); if (error != SA_AIS_OK) { goto error_exit; } @@ -940,7 +940,7 @@ saCkptActiveReplicaSet ( pthread_mutex_lock (&ckptCheckpointInstance->response_mutex); error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_activereplicaset, - sizeof (struct req_lib_ckpt_activereplicaset), MSG_NOSIGNAL); + sizeof (struct req_lib_ckpt_activereplicaset)); if (error != SA_AIS_OK) { goto error_put; } @@ -985,7 +985,7 @@ saCkptCheckpointStatusGet ( pthread_mutex_lock (&ckptCheckpointInstance->response_mutex); error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_checkpointstatusget, - sizeof (struct req_lib_ckpt_checkpointstatusget), MSG_NOSIGNAL); + sizeof (struct req_lib_ckpt_checkpointstatusget)); if (error != SA_AIS_OK) { goto error_exit; } @@ -1055,7 +1055,7 @@ saCkptSectionCreate ( pthread_mutex_lock (&ckptCheckpointInstance->response_mutex); error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_sectioncreate, - sizeof (struct req_lib_ckpt_sectioncreate), MSG_NOSIGNAL); + sizeof (struct req_lib_ckpt_sectioncreate)); if (error != SA_AIS_OK) { goto error_exit; } @@ -1064,13 +1064,13 @@ saCkptSectionCreate ( * Write section identifier to server */ error = saSendRetry (ckptCheckpointInstance->response_fd, sectionCreationAttributes->sectionId->id, - sectionCreationAttributes->sectionId->idLen, MSG_NOSIGNAL); + sectionCreationAttributes->sectionId->idLen); if (error != SA_AIS_OK) { goto error_exit; } error = saSendRetry (ckptCheckpointInstance->response_fd, initialData, - initialDataSize, MSG_NOSIGNAL); + initialDataSize); if (error != SA_AIS_OK) { goto error_exit; } @@ -1123,7 +1123,7 @@ saCkptSectionDelete ( &ckptCheckpointInstance->checkpointName, sizeof (SaNameT)); error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_sectiondelete, - sizeof (struct req_lib_ckpt_sectiondelete), MSG_NOSIGNAL); + sizeof (struct req_lib_ckpt_sectiondelete)); if (error != SA_AIS_OK) { goto error_exit; } @@ -1132,7 +1132,7 @@ saCkptSectionDelete ( * Write section identifier to server */ error = saSendRetry (ckptCheckpointInstance->response_fd, sectionId->id, - sectionId->idLen, MSG_NOSIGNAL); + sectionId->idLen); if (error != SA_AIS_OK) { goto error_exit; } @@ -1186,7 +1186,7 @@ saCkptSectionExpirationTimeSet ( pthread_mutex_lock (&ckptCheckpointInstance->response_mutex); error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_sectionexpirationtimeset, - sizeof (struct req_lib_ckpt_sectionexpirationtimeset), MSG_NOSIGNAL); + sizeof (struct req_lib_ckpt_sectionexpirationtimeset)); if (error != SA_AIS_OK) { goto error_exit; } @@ -1196,7 +1196,7 @@ saCkptSectionExpirationTimeSet ( */ if (sectionId->idLen) { error = saSendRetry (ckptCheckpointInstance->response_fd, sectionId->id, - sectionId->idLen, MSG_NOSIGNAL); + sectionId->idLen); if (error != SA_AIS_OK) { goto error_exit; } @@ -1287,8 +1287,7 @@ saCkptSectionIterationInitialize ( error = saSendRetry (ckptSectionIterationInstance->response_fd, &req_lib_ckpt_sectioniterationinitialize, - sizeof (struct req_lib_ckpt_sectioniterationinitialize), - MSG_NOSIGNAL); + sizeof (struct req_lib_ckpt_sectioniterationinitialize)); if (error != SA_AIS_OK) { goto error_put_destroy; @@ -1354,7 +1353,7 @@ saCkptSectionIterationNext ( error = saSendRetry (ckptSectionIterationInstance->response_fd, &req_lib_ckpt_sectioniteratornext, - sizeof (struct req_lib_ckpt_sectioniteratornext), MSG_NOSIGNAL); + sizeof (struct req_lib_ckpt_sectioniteratornext)); if (error != SA_AIS_OK) { goto error_put_unlock; @@ -1426,7 +1425,7 @@ saCkptSectionIterationFinalize ( error = saSendRetry (ckptSectionIterationInstance->response_fd, &req_lib_ckpt_sectioniterationfinalize, - sizeof (struct req_lib_ckpt_sectioniterationfinalize), MSG_NOSIGNAL); + sizeof (struct req_lib_ckpt_sectioniterationfinalize)); if (error != SA_AIS_OK) { goto error_put; @@ -1587,19 +1586,19 @@ saCkptSectionOverwrite ( pthread_mutex_lock (&ckptCheckpointInstance->response_mutex); error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_sectionoverwrite, - sizeof (struct req_lib_ckpt_sectionoverwrite), MSG_NOSIGNAL); + sizeof (struct req_lib_ckpt_sectionoverwrite)); if (error != SA_AIS_OK) { goto error_exit; } if (sectionId->idLen) { error = saSendRetry (ckptCheckpointInstance->response_fd, sectionId->id, - sectionId->idLen, MSG_NOSIGNAL); + sectionId->idLen); if (error != SA_AIS_OK) { goto error_exit; } } - error = saSendRetry (ckptCheckpointInstance->response_fd, dataBuffer, dataSize, MSG_NOSIGNAL); + error = saSendRetry (ckptCheckpointInstance->response_fd, dataBuffer, dataSize); if (error != SA_AIS_OK) { goto error_exit; } @@ -1753,7 +1752,7 @@ saCkptCheckpointSynchronize ( pthread_mutex_lock (&ckptCheckpointInstance->response_mutex); error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_checkpointsynchronize, - sizeof (struct req_lib_ckpt_checkpointsynchronize), MSG_NOSIGNAL); + sizeof (struct req_lib_ckpt_checkpointsynchronize)); if (error != SA_AIS_OK) { goto error_exit; @@ -1817,7 +1816,7 @@ saCkptCheckpointSynchronizeAsync ( pthread_mutex_lock (&ckptCheckpointInstance->response_mutex); error = saSendRetry (ckptCheckpointInstance->response_fd, &req_lib_ckpt_checkpointsynchronizeasync, - sizeof (struct req_lib_ckpt_checkpointsynchronizeasync), MSG_NOSIGNAL); + sizeof (struct req_lib_ckpt_checkpointsynchronizeasync)); if (error != SA_AIS_OK) { goto error_exit; diff --git a/lib/evt.c b/lib/evt.c index b900a2e9..80096e8d 100644 --- a/lib/evt.c +++ b/lib/evt.c @@ -723,8 +723,7 @@ saEvtDispatch( res.evd_head.size = sizeof(res); pthread_mutex_lock(&evti->ei_response_mutex); - error = saSendRetry(evti->ei_response_fd, &res, sizeof(res), - MSG_NOSIGNAL); + error = saSendRetry(evti->ei_response_fd, &res, sizeof(res)); if (error != SA_AIS_OK) { printf("MESSAGE_RES_EVT_AVAILABLE: send failed: %d\n", error); diff --git a/lib/util.c b/lib/util.c index 1dbcde19..73f0c5b7 100644 --- a/lib/util.c +++ b/lib/util.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -68,6 +69,26 @@ struct saHandle { uint32_t check; }; +#if defined(OPENAIS_LINUX) +/* SUN_LEN is broken for abstract namespace + */ +#define AIS_SUN_LEN(a) sizeof(*(a)) + +static char *socketname = "libais.socket"; +#else +#define AIS_SUN_LEN(a) SUN_LEN(a) + +static char *socketname = "/var/run/libais.socket"; +#endif + +#ifdef SO_NOSIGPIPE +void socket_nosigpipe(int s) +{ + int on = 1; + setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, (void *)&on, sizeof(on)); +} +#endif + SaAisErrorT saServiceConnect ( int *fdOut, @@ -80,7 +101,6 @@ saServiceConnect ( struct res_lib_response_init res_lib_response_init; SaAisErrorT error; gid_t egid; - int res; /* * Allow set group id binaries to be authenticated @@ -89,24 +109,38 @@ saServiceConnect ( setregid (egid, -1); memset (&address, 0, sizeof (struct sockaddr_un)); +#if defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN) + address.sun_len = sizeof(struct sockaddr_un); +#endif address.sun_family = PF_UNIX; - strcpy (address.sun_path + 1, "libais.socket"); +#if defined(OPENAIS_LINUX) + strcpy (address.sun_path + 1, socketname); +#else + strcpy (address.sun_path, socketname); +#endif fd = socket (PF_UNIX, SOCK_STREAM, 0); if (fd == -1) { return (SA_AIS_ERR_NO_RESOURCES); } - result = connect (fd, (struct sockaddr *)&address, sizeof (address)); + + socket_nosigpipe (fd); + + result = connect (fd, (struct sockaddr *)&address, AIS_SUN_LEN(&address)); + if (result == -1) { + return (SA_AIS_ERR_TRY_AGAIN); + } + + result = fcntl (fd, F_SETFL, O_NONBLOCK); if (result == -1) { return (SA_AIS_ERR_TRY_AGAIN); } - res = fcntl (fd, F_SETFL, O_NONBLOCK); req_lib_response_init.resdis_header.size = sizeof (req_lib_response_init); req_lib_response_init.resdis_header.id = MESSAGE_REQ_RESPONSE_INIT; req_lib_response_init.resdis_header.service = service; error = saSendRetry (fd, &req_lib_response_init, - sizeof (struct req_lib_response_init), MSG_NOSIGNAL); + sizeof (struct req_lib_response_init)); if (error != SA_AIS_OK) { goto error_exit; } @@ -147,7 +181,6 @@ saServiceConnectTwo ( struct res_lib_dispatch_init res_lib_dispatch_init; SaAisErrorT error; gid_t egid; - int res; /* * Allow set group id binaries to be authenticated @@ -156,13 +189,23 @@ saServiceConnectTwo ( setregid (egid, -1); memset (&address, 0, sizeof (struct sockaddr_un)); +#if defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN) + address.sun_len = sizeof(struct sockaddr_un); +#endif address.sun_family = PF_UNIX; - strcpy (address.sun_path + 1, "libais.socket"); +#if defined(OPENAIS_LINUX) + strcpy (address.sun_path + 1, socketname); +#else + strcpy (address.sun_path, socketname); +#endif responseFD = socket (PF_UNIX, SOCK_STREAM, 0); if (responseFD == -1) { return (SA_AIS_ERR_NO_RESOURCES); } - result = connect (responseFD, (struct sockaddr *)&address, sizeof (address)); + + socket_nosigpipe (responseFD); + + result = connect (responseFD, (struct sockaddr *)&address, AIS_SUN_LEN(&address)); if (result == -1) { close (responseFD); return (SA_AIS_ERR_TRY_AGAIN); @@ -179,8 +222,7 @@ saServiceConnectTwo ( req_lib_response_init.resdis_header.service = service; error = saSendRetry (responseFD, &req_lib_response_init, - sizeof (struct req_lib_response_init), - MSG_NOSIGNAL); + sizeof (struct req_lib_response_init)); if (error != SA_AIS_OK) { goto error_exit; } @@ -205,14 +247,19 @@ saServiceConnectTwo ( if (callbackFD == -1) { return (SA_AIS_ERR_NO_RESOURCES); } - result = fcntl (callbackFD, F_SETFL, O_NONBLOCK); + + socket_nosigpipe (callbackFD); + + result = connect (callbackFD, (struct sockaddr *)&address, AIS_SUN_LEN(&address)); if (result == -1) { close (callbackFD); close (responseFD); return (SA_AIS_ERR_TRY_AGAIN); } - result = connect (callbackFD, (struct sockaddr *)&address, sizeof (address)); + + result = fcntl (callbackFD, F_SETFL, O_NONBLOCK); if (result == -1) { + close (callbackFD); close (responseFD); return (SA_AIS_ERR_TRY_AGAIN); } @@ -224,8 +271,7 @@ saServiceConnectTwo ( req_lib_dispatch_init.conn_info = res_lib_response_init.conn_info; error = saSendRetry (callbackFD, &req_lib_dispatch_init, - sizeof (struct req_lib_dispatch_init), - MSG_NOSIGNAL); + sizeof (struct req_lib_dispatch_init)); if (error != SA_AIS_OK) { goto error_exit_two; } @@ -278,7 +324,7 @@ retry_recv: iov_recv.iov_base = (void *)&rbuf[processed]; iov_recv.iov_len = len - processed; - result = recvmsg (s, &msg_recv, MSG_NOSIGNAL|MSG_WAITALL); + result = recvmsg (s, &msg_recv, MSG_NOSIGNAL | MSG_DONTWAIT); if (result == -1 && errno == EINTR) { goto retry_recv; } @@ -307,8 +353,7 @@ SaAisErrorT saSendRetry ( int s, const void *msg, - size_t len, - int flags) + size_t len) { SaAisErrorT error = SA_AIS_OK; int result; @@ -329,7 +374,7 @@ retry_send: iov_send.iov_base = (void *)&rbuf[processed]; iov_send.iov_len = len - processed; - result = sendmsg (s, &msg_send, flags); + result = sendmsg (s, &msg_send, MSG_NOSIGNAL); /* * return immediately on any kind of syscall error that maps to @@ -415,7 +460,7 @@ SaAisErrorT saSendMsgRetry ( msg_send.msg_flags = 0; retry_sendmsg: - result = sendmsg (s, &msg_send, MSG_NOSIGNAL | MSG_DONTWAIT); + result = sendmsg (s, &msg_send, MSG_NOSIGNAL); /* * Can't send now, and message not committed, so don't retry send */ @@ -519,8 +564,7 @@ SaAisErrorT saSendReceiveReply ( { SaAisErrorT error = SA_AIS_OK; - error = saSendRetry (s, requestMessage, requestLen, - MSG_NOSIGNAL); + error = saSendRetry (s, requestMessage, requestLen); if (error != SA_AIS_OK) { goto error_exit; } diff --git a/lib/util.h b/lib/util.h index 3fe93f60..160a8603 100644 --- a/lib/util.h +++ b/lib/util.h @@ -38,8 +38,19 @@ #include #include +#include + #include "../include/ipc_gen.h" +#ifdef SO_NOSIGPIPE +#ifndef MSG_NOSIGNAL +#define MSG_NOSIGNAL 0 +#endif +void socket_nosigpipe(int s); +#else +#define socket_nosigpipe(s) +#endif + struct saHandleDatabase { unsigned int handleCount; struct saHandle *handles; @@ -84,8 +95,7 @@ SaAisErrorT saSendRetry ( int s, const void *msg, - size_t len, - int flags); + size_t len); SaAisErrorT saSendMsgRetry ( int s, diff --git a/test/Makefile b/test/Makefile index f32dfa7f..e1df95ff 100644 --- a/test/Makefile +++ b/test/Makefile @@ -28,24 +28,15 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF # THE POSSIBILITY OF SUCH DAMAGE. +# Include configuration +# +include ../Makefile.inc + LIBRARIES= ../lib/libSaClm.a ../lib/libSaAmf.a ../lib/libSaCkpt.a ../lib/libSaEvt.a ../lib/libSaLck.a ../lib/libSaMsg.a ../lib/libevs.a -LIBS = $(LIBRARIES) -lpthread +LIBS = $(LIBRARIES) -# Production mode flags -#CFLAGS = -c -O3 -Wall -I../include -#CFLAGS = -c -O3 -Wall -I../include -#LDFLAGS = -L../lib -#LIBRARIES= ../lib/libais.a ../lib/libevs.a -#LIBS = $(LIBRARIES) -lpthread - -# Debug mode flags -CFLAGS = -c -g -Wall -DDEBUG -I../include -CPPFLAGS = -c -g -Wall -DDEBUG -I../include -LDFLAGS = -g -L../lib - -# Profile mode flags -#CFLAGS = -c -O3 -pg -DDEBUG -I../include -#LDFLAGS = -pg -L../lib +CFLAGS += -I../include +LDFLAGS += -L../lib EXTRA_CFLAGS = -I../include TEST_SRC = testclm.c testamf1.c \ diff --git a/test/ckpt-wr.c b/test/ckpt-wr.c index b31d165a..367a886d 100644 --- a/test/ckpt-wr.c +++ b/test/ckpt-wr.c @@ -34,6 +34,7 @@ #include #include +#include #include #include #include diff --git a/test/ckptbench.c b/test/ckptbench.c index 11e73d8e..0fda6c3d 100644 --- a/test/ckptbench.c +++ b/test/ckptbench.c @@ -35,6 +35,7 @@ #include #include +#include #include #include #include diff --git a/test/ckptbenchth.c b/test/ckptbenchth.c index 928b82de..de969962 100644 --- a/test/ckptbenchth.c +++ b/test/ckptbenchth.c @@ -35,6 +35,7 @@ #include #include +#include #include #include #include diff --git a/test/ckptstress.c b/test/ckptstress.c index 7f61707f..4d2dfdd7 100644 --- a/test/ckptstress.c +++ b/test/ckptstress.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include diff --git a/test/evsbench.c b/test/evsbench.c index 2bb4b0e9..ac51e667 100644 --- a/test/evsbench.c +++ b/test/evsbench.c @@ -163,7 +163,7 @@ int main (void) { int i; evs_error_t result; evs_handle_t handle; - + signal (SIGALRM, sigalrm_handler); result = evs_initialize (&handle, &callbacks); @@ -173,7 +173,7 @@ int main (void) { result = evs_leave (handle, &groups[0], 1); printf ("Leave result %d\n", result); - size = 100000; + size = 1; for (i = 0; i < 225; i++) { /* number of repetitions - up to 50k */ evs_benchmark (handle, size); diff --git a/test/testamf1.c b/test/testamf1.c index 04a832b0..feb0e728 100644 --- a/test/testamf1.c +++ b/test/testamf1.c @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -204,9 +205,11 @@ SaAmfCallbacksT amfCallbacks; SaVersionT version = { 'B', 1, 1 }; +#if defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) static struct sched_param sched_param = { sched_priority: 99 }; +#endif void sigintr_handler (int signum) { exit (0); @@ -233,10 +236,12 @@ int main (int argc, char **argv) { extern int optind; signal (SIGINT, sigintr_handler); +#if defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) result = sched_setscheduler (0, SCHED_RR, &sched_param); if (result == -1) { printf ("couldn't set sched priority\n"); } +#endif result = saAmfInitialize (&handle, &amfCallbacks, &version); if (result != SA_AIS_OK) { diff --git a/test/testckpt.c b/test/testckpt.c index f3e923d7..4d5297a0 100644 --- a/test/testckpt.c +++ b/test/testckpt.c @@ -35,6 +35,7 @@ #include #include +#include #include #include #include diff --git a/test/testevt.c b/test/testevt.c index 4c2826b8..7ceb95ab 100644 --- a/test/testevt.c +++ b/test/testevt.c @@ -61,7 +61,7 @@ #include #include #include -#include +#include #include "saAis.h" #include "saEvt.h" diff --git a/test/testlck.c b/test/testlck.c index 73c4f52a..99bc25ed 100644 --- a/test/testlck.c +++ b/test/testlck.c @@ -34,6 +34,7 @@ #include #include +#include #include #include #include diff --git a/test/testmsg.c b/test/testmsg.c index ce0b734c..a2e2193c 100644 --- a/test/testmsg.c +++ b/test/testmsg.c @@ -34,6 +34,7 @@ #include #include +#include #include #include #include