~ubuntu-branches/ubuntu/precise/corosync/precise-proposed

« back to all changes in this revision

Viewing changes to exec/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Ante Karamatic
  • Date: 2009-08-21 09:29:56 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090821092956-w9qxxxx3zeoh8dem
Tags: 1.0.0-4ubuntu2
* debian/control:
  - 'Ubuntu Developers' instead of 'Ubuntu Core Developers'
    as maintainer
  - Bump debhelper dependecy to 7

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * Copyright (c) 2002-2006 MontaVista Software, Inc.
3
 
 * Copyright (c) 2006-2008 Red Hat, Inc.
 
3
 * Copyright (c) 2006-2009 Red Hat, Inc.
4
4
 *
5
5
 * All rights reserved.
6
6
 *
32
32
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
33
33
 * THE POSSIBILITY OF SUCH DAMAGE.
34
34
 */
 
35
 
 
36
#include <config.h>
 
37
 
35
38
#include <pthread.h>
36
39
#include <assert.h>
37
 
#include <pwd.h>
38
 
#include <grp.h>
39
40
#include <sys/types.h>
40
41
#include <sys/poll.h>
41
42
#include <sys/uio.h>
44
45
#include <sys/un.h>
45
46
#include <sys/time.h>
46
47
#include <sys/resource.h>
 
48
#include <sys/stat.h>
47
49
#include <netinet/in.h>
48
50
#include <arpa/inet.h>
49
51
#include <unistd.h>
56
58
#include <time.h>
57
59
 
58
60
#include <corosync/swab.h>
59
 
#include <corosync/saAis.h>
 
61
#include <corosync/corotypes.h>
 
62
#include <corosync/coroipc_types.h>
 
63
#include <corosync/corodefs.h>
60
64
#include <corosync/list.h>
61
 
#include <corosync/queue.h>
62
65
#include <corosync/lcr/lcr_ifact.h>
63
66
#include <corosync/totem/coropoll.h>
64
67
#include <corosync/totem/totempg.h>
65
68
#include <corosync/engine/objdb.h>
66
69
#include <corosync/engine/config.h>
67
70
#include <corosync/engine/logsys.h>
 
71
#include <corosync/coroipcs.h>
68
72
 
 
73
#include "quorum.h"
69
74
#include "totemsrp.h"
70
 
#include "mempool.h"
71
75
#include "mainconfig.h"
72
76
#include "totemconfig.h"
73
77
#include "main.h"
74
78
#include "sync.h"
 
79
#include "syncv2.h"
75
80
#include "tlist.h"
76
 
#include "flow.h"
77
 
#include "ipc.h"
78
81
#include "timer.h"
79
82
#include "util.h"
80
 
#include "flow.h"
81
83
#include "apidef.h"
82
84
#include "service.h"
 
85
#include "schedwrk.h"
83
86
#include "version.h"
 
87
#include "evil.h"
84
88
 
85
89
LOGSYS_DECLARE_SYSTEM ("corosync",
86
 
        LOG_MODE_OUTPUT_STDERR | LOG_MODE_OUTPUT_SYSLOG_THREADED | LOG_MODE_BUFFER_BEFORE_CONFIG,
87
 
        NULL,
88
 
        LOG_DAEMON);
 
90
        LOGSYS_MODE_OUTPUT_STDERR | LOGSYS_MODE_THREADED | LOGSYS_MODE_FORK,
 
91
        0,
 
92
        NULL,
 
93
        LOG_INFO,
 
94
        LOG_DAEMON,
 
95
        LOG_INFO,
 
96
        NULL,
 
97
        1000000);
89
98
 
90
 
LOGSYS_DECLARE_SUBSYS ("MAIN", LOG_INFO);
 
99
LOGSYS_DECLARE_SUBSYS ("MAIN");
91
100
 
92
101
#define SERVER_BACKLOG 5
93
102
 
94
 
static int ais_uid = 0;
95
 
 
96
 
static int gid_valid = 0;
 
103
static int sched_priority = 0;
97
104
 
98
105
static unsigned int service_count = 32;
99
106
 
 
107
#if defined(HAVE_PTHREAD_SPIN_LOCK)
 
108
static pthread_spinlock_t serialize_spin;
 
109
#else
100
110
static pthread_mutex_t serialize_mutex = PTHREAD_MUTEX_INITIALIZER;
 
111
#endif
101
112
 
102
113
static struct totem_logging_configuration totem_logging_configuration;
103
114
 
104
 
static char delivery_data[MESSAGE_SIZE_MAX];
105
 
 
106
115
static int num_config_modules;
107
116
 
108
117
static struct config_iface_ver0 *config_modules[MAX_DYNAMIC_SERVICES];
111
120
 
112
121
static struct corosync_api_v1 *api = NULL;
113
122
 
114
 
unsigned long long *(*main_clm_get_by_nodeid) (unsigned int node_id);
 
123
static enum cs_sync_mode minimum_sync_mode;
 
124
 
 
125
static enum cs_sync_mode minimum_sync_mode;
 
126
 
 
127
static int sync_in_process = 1;
 
128
 
 
129
static hdb_handle_t corosync_poll_handle;
 
130
 
 
131
struct sched_param global_sched_param;
 
132
 
 
133
hdb_handle_t corosync_poll_handle_get (void)
 
134
{
 
135
        return (corosync_poll_handle);
 
136
}
 
137
 
 
138
void corosync_state_dump (void)
 
139
{
 
140
        int i;
 
141
 
 
142
        for (i = 0; i < SERVICE_HANDLER_MAXIMUM_COUNT; i++) {
 
143
                if (ais_service[i] && ais_service[i]->exec_dump_fn) {
 
144
                        ais_service[i]->exec_dump_fn ();
 
145
                }
 
146
        }
 
147
}
115
148
 
116
149
static void sigusr2_handler (int num)
117
150
{
118
 
        int i;
119
 
 
120
 
        for (i = 0; ais_service[i]; i++) {
121
 
                if (ais_service[i]->exec_dump_fn) {
122
 
                        ais_service[i]->exec_dump_fn ();
123
 
                }
124
 
        }
 
151
        /*
 
152
         * TODO remove this from sigusr2 handler and access via cfg service
 
153
         * engine api - corosync-cfgtool
 
154
         */
 
155
        corosync_state_dump ();
125
156
}
126
157
 
127
 
static void *aisexec_exit (void *arg)
 
158
/*
 
159
 * TODO this function needs some love
 
160
 */
 
