~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): Andres Rodriguez
  • Date: 2010-07-02 01:24:53 UTC
  • mfrom: (1.1.4 upstream) (5.1.9 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100702012453-qky79tg6hjly2dmq
Tags: 1.2.1-1ubuntu1
* Merge from debian unstable (LP: #600900). Remaining changes:
  - Raised consensus time out to 5000ms
  - debian/control, debian/rules: Removing now-unnecessary quilt build-dep

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
#include <signal.h>
57
57
#include <sched.h>
58
58
#include <time.h>
 
59
#include <semaphore.h>
59
60
 
60
61
#include <corosync/swab.h>
61
62
#include <corosync/corotypes.h>
121
122
 
122
123
static enum cs_sync_mode minimum_sync_mode;
123
124
 
124
 
static enum cs_sync_mode minimum_sync_mode;
125
 
 
126
125
static int sync_in_process = 1;
127
126
 
128
127
static hdb_handle_t corosync_poll_handle;
133
132
 
134
133
static corosync_timer_handle_t corosync_stats_timer_handle;
135
134
 
 
135
static pthread_t corosync_exit_thread;
 
136
 
 
137
static sem_t corosync_exit_sem;
 
138
 
136
139
hdb_handle_t corosync_poll_handle_get (void)
137
140
{
138
141
        return (corosync_poll_handle);
151
154
 
152
155
static void unlink_all_completed (void)
153
156
{
154
 
        poll_stop (0);
 
157
        poll_stop (corosync_poll_handle);
155
158
        totempg_finalize ();
156
 
        coroipcs_ipc_exit ();
157
159
 
158
160
        corosync_exit_error (AIS_DONE_EXIT);
159
161
}
167
169
        if (called == 0) {
168
170
                called = 1;
169
171
        }
 
172
 
 
173
        sem_post (&corosync_exit_sem);
 
174
}
 
175
 
 
176
static void *corosync_exit_thread_handler (void *arg)
 
177
{
 
178
        sem_wait (&corosync_exit_sem);
 
179
 
170
180
        corosync_service_unlink_all (api, unlink_all_completed);
 
181
 
 
182
        return arg;
171
183
}
172
184
 
173
185
static void sigusr2_handler (int num)
261
273
                ais_service_index++) {
262
274
 
263
275
                if (ais_service[ais_service_index] != NULL
264
 
                        && ais_service[ais_service_index]->sync_mode == CS_SYNC_V1) {
 
276
                        && (ais_service[ais_service_index]->sync_mode == CS_SYNC_V1
 
277
                                || ais_service[ais_service_index]->sync_mode == CS_SYNC_V1_APIV2)) {
265
278
                        if (ais_service_index == sync_id) {
266
279
                                break;
267
280
                        }
275
288
                return (res);
276
289
        }
277
290
        callbacks->name = ais_service[ais_service_index]->name;
278
 
        callbacks->sync_init = ais_service[ais_service_index]->sync_init;
 
291
        callbacks->sync_init_api.sync_init_v1 = ais_service[ais_service_index]->sync_init;
 
292
        callbacks->api_version = 1;
 
293
        if (ais_service[ais_service_index]->sync_mode == CS_SYNC_V1_APIV2) {
 
294
                callbacks->api_version = 2;
 
295
        }
279
296
        callbacks->sync_process = ais_service[ais_service_index]->sync_process;
280
297
        callbacks->sync_activate = ais_service[ais_service_index]->sync_activate;
281
298
        callbacks->sync_abort = ais_service[ais_service_index]->sync_abort;
304
321
        }
305
322
 
306
323
        callbacks->name = ais_service[service_id]->name;
307
 
        callbacks->sync_init = ais_service[service_id]->sync_init;
 
324
 
 
325
        callbacks->api_version = 1;
 
326
        if (ais_service[service_id]->sync_mode == CS_SYNC_V1_APIV2) {
 
327
                callbacks->api_version = 2;
 
328
        }
 
329
 
 
330
        callbacks->sync_init_api.sync_init_v1 = ais_service[service_id]->sync_init;
308
331
        callbacks->sync_process = ais_service[service_id]->sync_process;
309
332
        callbacks->sync_activate = ais_service[service_id]->sync_activate;
310
333
        callbacks->sync_abort = ais_service[service_id]->sync_abort;
346
369
        if (abort_activate) {
347
370
                sync_v2_abort ();
348
371
        }
 
372
        if (minimum_sync_mode == CS_SYNC_V2 && configuration_type == TOTEM_CONFIGURATION_TRANSITIONAL) {
 
373
                sync_v2_save_transitional (member_list, member_list_entries, ring_id);
 
374
        }
349
375
        if (minimum_sync_mode == CS_SYNC_V2 && configuration_type == TOTEM_CONFIGURATION_REGULAR) {
350
376
                sync_v2_start (member_list, member_list_entries, ring_id);
351
377
        }
425
451
#else
426
452
        res = mlockall (MCL_CURRENT | MCL_FUTURE);
427
453
        if (res == -1) {
428
 
                log_printf (LOGSYS_LEVEL_WARNING, "Could not lock memory of service to avoid page faults: %s\n", strerror (errno));
 
454
                char error_str[100];
 
455
                strerror_r (errno, error_str, 100);
 
456
                log_printf (LOGSYS_LEVEL_WARNING,
 
457
                        "Could not lock memory of service to avoid page faults: %s\n",
 
458
                        error_str);
429
459
        };
430
460
#endif
431
461
}
828
858
 
