Patch to remove segfault on the exiting of a service.
[openais.git] / exec / totemmrp.c
blob20efd718a0d6ee04fbf6e37a92e71de0cabb9be6
1 /*
2 * Copyright (c) 2005 MontaVista Software, Inc.
3 * Copyright (c) 2006-2007 Red Hat, Inc.
5 * All rights reserved.
7 * Author: Steven Dake (sdake@redhat.com)
9 * This software licensed under BSD license, the text of which follows:
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
14 * - Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 * - Redistributions in binary form must reproduce the above copyright notice,
17 * this list of conditions and the following disclaimer in the documentation
18 * and/or other materials provided with the distribution.
19 * - Neither the name of the MontaVista Software, Inc. nor the names of its
20 * contributors may be used to endorse or promote products derived from this
21 * software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
33 * THE POSSIBILITY OF SUCH DAMAGE.
35 #include <assert.h>
36 #include <sys/mman.h>
37 #include <sys/types.h>
38 #include <sys/stat.h>
39 #include <sys/socket.h>
40 #include <netdb.h>
41 #include <sys/un.h>
42 #include <sys/ioctl.h>
43 #include <sys/param.h>
44 #include <netinet/in.h>
45 #include <arpa/inet.h>
46 #include <unistd.h>
47 #include <fcntl.h>
48 #include <stdlib.h>
49 #include <stdio.h>
50 #include <errno.h>
51 #include <signal.h>
52 #include <sched.h>
53 #include <time.h>
54 #include <sys/time.h>
55 #include <sys/poll.h>
57 #include "swab.h"
58 #include "totem.h"
59 #include "totemsrp.h"
60 #include "aispoll.h"
62 totemsrp_handle totemsrp_handle_in;
64 void (*pg_deliver_fn) (
65 unsigned int nodeid,
66 struct iovec *iovec,
67 int iov_len,
68 int endian_conversion_required) = 0;
70 void (*pg_confchg_fn) (
71 enum totem_configuration_type configuration_type,
72 unsigned int *member_list, int member_list_entries,
73 unsigned int *left_list, int left_list_entries,
74 unsigned int *joined_list, int joined_list_entries,
75 struct memb_ring_id *ring_id) = 0;
77 void totemmrp_deliver_fn (
78 unsigned int nodeid,
79 struct iovec *iovec,
80 int iov_len,
81 int endian_conversion_required)
83 pg_deliver_fn (nodeid, iovec, iov_len, endian_conversion_required);
86 void totemmrp_confchg_fn (
87 enum totem_configuration_type configuration_type,
88 unsigned int *member_list, int member_list_entries,
89 unsigned int *left_list, int left_list_entries,
90 unsigned int *joined_list, int joined_list_entries,
91 struct memb_ring_id *ring_id)
93 pg_confchg_fn (configuration_type,
94 member_list, member_list_entries,
95 left_list, left_list_entries,
96 joined_list, joined_list_entries,
97 ring_id);
101 * Initialize the totem multiple ring protocol
103 int totemmrp_initialize (
104 poll_handle poll_handle,
105 struct totem_config *totem_config,
107 void (*deliver_fn) (
108 unsigned int nodeid,
109 struct iovec *iovec,
110 int iov_len,
111 int endian_conversion_required),
112 void (*confchg_fn) (
113 enum totem_configuration_type configuration_type,
114 unsigned int *member_list, int member_list_entries,
115 unsigned int *left_list, int left_list_entries,
116 unsigned int *joined_list, int joined_list_entries,
117 struct memb_ring_id *ring_id))
119 int result;
120 pg_deliver_fn = deliver_fn;
121 pg_confchg_fn = confchg_fn;
123 result = totemsrp_initialize (
124 poll_handle,
125 &totemsrp_handle_in,
126 totem_config,
127 totemmrp_deliver_fn,
128 totemmrp_confchg_fn);
130 return (result);
133 void totemmrp_finalize (void)
135 totemsrp_finalize (totemsrp_handle_in);
139 * Multicast a message
141 int totemmrp_mcast (
142 struct iovec *iovec,
143 int iov_len,
144 int priority)
146 return totemsrp_mcast (totemsrp_handle_in, iovec, iov_len, priority);
150 * Return number of available messages that can be queued
152 int totemmrp_avail (void)
154 return (totemsrp_avail (totemsrp_handle_in));
157 int totemmrp_callback_token_create (
158 void **handle_out,
159 enum totem_callback_token_type type,
160 int delete,
161 int (*callback_fn) (enum totem_callback_token_type type, void *),
162 void *data)
164 return totemsrp_callback_token_create (totemsrp_handle_in, handle_out, type, delete, callback_fn, data);
167 void totemmrp_callback_token_destroy (
168 void *handle_out)
170 totemsrp_callback_token_destroy (totemsrp_handle_in, handle_out);
173 void totemmrp_new_msg_signal (void) {
174 totemsrp_new_msg_signal (totemsrp_handle_in);
177 int totemmrp_ifaces_get (
178 unsigned int nodeid,
179 struct totem_ip_address *interfaces,
180 char ***status,
181 unsigned int *iface_count)
183 int res;
185 res = totemsrp_ifaces_get (
186 totemsrp_handle_in,
187 nodeid,
188 interfaces,
189 status,
190 iface_count);
192 return (res);
195 int totemmrp_my_nodeid_get (void)
197 return (totemsrp_my_nodeid_get (totemsrp_handle_in));
200 int totemmrp_my_family_get (void)
202 return (totemsrp_my_family_get (totemsrp_handle_in));
205 extern int totemmrp_ring_reenable (void)
207 int res;
209 res = totemsrp_ring_reenable (
210 totemsrp_handle_in);
212 return (res);