161
void corosync_shutdown_request (void)
128
162
{
129
163
        if (api) {
130
164
                corosync_service_unlink_all (api);
131
165
        }
132
166
 
133
 
#ifdef DEBUG_MEMPOOL
134
 
        int stats_inuse[MEMPOOL_GROUP_SIZE];
135
 
        int stats_avail[MEMPOOL_GROUP_SIZE];
136
 
        int stats_memoryused[MEMPOOL_GROUP_SIZE];
137
 
        int i;
138
 
 
139
 
        mempool_getstats (stats_inuse, stats_avail, stats_memoryused);
140
 
        log_printf (LOG_LEVEL_DEBUG, "Memory pools:\n");
141
 
        for (i = 0; i < MEMPOOL_GROUP_SIZE; i++) {
142
 
        log_printf (LOG_LEVEL_DEBUG, "order %d size %d inuse %d avail %d memory used %d\n",
143
 
                i, 1<<i, stats_inuse[i], stats_avail[i], stats_memoryused[i]);
144
 
        }
145
 
#endif
146
 
 
 
167
        poll_stop (0);
147
168
        totempg_finalize ();
148
 
        logsys_flush ();
 
169
        coroipcs_ipc_exit ();
149
170
 
150
171
        corosync_exit_error (AIS_DONE_EXIT);
151
 
 
152
 
        /* never reached */
153
 
        return NULL;
154
 
}
155
 
 
156
 
pthread_t aisexec_exit_thread;
157
 
static void init_shutdown(void *data) 
158
 
{
159
 
        pthread_create (&aisexec_exit_thread, NULL, aisexec_exit, NULL);
160
 
}
161
 
 
162
 
 
163
 
static poll_timer_handle shutdown_handle;
 
172
}
 
173
 
164
174
static void sigquit_handler (int num)
165
175
{
166
 
        /* avoid creating threads from within the interrupt context */
167
 
        poll_timer_add (aisexec_poll_handle, 500, NULL, init_shutdown, &shutdown_handle);
 
176
        corosync_shutdown_request ();
168
177
}
169
178
 
 
179
static void sigintr_handler (int num)
 
180
{
 
181
        corosync_shutdown_request ();
 
182
}
170
183
 
171
184
static void sigsegv_handler (int num)
172
185
{
173
 
        signal (SIGSEGV, SIG_DFL);
174
 
        logsys_flush ();
 
186
        (void)signal (SIGSEGV, SIG_DFL);
 
187
        logsys_atexit();
 
188
        logsys_log_rec_store (LOCALSTATEDIR "/lib/corosync/fdata");
175
189
        raise (SIGSEGV);
176
190
}
177
191
 
178
192
static void sigabrt_handler (int num)
179
193
{
180
 
        signal (SIGABRT, SIG_DFL);
181
 
        logsys_flush ();
 
194
        (void)signal (SIGABRT, SIG_DFL);
 
195
        logsys_atexit();
 
196
        logsys_log_rec_store (LOCALSTATEDIR "/lib/corosync/fdata");
182
197
        raise (SIGABRT);
183
198
}
184
199
 
185
200
#define LOCALHOST_IP inet_addr("127.0.0.1")
186
201
 
187
 
totempg_groups_handle corosync_group_handle;
 
202
static hdb_handle_t corosync_group_handle;
188
203
 
189
 