829
859
static int corosync_service_available (unsigned int service)
830
860
{
831
 
        return (ais_service[service] != NULL);
 
861
        return (ais_service[service] != NULL && !ais_service_exiting[service]);
832
862
}
833
863
 
834
864
struct sending_allowed_private_data_struct {
934
964
                corosync_poll_handler_dispatch);
935
965
}
936
966
 
 
967
static void corosync_poll_dispatch_destroy (
 
968
    int fd,
 
969
    void *context)
 
970
{
 
971
        poll_dispatch_delete (corosync_poll_handle, fd);
 
972
}
937
973
 
938
974
static hdb_handle_t corosync_stats_create_connection (const char* name,
939
975
                       const pid_t pid, const int fd)
1071
1107
        .poll_accept_add                = corosync_poll_accept_add,
1072
1108
        .poll_dispatch_add              = corosync_poll_dispatch_add,
1073
1109
        .poll_dispatch_modify           = corosync_poll_dispatch_modify,
 
1110
        .poll_dispatch_destroy          = corosync_poll_dispatch_destroy,
1074
1111
        .init_fn_get                    = corosync_init_fn_get,
1075
1112
        .exit_fn_get                    = corosync_exit_fn_get,
1076
1113
        .handler_fn_get                 = corosync_handler_fn_get,
1091
1128
                global_sched_param.sched_priority = sched_priority;
1092
1129
                res = sched_setscheduler (0, SCHED_RR, &global_sched_param);
1093
1130
                if (res == -1) {
 
1131
                        char error_str[100];
 
1132
                        strerror_r (errno, error_str, 100);
1094
1133
                        global_sched_param.sched_priority = 0;
1095
1134
                        log_printf (LOGSYS_LEVEL_WARNING, "Could not set SCHED_RR at priority %d: %s\n",
1096
 
                                global_sched_param.sched_priority, strerror (errno));
 
1135
                                global_sched_param.sched_priority, error_str);
1097
1136
 
1098
1137
                        logsys_thread_priority_set (SCHED_OTHER, NULL, 1);
1099
1138
                } else {
1114
1153
                        }
1115
1154
                }
1116
1155
        } else {
1117
 
                log_printf (LOGSYS_LEVEL_WARNING, "Could not get maximum scheduler priority: %s\n", strerror (errno));
 
1156
                char error_str[100];
 
1157
                strerror_r (errno, error_str, 100);
 
1158
                log_printf (LOGSYS_LEVEL_WARNING,
 
1159
                        "Could not get maximum scheduler priority: %s\n",
 
1160
                        error_str);
1118
1161
                sched_priority = 0;
1119
1162
        }
1120
1163
#else
1166
1209
        evil_init (api);
1167
1210
        corosync_stats_init ();
1168
1211
        corosync_totem_stats_init ();
 
1212
        if (minimum_sync_mode == CS_SYNC_V2) {
 
1213
                log_printf (LOGSYS_LEVEL_NOTICE, "Compatibility mode set to none.  Using V2 of the synchronization engine.\n");
 
1214
                sync_v2_init (
 
1215
                        corosync_sync_v2_callbacks_retrieve,
 
1216
                        corosync_sync_completed);
 
1217
        } else
 