struct totempg_group corosync_group = {
 
204
static struct totempg_group corosync_group = {
190
205
        .group          = "a",
191
206
        .group_len      = 1
192
207
};
193
208
 
194
 
void sigintr_handler (int signum)
195
 
{
196
 
        poll_timer_add (aisexec_poll_handle, 500, NULL, init_shutdown, &shutdown_handle);
197
 
}
198
 
 
199
 
 
200
 
static int pool_sizes[] = { 0, 0, 0, 0, 0, 4096, 0, 1, 0, /* 256 */
201
 
                                        1024, 0, 1, 4096, 0, 0, 0, 0, /* 65536 */
202
 
                                        1, 1, 1, 1, 1, 1, 1, 1, 1 };
203
 
 
204
 
void serialize_mutex_lock (void)
 
209
 
 
210
 
 
211
#if defined(HAVE_PTHREAD_SPIN_LOCK)
 
212
static void serialize_lock (void)
 
213
{
 
214
        pthread_spin_lock (&serialize_spin);
 
215
}
 
216
 
 
217
static void serialize_unlock (void)
 
218
{
 
219
        pthread_spin_unlock (&serialize_spin);
 
220
}
 
221
#else
 
222
static void serialize_lock (void)
205
223
{
206
224
        pthread_mutex_lock (&serialize_mutex);
207
225
}
208
226
 
209
 
void serialize_mutex_unlock (void)
 
227
static void serialize_unlock (void)
210
228
{
211
229
        pthread_mutex_unlock (&serialize_mutex);
212
230
}
213
 
 
 
231
#endif
214
232
 
215
233
static void corosync_sync_completed (void)
216
234
{
 
235
        log_printf (LOGSYS_LEVEL_NOTICE,
 
236
                "Completed service synchronization, ready to provide service.\n");
 
237
        sync_in_process = 0;
217
238
}
218
239
 
219
240
static int corosync_sync_callbacks_retrieve (int sync_id,
220
241
        struct sync_callbacks *callbacks)
221
242
{
222
243
        unsigned int ais_service_index;
223
 
        unsigned int ais_services_found = 0;
224
 
        
 
244
        int res;
 
245
 
225
246
        for (ais_service_index = 0;
226
247
                ais_service_index < SERVICE_HANDLER_MAXIMUM_COUNT;
227
248
                ais_service_index++) {
228
249
 
229
 
                if (ais_service[ais_service_index] != NULL) {
230
 
                        if (ais_services_found == sync_id) {
 
250
                if (ais_service[ais_service_index] != NULL
 
251
                        && ais_service[ais_service_index]->sync_mode == CS_SYNC_V1) {
 
252
                        if (ais_service_index == sync_id) {
231
253
                                break;
232
254
                        }
233
 
                        ais_services_found += 1;
234
255
                }
235
256
        }
 
257
        /*
 
258
         * Try to load backwards compat sync engines
 
259
         */
236
260
        if (ais_service_index == SERVICE_HANDLER_MAXIMUM_COUNT) {
237
 
                memset (callbacks, 0, sizeof (struct sync_callbacks));
238
 
                return (-1);
 
261
                res = evil_callbacks_load (sync_id, callbacks);
 
262
                return (res);
239
263
        }
240
264
        callbacks->name = ais_service[ais_service_index]->name;
241
265
        callbacks->sync_init = ais_service[ais_service_index]->sync_init;
245
269
        return (0);
246
270
}
247
271
 
248
 
static struct memb_ring_id aisexec_ring_id;
 
272
static int corosync_sync_v2_callbacks_retrieve (
 
273
        int service_id,
 
274
        struct sync_callbacks *callbacks)
 
275
{
 
276
        int res;
 
277
 
 
278
        if (minimum_sync_mode == CS_SYNC_V2 && service_id == CLM_SERVICE && ais_service[CLM_SERVICE] == NULL) {
 
279
                res = evil_callbacks_load (service_id, callbacks);
 
280
                return (res);
 
281
        }
 
282
        if (minimum_sync_mode == CS_SYNC_V2 && service_id == EVT_SERVICE && ais_service[EVT_SERVICE] == NULL) {
 
283
                res = evil_callbacks_load (service_id, callbacks);
 
284
                return (res);
 
285
        }
 
286
        if (ais_service[service_id] == NULL) {
 
287
                return (-1);
 
288
        }
 
289
        if (minimum_sync_mode == CS_SYNC_V1 && ais_service[service_id]->sync_mode != CS_SYNC_V2) {
 
290
                return (-1);
 
291
        }
 
292
 
 
293
        callbacks->name = ais_service[service_id]->name;
 
294
        callbacks->sync_init = ais_service[service_id]->sync_init;
 
295
        callbacks->sync_process = ais_service[service_id]->sync_process;
 
296
        callbacks->sync_activate = ais_service[service_id]->sync_activate;
 
297
        callbacks->sync_abort = ais_service[service_id]->sync_abort;
 
298
        return (0);
 
299
}
 
300
 
 
301
static struct memb_ring_id corosync_ring_id;
249
302
 
250
303
static void confchg_fn (
251
304
        enum totem_configuration_type configuration_type,
252
 
        unsigned int *member_list, int member_list_entries,
253
 
        unsigned int *left_list, int left_list_entries,
254
 
        unsigned int *joined_list, int joined_list_entries,
255
 
        struct memb_ring_id *ring_id)
 
305
        const unsigned int *member_list, size_t member_list_entries,
 
306
        const unsigned int *left_list, size_t left_list_entries,
 
307
        const unsigned int *joined_list, size_t joined_list_entries,
 
308
        const struct memb_ring_id *ring_id)
256
309
{
257
310
        int i;
 
311
        int abort_activate = 0;
258
312
 
259
 
        memcpy (&aisexec_ring_id, ring_id, sizeof (struct memb_ring_id));
 
313
        if (sync_in_process == 1) {
 
314
                abort_activate = 1;
 
315
        }
 
316
        sync_in_process = 1;
 
317
        serialize_lock ();
 
318
        memcpy (&corosync_ring_id, ring_id, sizeof (struct memb_ring_id));
260
319
 
261
320
        /*
262
321
         * Call configuration change for all services
269
328
                                joined_list, joined_list_entries, ring_id);
270
329
                }
271
330
        }
272
 
}
273
 
 
274
 
static void aisexec_uid_determine (struct main_config *main_config)
275
 
{
276
 
        struct passwd *passwd;
277
 
 
278
 
        passwd = getpwnam(main_config->user);
279
 
        if (passwd == 0) {
280
 
                log_printf (LOG_LEVEL_ERROR, "ERROR: The '%s' user is not found in /etc/passwd, please read the documentation.\n", main_config->user);
281
 
                corosync_exit_error (AIS_DONE_UID_DETERMINE);
282
 
        }
283
 
        ais_uid = passwd->pw_uid;
284
 
        endpwent ();
285
 
}
286
 
 
287
 
static void aisexec_gid_determine (struct main_config *main_config)
288
 
{
289
 
        struct group *group;
290
 
        group = getgrnam (main_config->group);
291
 
        if (group == 0) {
292
 
                log_printf (LOG_LEVEL_ERROR, "ERROR: The '%s' group is not found in /etc/group, please read the documentation.\n", group->gr_name);
293
 
                corosync_exit_error (AIS_DONE_GID_DETERMINE);
294
 
        }
295
 
        gid_valid = group->gr_gid;
296
 
        endgrent ();
297
 
}
298
 
 
299
 
static void aisexec_priv_drop (void)
300
 
{
301
 
return;
302
 
        setuid (ais_uid);
303
 
        setegid (ais_uid);
304
 
}
305
 
 
306
 
static void aisexec_mempool_init (void)
307
 
{
308
 
        int res;
309
 
 
310
 
        res = mempool_init (pool_sizes);
311
 
        if (res == ENOMEM) {
312
 
                log_printf (LOG_LEVEL_ERROR, "Couldn't allocate memory pools, not enough memory");
313
 
                corosync_exit_error (AIS_DONE_MEMPOOL_INIT);
314
 
        }
315
 
}
316
 
 
317
 
static void aisexec_tty_detach (void)
 
331
        serialize_unlock ();
 
332
 
 
333
        if (abort_activate) {
 
334
                sync_v2_abort ();
 
335
        }
 
336
        if (minimum_sync_mode == CS_SYNC_V2 && configuration_type == TOTEM_CONFIGURATION_REGULAR) {
 
337
                sync_v2_start (member_list, member_list_entries, ring_id);
 
338
        }
 
339
}
 
340
 
 
341
static void priv_drop (void)
 
342
{
 
343
        return; /* TODO: we are still not dropping privs */
 
344
}
 
345
 
 
346
static void corosync_tty_detach (void)
318
347
{
319
348
        int fd;
320
349
 
330
359
                        /*
331
360
                         * child which is disconnected, run this process
332
361
                         */
333
 
/*                      setset(); */
 
362
/*                      setset();
334
363
                        close (0);
335
364
                        close (1);
336
365
                        close (2);
 
366
*/
337
367
                        break;
338
368
                default:
339
369
                        exit (0);
341
371
        }
342
372
 
343
373
        /* Create new session */
344
 
        setsid();
 
374
        (void)setsid();
345
375
 
346
 
        /* 
 
376
        /*
347
377
         * Map stdin/out/err to /dev/null.
348
378
         */
349
379
        fd = open("/dev/null", O_RDWR);
354
384
                dup2(fd, STDERR_FILENO); /* 2 */
355
385
 
356
386
                /* Should be 0, but just in case it isn't... */
357
 
                if (fd > 2) 
 
387
                if (fd > 2)
358
388
                        close(fd);
359
389
        }
360
390
}
361
391
 
362
 
static void aisexec_setscheduler (void)
363
 
{
364
 
#if ! defined(TS_CLASS) && (defined(COROSYNC_BSD) || defined(COROSYNC_LINUX) || defined(COROSYNC_SOLARIS))
365
 
        struct sched_param sched_param;
366
 
        int res;
367
 
 
368
 
        res = sched_get_priority_max (SCHED_RR);
369
 
        if (res != -1) {
370
 
                sched_param.sched_priority = 1;//res;
371
 
                res = sched_setscheduler (0, SCHED_RR, &sched_param);
372
 
                if (res == -1) {
373
 
                        log_printf (LOG_LEVEL_WARNING, "Could not set SCHED_RR at priority %d: %s\n",
374
 
                                sched_param.sched_priority, strerror (errno));
375
 
                }
376
 
        } else
377
 
                log_printf (LOG_LEVEL_WARNING, "Could not get maximum scheduler priority: %s\n", strerror (errno));
378
 
#else
379
 
        log_printf(LOG_LEVEL_WARNING, "Scheduler priority left to default value (no OS support)\n");
380
 
#endif
381
 
}
382
 
 
383
 
static void aisexec_mlockall (void)
 
392
static void corosync_mlockall (void)
384
393
{
385
394
#if !defined(COROSYNC_BSD)
386
395
        int res;
399
408
        /* under FreeBSD a process with locked page cannot call dlopen
400
409
         * code disabled until FreeBSD bug i386/93396 was solved
401
410
         */
402
 
        log_printf (LOG_LEVEL_WARNING, "Could not lock memory of service to avoid page faults\n");
 
411
        log_printf (LOGSYS_LEVEL_WARNING, "Could not lock memory of service to avoid page faults\n");
403
412
#else
404
413
        res = mlockall (MCL_CURRENT | MCL_FUTURE);
405
414
        if (res == -1) {
406
 
                log_printf (LOG_LEVEL_WARNING, "Could not lock memory of service to avoid page faults: %s\n", strerror (errno));
 
415
                log_printf (LOGSYS_LEVEL_WARNING, "Could not lock memory of service to avoid page faults: %s\n", strerror (errno));
407
416
        };
408
417
#endif
409
418
}
410
419
 
411
 
 
412
420
static void deliver_fn (
413
421
        unsigned int nodeid,
414
 
        struct iovec *iovec,
415
 
        int iov_len,
 
422
        const void *msg,
 
423
        unsigned int msg_len,
416
424
        int endian_conversion_required)
417
425
{
418
 
        mar_req_header_t *header;
419
 
        int pos = 0;
420
 
        int i;
 
426
        const coroipc_request_header_t *header;
421
427
        int service;
422
428
        int fn_id;
 
429
        unsigned int id;
 
430
        unsigned int size;
423
431
 
424
 
        /*
425
 
         * Build buffer without iovecs to make processing easier
426
 
         * This is only used for messages which are multicast with iovecs
427
 
         * and self-delivered.  All other mechanisms avoid the copy.
428
 
         */
429
 
        if (iov_len > 1) {
430
 
                for (i = 0; i < iov_len; i++) {
431
 
                        memcpy (&delivery_data[pos], iovec[i].iov_base, iovec[i].iov_len);
432
 
                        pos += iovec[i].iov_len;
433
 
                        assert (pos < MESSAGE_SIZE_MAX);
434
 
                }
435
 
                header = (mar_req_header_t *)delivery_data;
 
432
        header = msg;
 
433
        if (endian_conversion_required) {
 
434
                id = swab32 (header->id);
 
435
                size = swab32 (header->size);
436
436
        } else {
437
 
                header = (mar_req_header_t *)iovec[0].iov_base;
438
 
        }
439
 
        if (endian_conversion_required) {
440
 
                header->id = swab32 (header->id);
441
 
                header->size = swab32 (header->size);
442
 
        }
443
 
 
444
 
//      assert(iovec->iov_len == header->size);
 
437
                id = header->id;
 
438
                size = header->size;
 
439
        }
445
440
 
446
441
        /*
447
442
         * Call the proper executive handler
448
443
         */
449
 
        service = header->id >> 16;
450
 
        fn_id = header->id & 0xffff;
 
444
        service = id >> 16;
 
445
        fn_id = id & 0xffff;
 
446
 
 
447
        serialize_lock();
 
448
 
 
449
        if (ais_service[service] == NULL && service == EVT_SERVICE) {
 
450
                evil_deliver_fn (nodeid, service, fn_id, msg,
 
451
                        endian_conversion_required);
 
452
        }
 
453
 
 
454
        if (!ais_service[service]) {
 
455
                serialize_unlock();
 
456
                return;
 
457
        }
 
458
 
451
459
        if (endian_conversion_required) {
452
460
                assert(ais_service[service]->exec_engine[fn_id].exec_endian_convert_fn != NULL);
453
461
                ais_service[service]->exec_engine[fn_id].exec_endian_convert_fn
454
 
                        (header);
 
462
                        ((void *)msg);
455
463
        }
456
464
 
457
465
        ais_service[service]->exec_engine[fn_id].exec_handler_fn
458
 
                (header, nodeid);
 
466
                (msg, nodeid);
 
467
 
 
468
        serialize_unlock();
459
469
}
460
470
 
461
471
void main_get_config_modules(struct config_iface_ver0 ***modules, int *num)
465
475
}
466
476
 
467
477
int main_mcast (
468
 
        struct iovec *iovec,
469
 
        int iov_len,
 
478
        const struct iovec *iovec,
 
479
        unsigned int iov_len,
470
480
        unsigned int guarantee)
471
481
{
472
482
        return (totempg_groups_mcast_joined (corosync_group_handle, iovec, iov_len, guarantee));
473
483
}
474
484
 
475
 
extern int main_send_ok (
476
 
        struct iovec *iovec,
477
 
        int iov_len)
478
 