1218
        if (minimum_sync_mode == CS_SYNC_V1) {
 
1219
                log_printf (LOGSYS_LEVEL_NOTICE, "Compatibility mode set to whitetank.  Using V1 and V2 of the synchronization engine.\n");
 
1220
                sync_register (
 
1221
                        corosync_sync_callbacks_retrieve,
 
1222
                        sync_v2_memb_list_determine,
 
1223
                        sync_v2_memb_list_abort,
 
1224
                        sync_v2_start);
 
1225
 
 
1226
                sync_v2_init (
 
1227
                        corosync_sync_v2_callbacks_retrieve,
 
1228
                        corosync_sync_completed);
 
1229
        }
 
1230
 
 
1231
 
1169
1232
}
1170
1233
 
1171
1234
int main (int argc, char **argv)
1181
1244
        const char *config_iface_init;
1182
1245
        char *config_iface;
1183
1246
        char *iface;
 
1247
        char *strtok_save_pt;
1184
1248
        int res, ch;
1185
1249
        int background, setprio;
1186
1250
        struct stat stat_out;
1288
1352
                corosync_exit_error (AIS_DONE_OBJDB);
1289
1353
        }
1290
1354
 
1291
 
        iface = strtok(config_iface, ":");
 
1355
        iface = strtok_r(config_iface, ":", &strtok_save_pt);
1292
1356
        while (iface)
1293
1357
        {
1294
1358
                res = lcr_ifact_reference (
1312
1376
                log_printf (LOGSYS_LEVEL_NOTICE, "%s", error_string);
1313
1377
                config_modules[num_config_modules++] = config;
1314
1378
 
1315
 
                iface = strtok(NULL, ":");
 
1379
                iface = strtok_r(NULL, ":", &strtok_save_pt);
1316
1380
        }
1317
1381
        free(config_iface);
1318
1382
 
1421
1485
// TODO what is this hack for?  usleep(totem_config.token_timeout * 2000);
1422
1486
 
1423
1487
        /*
 
1488
         * Create semaphore and start "exit" thread
 
1489
         */
 
1490
        res = sem_init (&corosync_exit_sem, 0, 0);
 
1491
        if (res != 0) {
 
1492
                log_printf (LOGSYS_LEVEL_ERROR, "Corosync Executive couldn't create exit thread.\n");
 
1493
                corosync_exit_error (AIS_DONE_FATAL_ERR);
 
1494
        }
 
1495
 
 
1496
        res = pthread_create (&corosync_exit_thread, NULL, corosync_exit_thread_handler, NULL);
 
1497
        if (res != 0) {
 
1498
                log_printf (LOGSYS_LEVEL_ERROR, "Corosync Executive couldn't create exit thread.\n");
 
1499
                corosync_exit_error (AIS_DONE_FATAL_ERR);
 
1500
        }
 
1501
 
 
1502
        /*
1424
1503
         * if totempg_initialize doesn't have root priveleges, it cannot
1425
1504
         * bind to a specific interface.  This only matters if
1426
1505
         * there is more then one interface in a system, so
1447
1526
                &corosync_group,
1448
1527
                1);
1449
1528
 
1450
 
        if (minimum_sync_mode == CS_SYNC_V2) {
1451
 
                log_printf (LOGSYS_LEVEL_NOTICE, "Compatibility mode set to none.  Using V2 of the synchronization engine.\n");
1452
 
                sync_v2_init (
1453
 
                        corosync_sync_v2_callbacks_retrieve,
1454
 
                        corosync_sync_completed);
1455
 
        } else
1456
 
        if (minimum_sync_mode == CS_SYNC_V1) {
1457
 
                log_printf (LOGSYS_LEVEL_NOTICE, "Compatibility mode set to whitetank.  Using V1 and V2 of the synchronization engine.\n");
1458
 
                sync_register (
1459
 
                        corosync_sync_callbacks_retrieve,
1460
 
                        sync_v2_memb_list_determine,
1461
 
                        sync_v2_memb_list_abort,
1462
 
                        sync_v2_start);
1463
 
 
1464
 
                sync_v2_init (
1465
 
                        corosync_sync_v2_callbacks_retrieve,
1466
 
                        corosync_sync_completed);
1467
 
        }
1468
 
 
1469
 
 
1470
1529
        /*
1471
1530
         * Drop root privleges to user 'ais'
1472
1531
         * TODO: Don't really need full root capabilities;