{
479
 
        return (totempg_groups_send_ok_joined (corosync_group_handle, iovec, iov_len));
 
485
int message_source_is_local (const mar_message_source_t *source)
 
486
{
 
487
        int ret = 0;
 
488
 
 
489
        assert (source != NULL);
 
490
        if (source->nodeid == totempg_my_nodeid_get ()) {
 
491
                ret = 1;
 
492
        }
 
493
        return ret;
 
494
}
 
495
 
 
496
void message_source_set (
 
497
        mar_message_source_t *source,
 
498
        void *conn)
 
499
{
 
500
        assert ((source != NULL) && (conn != NULL));
 
501
        memset (source, 0, sizeof (mar_message_source_t));
 
502
        source->nodeid = totempg_my_nodeid_get ();
 
503
        source->conn = conn;
 
504
}
 
505
 
 
506
/*
 
507
 * Provides the glue from corosync to the IPC Service
 
508
 */
 
509
static int corosync_private_data_size_get (unsigned int service)
 
510
{
 
511
        return (ais_service[service]->private_data_size);
 
512
}
 
513
 
 
514
static coroipcs_init_fn_lvalue corosync_init_fn_get (unsigned int service)
 
515
{
 
516
        return (ais_service[service]->lib_init_fn);
 
517
}
 
518
 
 
519
static coroipcs_exit_fn_lvalue corosync_exit_fn_get (unsigned int service)
 
520
{
 
521
        return (ais_service[service]->lib_exit_fn);
 
522
}
 
523
 
 
524
static coroipcs_handler_fn_lvalue corosync_handler_fn_get (unsigned int service, unsigned int id)
 
525
{
 
526
        return (ais_service[service]->lib_engine[id].lib_handler_fn);
 
527
}
 
528
 
 
529
 
 
530
static int corosync_security_valid (int euid, int egid)
 
531
{
 
532
        struct list_head *iter;
 
533
        if (euid == 0 || egid == 0) {
 
534
                return (1);
 
535
        }
 
536
 
 
537
        for (iter = uidgid_list_head.next; iter != &uidgid_list_head;
 
538
                iter = iter->next) {
 
539
 
 
540
                struct uidgid_item *ugi = list_entry (iter, struct uidgid_item,
 
541
                        list);
 
542
 
 
543
                if (euid == ugi->uid || egid == ugi->gid)
 
544
                        return (1);
 
545
        }
 
546
 
 
547
        return (0);
 
548
}
 
549
 
 
550
static int corosync_service_available (unsigned int service)
 
551
{
 
552
        return (ais_service[service] != NULL);
 
553
}
 
554
 
 
555
struct sending_allowed_private_data_struct {
 
556
        int reserved_msgs;
 
557
};
 
558
 
 
559
static int corosync_sending_allowed (
 
560
        unsigned int service,
 
561
        unsigned int id,
 
562
        const void *msg,
 
563
        void *sending_allowed_private_data)
 
564
{
 
565
        struct sending_allowed_private_data_struct *pd =
 
566
                (struct sending_allowed_private_data_struct *)sending_allowed_private_data;
 
567
        struct iovec reserve_iovec;
 
568
        coroipc_request_header_t *header = (coroipc_request_header_t *)msg;
 
569
        int sending_allowed;
 
570
 
 
571
        reserve_iovec.iov_base = (char *)header;
 
572
        reserve_iovec.iov_len = header->size;
 
573
 
 
574
        pd->reserved_msgs = totempg_groups_joined_reserve (
 
575
                corosync_group_handle,
 
576
                &reserve_iovec, 1);
 
577
 
 
578
        sending_allowed =
 
579
                (corosync_quorum_is_quorate() == 1 ||
 
580
                ais_service[service]->allow_inquorate == CS_LIB_ALLOW_INQUORATE) &&
 
581
                ((ais_service[service]->lib_engine[id].flow_control == CS_LIB_FLOW_CONTROL_NOT_REQUIRED) ||
 
582
                ((ais_service[service]->lib_engine[id].flow_control == CS_LIB_FLOW_CONTROL_REQUIRED) &&
 
583
                (pd->reserved_msgs) &&
 
584
                (sync_in_process == 0)));
 
585
 
 
586
        return (sending_allowed);
 
587
}
 
588
 
 
589
static void corosync_sending_allowed_release (void *sending_allowed_private_data)
 
590
{
 
591
        struct sending_allowed_private_data_struct *pd =
 
592
                (struct sending_allowed_private_data_struct *)sending_allowed_private_data;
 
593
 
 
594
        totempg_groups_joined_release (pd->reserved_msgs);
 
595
}
 
596
 
 
597
static int ipc_subsys_id = -1;
 
598
 
 
599
static void ipc_log_printf (const char *format, ...) __attribute__((format(printf, 1, 2)));
 
600
static void ipc_log_printf (const char *format, ...) {
 
601
        va_list ap;
 
602
 
 
603
        va_start (ap, format);
 
604
 
 
605
        _logsys_log_vprintf (
 
606
                LOGSYS_ENCODE_RECID(LOGSYS_LEVEL_ERROR,
 
607
                                    ipc_subsys_id,
 
608
                                    LOGSYS_RECID_LOG),
 
609
                __FUNCTION__, __FILE__, __LINE__,
 
610
                format, ap);
 
611
 
 
612
        va_end (ap);
 
613
}
 
614
 
 
615
static void ipc_fatal_error(const char *error_msg) {
 
616
       _logsys_log_printf (
 
617
                LOGSYS_ENCODE_RECID(LOGSYS_LEVEL_ERROR,
 
618
                                    ipc_subsys_id,
 
619
                                    LOGSYS_RECID_LOG),
 
620
                __FUNCTION__, __FILE__, __LINE__,
 
621
                "%s", error_msg);
 
622
        exit(EXIT_FAILURE);
 
623
}
 
624
 
 
625
static int corosync_poll_handler_accept (
 
626
        hdb_handle_t handle,
 
627
        int fd,
 
628
        int revent,
 
629
        void *context)
 
630
{
 
631
        return (coroipcs_handler_accept (fd, revent, context));
 
632
}
 
633
 
 
634
static int corosync_poll_handler_dispatch (
 
635
        hdb_handle_t handle,
 
636
        int fd,
 
637
        int revent,
 
638
        void *context)
 
639
{
 
640
        return (coroipcs_handler_dispatch (fd, revent, context));
 
641
}
 
642
 
 
643
 
 
644
static void corosync_poll_accept_add (
 
645
        int fd)
 
646
{
 
647
        poll_dispatch_add (corosync_poll_handle, fd, POLLIN|POLLNVAL, 0,
 
648
                corosync_poll_handler_accept);
 
649
}
 
650
 
 
651
static void corosync_poll_dispatch_add (
 
652
        int fd,
 
653
        void *context)
 
654
{
 
655
        poll_dispatch_add (corosync_poll_handle, fd, POLLIN|POLLNVAL, context,
 
656
                corosync_poll_handler_dispatch);
 
657
}
 
658
 
 
659
static void corosync_poll_dispatch_modify (
 
660
        int fd,
 
661
        int events)
 
662
{
 
663
        poll_dispatch_modify (corosync_poll_handle, fd, events,
 
664
                corosync_poll_handler_dispatch);
 
665
}
 
666
 
 
667
static struct coroipcs_init_state ipc_init_state = {
 
668
        .socket_name                    = COROSYNC_SOCKET_NAME,
 
669
        .sched_policy                   = SCHED_OTHER,
 
670
        .sched_param                    = &global_sched_param,
 
671
        .malloc                         = malloc,
 
672
        .free                           = free,
 
673
        .log_printf                     = ipc_log_printf,
 
674
        .fatal_error                    = ipc_fatal_error,
 
675
        .security_valid                 = corosync_security_valid,
 
676
        .service_available              = corosync_service_available,
 
677
        .private_data_size_get          = corosync_private_data_size_get,
 
678
        .serialize_lock                 = serialize_lock,
 
679
        .serialize_unlock               = serialize_unlock,
 
680
        .sending_allowed                = corosync_sending_allowed,
 
681
        .sending_allowed_release        = corosync_sending_allowed_release,
 
682
        .poll_accept_add                = corosync_poll_accept_add,
 
683
        .poll_dispatch_add              = corosync_poll_dispatch_add,
 
684
        .poll_dispatch_modify           = corosync_poll_dispatch_modify,
 
685
        .init_fn_get                    = corosync_init_fn_get,
 
686
        .exit_fn_get                    = corosync_exit_fn_get,
 
687
        .handler_fn_get                 = corosync_handler_fn_get
 
688
};
 
689
 
 
690
static void corosync_setscheduler (void)
 
691
{
 
692
#if defined(HAVE_PTHREAD_SETSCHEDPARAM) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
 
693
        int res;
 
694
 
 
695
        sched_priority = sched_get_priority_max (SCHED_RR);
 
696
        if (sched_priority != -1) {
 
697
                global_sched_param.sched_priority = sched_priority;
 
698
                res = sched_setscheduler (0, SCHED_RR, &global_sched_param);
 
699
                if (res == -1) {
 
700
                        global_sched_param.sched_priority = 0;
 
701
                        log_printf (LOGSYS_LEVEL_WARNING, "Could not set SCHED_RR at priority %d: %s\n",
 
702
                                global_sched_param.sched_priority, strerror (errno));
 
703
                } else {
 
704
                        /*
 
705
                         * Turn on SCHED_RR in ipc system
 
706
                         */
 
707
                        ipc_init_state.sched_policy = SCHED_RR;
 
708
                }
 
709
        } else {
 
710
                log_printf (LOGSYS_LEVEL_WARNING, "Could not get maximum scheduler priority: %s\n", strerror (errno));
 
711
                sched_priority = 0;
 
712
        }
 
713
#else
 
714
        log_printf(LOGSYS_LEVEL_WARNING,
 
715
                "The Platform is missing process priority setting features.  Leaving at default.");
 
716
#endif
480
717
}
481
718
 
482
719
int main (int argc, char **argv)
483
720
{
484
 
        char *error_string;
485
 
        struct main_config main_config;
 
721
        const char *error_string;
486
722
        struct totem_config totem_config;
487
 
        unsigned int objdb_handle;
488
 
        unsigned int config_handle;
 
723
        hdb_handle_t objdb_handle;
 
724
        hdb_handle_t config_handle;
489
725
        unsigned int config_version = 0;
490
726
        void *objdb_p;
491
727
        struct config_iface_ver0 *config;
492
728
        void *config_p;
 
729
        const char *config_iface_init;
493
730
        char *config_iface;
494
731
        char *iface;
495
732
        int res, ch;
496
733
        int background, setprio;
497
 
        int totem_log_service;
 
734
        struct stat stat_out;
 
735
        char corosync_lib_dir[PATH_MAX];
 
736
 
 
737
#if defined(HAVE_PTHREAD_SPIN_LOCK)
 
738
        pthread_spin_init (&serialize_spin, 0);
 
739
#endif
498
740
 
499
741
        /* default configuration
500
742
         */
501
743
        background = 1;
502
744
        setprio = 1;
503
 
        
 
745
 
504
746
        while ((ch = getopt (argc, argv, "fp")) != EOF) {
505
 
        
 
747
 
506
748
                switch (ch) {
507
749
                        case 'f':
508
750
                                background = 0;
509
 
                                logsys_config_mode_set (LOG_MODE_OUTPUT_STDERR|LOG_MODE_FLUSH_AFTER_CONFIG);
 
751
                                logsys_config_mode_set (NULL, LOGSYS_MODE_OUTPUT_STDERR|LOGSYS_MODE_THREADED|LOGSYS_MODE_FORK);
510
752
                                break;
511
753
                        case 'p':
512
754
                                setprio = 0;
518
760
                                        "        -p     : Do not set process priority.    \n");
519
761
                                return EXIT_FAILURE;
520
762
                }
521
 
        }       
 
763
        }
522
764
 
523
765
        if (background)
524
 
                aisexec_tty_detach ();
525
 
 
526
 
        log_printf (LOG_LEVEL_NOTICE, "Corosync Executive Service RELEASE '%s'\n", RELEASE_VERSION);
527
 
        log_printf (LOG_LEVEL_NOTICE, "Copyright (C) 2002-2006 MontaVista Software, Inc and contributors.\n");
528
 
        log_printf (LOG_LEVEL_NOTICE, "Copyright (C) 2006-2008 Red Hat, Inc.\n");
529
 
 
530
 
        signal (SIGINT, sigintr_handler);
531
 
        signal (SIGUSR2, sigusr2_handler);
532
 
        signal (SIGSEGV, sigsegv_handler);
533
 
        signal (SIGABRT, sigabrt_handler);
534
 
        signal (SIGQUIT, sigquit_handler);
535
 
        
 
766
                corosync_tty_detach ();
 
767
 
 
768
        /*
 
769
         * Set round robin realtime scheduling with priority 99
 
770
         * Lock all memory to avoid page faults which may interrupt
 
771
         * application healthchecking
 
772
         */
 
773
        if (setprio) {
 
774
                corosync_setscheduler ();
 
775
        }
 
776
 
 
777
        corosync_mlockall ();
 
778
 
 
779
        log_printf (LOGSYS_LEVEL_NOTICE, "Corosync Cluster Engine ('%s'): started and ready to provide service.\n", RELEASE_VERSION);
 
780
 
 
781
        (void)signal (SIGINT, sigintr_handler);
 
782
        (void)signal (SIGUSR2, sigusr2_handler);
 
783
        (void)signal (SIGSEGV, sigsegv_handler);
 
784
        (void)signal (SIGABRT, sigabrt_handler);
 
785
        (void)signal (SIGQUIT, sigquit_handler);
 
786
#if MSG_NOSIGNAL == 0
 
787
        (void)signal (SIGPIPE, SIG_IGN);
 
788
#endif
 
789
 
536
790
        corosync_timer_init (
537
 
                serialize_mutex_lock,
538
 
                serialize_mutex_unlock);
539
 
 
540
 
        log_printf (LOG_LEVEL_NOTICE, "Corosync Executive Service: started and ready to provide service.\n");
541
 
 
542
 
        aisexec_poll_handle = poll_create (
543
 
                serialize_mutex_lock,
544
 
                serialize_mutex_unlock);
 
791
                serialize_lock,
 
792
                serialize_unlock,
 
793
                sched_priority);
 
794
 
 
795
        corosync_poll_handle = poll_create ();
545
796
 
546
797
        /*
547
798
         * Load the object database interface
553
804
                &objdb_p,
554
805
                0);
555
806
        if (res == -1) {
556
 
                log_printf (LOG_LEVEL_ERROR, "Corosync Executive couldn't open configuration object database component.\n");
 
807
                log_printf (LOGSYS_LEVEL_ERROR, "Corosync Executive couldn't open configuration object database component.\n");
557
808
                corosync_exit_error (AIS_DONE_OBJDB);
558
809
        }
559
810
 
574
825
         * the corosync default built in parser if the configuration parser
575
826
         * isn't overridden
576
827
         */
577
 
        config_iface = getenv("COROSYNC_DEFAULT_CONFIG_IFACE");
578
 
        if (!config_iface) {
579
 
                config_iface = "corosync_parser";
 
828
        config_iface_init = getenv("COROSYNC_DEFAULT_CONFIG_IFACE");
 
829
        if (!config_iface_init) {
 
830
                config_iface_init = "corosync_parser";
580
831
        }
581
832
 
582
833
        /* Make a copy so we can deface it with strtok */
583
 
        config_iface = strdup(config_iface);
 
834
        if ((config_iface = strdup(config_iface_init)) == NULL) {
 
835
                log_printf (LOGSYS_LEVEL_ERROR, "exhausted virtual memory");
 
836
                corosync_exit_error (AIS_DONE_OBJDB);
 
837
        }
584
838
 
585
839
        iface = strtok(config_iface, ":");
586
840
        while (iface)
594
848
 
595
849
                config = (struct config_iface_ver0 *)config_p;
596
850
                if (res == -1) {
597
 
                        log_printf (LOG_LEVEL_ERROR, "Corosync Executive couldn't open configuration component '%s'\n", iface);
 
851
                        log_printf (LOGSYS_LEVEL_ERROR, "Corosync Executive couldn't open configuration component '%s'\n", iface);
598
852
                        corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
599
853
                }
600
854
 
601
855
                res = config->config_readconfig(objdb, &error_string);
602
856
                if (res == -1) {
603
 
                        log_printf (LOG_LEVEL_ERROR, error_string);
 
857
                        log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
604
858
                        corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
605
859
                }
606
 
                log_printf (LOG_LEVEL_NOTICE, error_string);
 
860
                log_printf (LOGSYS_LEVEL_NOTICE, "%s", error_string);
607
861
                config_modules[num_config_modules++] = config;
608
862
 
609
863
                iface = strtok(NULL, ":");
610
864
        }
611
 
        if (config_iface)
612
 
                free(config_iface);
 
865
        free(config_iface);
613
866
 
614
 
        res = corosync_main_config_read (objdb, &error_string, &main_config);
 
867
        res = corosync_main_config_read (objdb, &error_string);
615
868
        if (res == -1) {
616
 
                log_printf (LOG_LEVEL_ERROR, error_string);
 
869
                /*
 
870
                 * if we are here, we _must_ flush the logsys queue
 
871
                 * and try to inform that we couldn't read the config.
 
872
                 * this is a desperate attempt before certain death
 
873
                 * and there is no guarantee that we can print to stderr
 
874
                 * nor that logsys is sending the messages where we expect.
 
875
                 */
 
876
                log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
 
877
                fprintf(stderr, "%s", error_string);
 
878
                syslog (LOGSYS_LEVEL_ERROR, "%s", error_string);
617
879
                corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
618
880
        }
 
881
        logsys_fork_completed();
 
882
        if (setprio) {
 
883
                res = logsys_thread_priority_set (SCHED_RR, &global_sched_param, 10);
 
884
                if (res == -1) {
 
885
                        log_printf (LOGSYS_LEVEL_ERROR,
 
886
                                "Could not set logsys thread priority.  Can't continue because of priority inversions.");
 
887
                        corosync_exit_error (AIS_DONE_LOGSETUP);
 
888
                }
 
889
        } else {
 
890
                res = logsys_thread_priority_set (SCHED_OTHER, NULL, 1);
 
891
        }
 
892
 
 
893
        /*
 
894
         * Make sure required directory is present
 
895
         */
 
896
        sprintf (corosync_lib_dir, "%s/lib/corosync", LOCALSTATEDIR);
 
897
        res = stat (corosync_lib_dir, &stat_out);
 
898
        if ((res == -1) || (res == 0 && !S_ISDIR(stat_out.st_mode))) {
 
899
                log_printf (LOGSYS_LEVEL_ERROR, "Required directory not present %s.  Please create it.\n", corosync_lib_dir);
 
900
                corosync_exit_error (AIS_DONE_DIR_NOT_PRESENT);
 
901
        }
619
902
 
620
903
        res = totem_config_read (objdb, &totem_config, &error_string);
621
904
        if (res == -1) {
622
 
                log_printf (LOG_LEVEL_ERROR, error_string);
 
905
                log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
623
906
                corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
624
907
        }
625
908
 
626
909
        res = totem_config_keyread (objdb, &totem_config, &error_string);
627
910
        if (res == -1) {
628
 
                log_printf (LOG_LEVEL_ERROR, error_string);
 
911
                log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
629
912
                corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
630
913
        }
631
914
 
632
915
        res = totem_config_validate (&totem_config, &error_string);
633
916
        if (res == -1) {
634
 
                log_printf (LOG_LEVEL_ERROR, error_string);
 
917
                log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
635
918
                corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
636
919
        }
637
920
 
638
 
        logsys_config_facility_set ("corosync", main_config.syslog_facility);
639
 
        logsys_config_mode_set (main_config.logmode);
640
 
        logsys_config_file_set (&error_string, main_config.logfile);
641
 
 
642
 
        aisexec_uid_determine (&main_config);
643
 
 
644
 
        aisexec_gid_determine (&main_config);
645
 
 
646
 
        /*
647
 
         * Set round robin realtime scheduling with priority 99
648
 
         * Lock all memory to avoid page faults which may interrupt
649
 
         * application healthchecking
650
 
         */
651
 
        if (setprio)
652
 
                aisexec_setscheduler ();
653
 
 
654
 
        aisexec_mlockall ();
655
 
 
656
921
        totem_config.totem_logging_configuration = totem_logging_configuration;
657
 
        totem_log_service = _logsys_subsys_create ("TOTEM", LOG_INFO);
658
 
        totem_config.totem_logging_configuration.log_level_security = logsys_mkpri (LOG_LEVEL_SECURITY, totem_log_service);
659
 
        totem_config.totem_logging_configuration.log_level_error = logsys_mkpri (LOG_LEVEL_ERROR, totem_log_service);
660
 
        totem_config.totem_logging_configuration.log_level_warning = logsys_mkpri (LOG_LEVEL_WARNING, totem_log_service);
661
 
        totem_config.totem_logging_configuration.log_level_notice = logsys_mkpri (LOG_LEVEL_NOTICE, totem_log_service);
662
 
        totem_config.totem_logging_configuration.log_level_debug = logsys_mkpri (LOG_LEVEL_DEBUG, totem_log_service);
663
 
        totem_config.totem_logging_configuration.log_printf = logsys_log_printf;
 
922
        totem_config.totem_logging_configuration.log_subsys_id =
 
923
                _logsys_subsys_create ("TOTEM");
 
924
 
 
925
        if (totem_config.totem_logging_configuration.log_subsys_id < 0) {
 
926
                log_printf (LOGSYS_LEVEL_ERROR,
 
927
                        "Unable to initialize TOTEM logging subsystem\n");
 
928
                corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
 
929
        }
 
930
 
 
931
        totem_config.totem_logging_configuration.log_level_security = LOGSYS_LEVEL_WARNING;
 
932
        totem_config.totem_logging_configuration.log_level_error = LOGSYS_LEVEL_ERROR;
 
933
        totem_config.totem_logging_configuration.log_level_warning = LOGSYS_LEVEL_WARNING;
 
934
        totem_config.totem_logging_configuration.log_level_notice = LOGSYS_LEVEL_NOTICE;
 
935
        totem_config.totem_logging_configuration.log_level_debug = LOGSYS_LEVEL_DEBUG;
 
936
        totem_config.totem_logging_configuration.log_printf = _logsys_log_printf;
 
937
 
 
938
        res = corosync_main_config_compatibility_read (objdb,
 
939
                &minimum_sync_mode,
 
940
                &error_string);
 
941
        if (res == -1) {
 
942
                log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
 
943
                corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
 
944
        }
 
945
 
 
946
        res = corosync_main_config_compatibility_read (objdb,
 
947
                &minimum_sync_mode,
 
948
                &error_string);
 
949
        if (res == -1) {
 
950
                log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
 
951
                corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
 
952
        }
664
953
 
665
954
        /*
666
955
         * Sleep for a while to let other nodes in the cluster
667
956
         * understand that this node has been away (if it was
668
 
         * an aisexec restart).
 
957
         * an corosync restart).
669
958
         */
670
959
 
671
960
// TODO what is this hack for?  usleep(totem_config.token_timeout * 2000);
681
970
         *  and configuration change functions
682
971
         */
683
972
        totempg_initialize (
684
 
                aisexec_poll_handle,
 
973
                corosync_poll_handle,
685
974
                &totem_config);
686
975
 
687
976
        totempg_groups_initialize (
699
988
         */
700
989
        res = corosync_service_defaults_link_and_init (api);
701
990
        if (res == -1) {
702
 
                log_printf (LOG_LEVEL_ERROR, "Could not initialize default services\n");
 
991
                log_printf (LOGSYS_LEVEL_ERROR, "Could not initialize default services\n");
703
992
                corosync_exit_error (AIS_DONE_INIT_SERVICES);
704
993
        }
705
 
 
706
 
 
707
 
        sync_register (corosync_sync_callbacks_retrieve, corosync_sync_completed,
708
 
                totem_config.vsf_type);
709
 
 
710
 
 
711
 
        res = corosync_flow_control_initialize ();
 
994
        evil_init (api);
 
995
 
 
996
        if (minimum_sync_mode == CS_SYNC_V2) {
 
997
                log_printf (LOGSYS_LEVEL_NOTICE, "Compatibility mode set to none.  Using V2 of the synchronization engine.\n");
 
998
                sync_v2_init (
 
999
                        corosync_sync_v2_callbacks_retrieve,
 
1000
                        corosync_sync_completed);
 
1001
        } else
 
1002
        if (minimum_sync_mode == CS_SYNC_V1) {
 
1003
                log_printf (LOGSYS_LEVEL_NOTICE, "Compatibility mode set to whitetank.  Using V1 and V2 of the synchronization engine.\n");
 
1004
                sync_register (
 
1005
                        corosync_sync_callbacks_retrieve,
 
1006
                        sync_v2_memb_list_determine,
 
1007
                        sync_v2_memb_list_abort,
 
1008
                        sync_v2_start);
 
1009
 
 
1010
                sync_v2_init (
 
1011
                        corosync_sync_v2_callbacks_retrieve,
 
1012
                        corosync_sync_completed);
 
1013
        }
 
1014
 
712
1015
 
713
1016
        /*
714
1017
         * Drop root privleges to user 'ais'
718
1021
         * CAP_SYS_NICE (setscheduler)
719
1022
         * CAP_IPC_LOCK (mlockall)
720
1023
         */
721
 
        aisexec_priv_drop ();
722
 
 
723
 
        aisexec_mempool_init ();
724
 
 
725
 
        corosync_ipc_init (
726
 
                serialize_mutex_lock,
727
 
                serialize_mutex_unlock,
728
 
                gid_valid);
 
1024
        priv_drop ();
 
1025
 
 
1026
        schedwrk_init (
 
1027
                serialize_lock,
 
1028
                serialize_unlock);
 
1029
 
 
1030
        ipc_subsys_id = _logsys_subsys_create ("IPC");
 
1031
        if (ipc_subsys_id < 0) {
 
1032
                log_printf (LOGSYS_LEVEL_ERROR,
 
1033
                        "Could not initialize IPC logging subsystem\n");
 
1034
                corosync_exit_error (AIS_DONE_INIT_SERVICES);
 
1035
        }
 
1036
 
 
1037
        coroipcs_ipc_init (&ipc_init_state);
729
1038
 
730
1039
        /*
731
1040
         * Start main processing loop
732
1041
         */
733
 
        poll_run (aisexec_poll_handle);
 
1042
        poll_run (corosync_poll_handle);
734
1043
 
735
1044
        return EXIT_SUCCESS;
736
1045
}