~ubuntu-branches/ubuntu/natty/redhat-cluster/natty

« back to all changes in this revision

Viewing changes to cman/daemon/cman-preconfig.c

  • Committer: Bazaar Package Importer
  • Author(s): Ante Karamatic
  • Date: 2009-09-15 07:15:43 UTC
  • mfrom: (1.1.16 upstream) (10.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090915071543-vr089k11l3kl9llu
Tags: 3.0.2-2ubuntu1
Remove unnecessary build dep on libvolume-id-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
#include <sys/socket.h>
10
10
#include <sys/errno.h>
11
11
#include <netdb.h>
 
12
#include <fcntl.h>
12
13
#define SYSLOG_NAMES
13
14
#include <sys/syslog.h>
14
15
#include <ifaddrs.h>
24
25
#define OBJDB_API struct objdb_iface_ver0
25
26
#include "cnxman-socket.h"
26
27
#include "nodelist.h"
27
 
#include "logging.h"
28
28
 
29
29
#define MAX_PATH_LEN PATH_MAX
30
30
 
31
 
static unsigned int debug_mask;
32
 
static int cmanpre_readconfig(struct objdb_iface_ver0 *objdb, char **error_string);
33
 
static int cmanpre_reloadconfig(struct objdb_iface_ver0 *objdb, int flush, char **error_string);
 
31
static unsigned int debug;
 
32
static int cmanpre_readconfig(struct objdb_iface_ver0 *objdb, const char **error_string);
 
33
static int cmanpre_reloadconfig(struct objdb_iface_ver0 *objdb, int flush, const char **error_string);
34
34
 
35
35
static char *nodename_env;
36
36
static int expected_votes;
48
48
static char *mcast_name;
49
49
static char *cluster_name;
50
50
static char error_reason[1024] = { '\0' };
51
 
static unsigned int cluster_parent_handle;
 
51
static hdb_handle_t cluster_parent_handle;
52
52
 
53
53
/*
54
54
 * Exports the interface for the service
116
116
static int ipaddr_equal(struct sockaddr_storage *addr1, struct sockaddr_storage *addr2)
117
117
{
118
118
        int addrlen = 0;
119
 
        struct sockaddr *saddr1 = (struct sockaddr *)addr1;
120
 
        struct sockaddr *saddr2 = (struct sockaddr *)addr2;
121
119
 
122
 
        if (saddr1->sa_family != saddr2->sa_family)
 
120
        if (addr1->ss_family != addr2->ss_family)
123
121
                return 0;
124
122
 
125
 
        if (saddr1->sa_family == AF_INET) {
 
123
        if (addr1->ss_family == AF_INET) {
126
124
                addrlen = sizeof(struct sockaddr_in);
127
125
        }
128
 
        if (saddr1->sa_family == AF_INET6) {
 
126
        if (addr1->ss_family == AF_INET6) {
129
127
                addrlen = sizeof(struct sockaddr_in6);
130
128
        }
131
129
        assert(addrlen);
132
130
 
133
 
        if (memcmp(saddr1, saddr2, addrlen) == 0)
 
131
        if (memcmp(addr1, addr2, addrlen) == 0)
134
132
                return 1;
135
133
        else
136
134
                return 0;
140
138
/* Build a localhost ip_address */
141
139
static int get_localhost(int family, struct sockaddr_storage *localhost)
142
140
{
143
 
        char *addr_text;
 
141
        const char *addr_text;
144
142
        struct addrinfo *ainfo;
145
143
        struct addrinfo ahints;
146
144
        int ret;
198
196
/* Find the "CMAN" logger_subsys object. Or create one if it does not
199
197
   exist
200
198
*/
201
 
static unsigned int find_cman_logger(struct objdb_iface_ver0 *objdb, unsigned int object_handle)
 
199
static hdb_handle_t find_cman_logger(struct objdb_iface_ver0 *objdb, hdb_handle_t object_handle)
202
200
{
203
 
        unsigned int subsys_handle;
204
 
        unsigned int find_handle;
 
201
        hdb_handle_t subsys_handle;
 
202
        hdb_handle_t find_handle;
205
203
        char *str;
206
204
 
207
205
        objdb->object_find_create(object_handle, "logger_subsys", strlen("logger_subsys"), &find_handle);
208
 
        while (!objdb->object_find_next(object_handle, &subsys_handle)) {
209
 
 
210
 
                if (objdb_get_string(objdb, subsys_handle, "subsys", &str)) {
211
 
                        continue;
 
206
        while (!objdb->object_find_next(find_handle, &subsys_handle)) {
 
207
                if (!objdb_get_string(objdb, subsys_handle, "subsys", &str)) {
 
208
                        if (strncmp(str, CMAN_NAME, 4) == 0) {
 
209
                                objdb->object_find_destroy(find_handle);
 
210
                                return subsys_handle;
 
211
                        }
212
212
                }
213
 
                if (strcmp(str, CMAN_NAME) == 0)
214
 
                        return subsys_handle;
215
213
        }
216
214
        objdb->object_find_destroy(find_handle);
217
215
 
218
 
        /* We can't find it ... create one */
219
 
        if (objdb->object_create(object_handle, &subsys_handle,
220
 
                                    "logger_subsys", strlen("logger_subsys")) == 0) {
221
 
 
222
 
                objdb->object_key_create(subsys_handle, "subsys", strlen("subsys"),
223
 
                                            CMAN_NAME, strlen(CMAN_NAME)+1);
224
 
        }
225
 
 
226
 
        return subsys_handle;
 
216
        return -1;
227
217
 
228
218
}
229
219
 
230
220
 
231
 
static int add_ifaddr(struct objdb_iface_ver0 *objdb, char *mcast, char *ifaddr, int portnum)
 
221
static int add_ifaddr(struct objdb_iface_ver0 *objdb, char *mcast, char *ifaddr, int port, int broadcast)
232
222
{
233
 
        unsigned int totem_object_handle;
234
 
        unsigned int find_handle;
235
 
        unsigned int interface_object_handle;
 
223
        hdb_handle_t totem_object_handle;
 
224
        hdb_handle_t find_handle;
 
225
        hdb_handle_t interface_object_handle;
236
226
        struct sockaddr_storage if_addr, localhost, mcast_addr;
237
227
        char tmp[132];
238
228
        int ret = 0;
277
267
                objdb->object_key_create(interface_object_handle, "bindnetaddr", strlen("bindnetaddr"),
278
268
                                         tmp, strlen(tmp)+1);
279
269
 
280
 
                objdb->object_key_create(interface_object_handle, "mcastaddr", strlen("mcastaddr"),
281
 
                                         mcast, strlen(mcast)+1);
 
270
                if (broadcast)
 
271
                        objdb->object_key_create(interface_object_handle, "broadcast", strlen("broadcast"),
 
272
                                                 "yes", strlen("yes")+1);
 
273
                else
 
274
                        objdb->object_key_create(interface_object_handle, "mcastaddr", strlen("mcastaddr"),
 
275
                                                 mcast, strlen(mcast)+1);
282
276
 
283
 
                sprintf(tmp, "%d", portnum);
 
277
                sprintf(tmp, "%d", port);
284
278
                objdb->object_key_create(interface_object_handle, "mcastport", strlen("mcastport"),
285
279
                                         tmp, strlen(tmp)+1);
286
280
 
302
296
        return value & 0xFFFF;
303
297
}
304
298
 
305
 
static char *default_mcast(char *nodename, uint16_t cluster_id)
 
299
static char *default_mcast(char *node, uint16_t clusterid)
306
300
{
307
301
        struct addrinfo *ainfo;
308
302
        struct addrinfo ahints;
314
308
 
315
309
        /* Lookup the the nodename address and use it's IP type to
316
310
           default a multicast address */
317
 
        ret = getaddrinfo(nodename, NULL, &ahints, &ainfo);
 
311
        ret = getaddrinfo(node, NULL, &ahints, &ainfo);
318
312
        if (ret) {
319
 
                sprintf(error_reason, "Can't determine address family of nodename %s\n", nodename);
 
313
                sprintf(error_reason, "Can't determine address family of nodename %s\n", node);
320
314
                write_cman_pipe("Can't determine address family of nodename");
321
315
                return NULL;
322
316
        }
325
319
        freeaddrinfo(ainfo);
326
320
 
327
321
        if (family == AF_INET) {
328
 
                snprintf(addr, sizeof(addr), "239.192.%d.%d", cluster_id >> 8, cluster_id % 0xFF);
 
322
                snprintf(addr, sizeof(addr), "239.192.%d.%d", clusterid >> 8, clusterid % 0xFF);
329
323
                return addr;
330
324
        }
331
325
        if (family == AF_INET6) {
332
 
                snprintf(addr, sizeof(addr), "ff15::%x", cluster_id);
 
326
                snprintf(addr, sizeof(addr), "ff15::%x", clusterid);
333
327
                return addr;
334
328
        }
335
329
 
336
330
        return NULL;
337
331
}
338
332
 
339
 
static int verify_nodename(struct objdb_iface_ver0 *objdb, char *nodename)
 
333
static int verify_nodename(struct objdb_iface_ver0 *objdb, char *node)
340
334
{
341
335
        char nodename2[MAX_CLUSTER_MEMBER_NAME_LEN+1];
342
336
        char nodename3[MAX_CLUSTER_MEMBER_NAME_LEN+1];
343
337
        char *str, *dot = NULL;
344
338
        struct ifaddrs *ifa, *ifa_list;
345
339
        struct sockaddr *sa;
346
 
        unsigned int nodes_handle;
347
 
        unsigned int find_handle = 0;
 
340
        hdb_handle_t nodes_handle;
 
341
        hdb_handle_t find_handle = 0;
348
342
        int error;
349
343
 
350
344
        /* nodename is either from commandline or from uname */
351
 
        if (nodelist_byname(objdb, cluster_parent_handle, nodename))
 
345
        if (nodelist_byname(objdb, cluster_parent_handle, node))
352
346
                return 0;
353
347
 
354
348
        /* If nodename was from uname, try a domain-less version of it */
355
 
        strcpy(nodename2, nodename);
 
349
        strcpy(nodename2, node);
356
350
        dot = strchr(nodename2, '.');
357
351
        if (dot) {
358
352
                *dot = '\0';
359
353
 
360
354
                if (nodelist_byname(objdb, cluster_parent_handle, nodename2)) {
361
 
                        strcpy(nodename, nodename2);
 
355
                        strcpy(node, nodename2);
362
356
                        return 0;
363
357
                }
364
358
        }
384
378
 
385
379
                if (strlen(nodename2) == len &&
386
380
                    !strncmp(nodename2, nodename3, len)) {
387
 
                        strcpy(nodename, str);
 
381
                        strcpy(node, str);
388
382
                        return 0;
389
383
                }
390
384
                nodes_handle = nodeslist_next(objdb, find_handle);
400
394
                return -1;
401
395
 
402
396
        for (ifa = ifa_list; ifa; ifa = ifa->ifa_next) {
 
397
                socklen_t salen = 0;
 
398
 
403
399
                /* Restore this */
404
 
                strcpy(nodename2, nodename);
 
400
                strcpy(nodename2, node);
405
401
                sa = ifa->ifa_addr;
406
 
                if (!sa || sa->sa_family != AF_INET)
407
 
                        continue;
408
 
 
409
 
                error = getnameinfo(sa, sizeof(*sa), nodename2,
 
402
                if (!sa)
 
403
                        continue;
 
404
                if (sa->sa_family != AF_INET && sa->sa_family != AF_INET6)
 
405
                        continue;
 
406
 
 
407
                if (sa->sa_family == AF_INET)
 
408
                        salen = sizeof(struct sockaddr_in);
 
409
                if (sa->sa_family == AF_INET6)
 
410
                        salen = sizeof(struct sockaddr_in6);
 
411
 
 
412
                error = getnameinfo(sa, salen, nodename2,
410
413
                                    sizeof(nodename2), NULL, 0, 0);
411
 
                if (error)
412
 
                        goto out;
413
 
 
414
 
                if (nodelist_byname(objdb, cluster_parent_handle, nodename2)) {
415
 
                        strcpy(nodename, nodename2);
416
 
                        goto out;
417
 
                }
418
 
 
419
 
                /* truncate this name and try again */
420
 
 
421
 
                dot = strchr(nodename2, '.');
422
 
                if (!dot)
423
 
                        continue;
424
 
                *dot = '\0';
425
 
 
426
 
                if (nodelist_byname(objdb, cluster_parent_handle, nodename2)) {
427
 
                        strcpy(nodename, nodename2);
428
 
                        goto out;
 
414
                if (!error) {
 
415
 
 
416
                        if (nodelist_byname(objdb, cluster_parent_handle, nodename2)) {
 
417
                                strcpy(node, nodename2);
 
418
                                goto out;
 
419
                        }
 
420
 
 
421
                        /* Truncate this name and try again */
 
422
                        dot = strchr(nodename2, '.');
 
423
                        if (dot) {
 
424
                                *dot = '\0';
 
425
 
 
426
                                if (nodelist_byname(objdb, cluster_parent_handle, nodename2)) {
 
427
                                        strcpy(node, nodename2);
 
428
                                        goto out;
 
429
                                }
 
430
                        }
429
431
                }
430
432
 
431
433
                /* See if it's the IP address that's in cluster.conf */
432
434
                error = getnameinfo(sa, sizeof(*sa), nodename2,
433
435
                                    sizeof(nodename2), NULL, 0, NI_NUMERICHOST);
434
436
                if (error)
435
 
                        goto out;
 
437
                        continue;
436
438
 
437
439
                if (nodelist_byname(objdb, cluster_parent_handle, nodename2)) {
438
 
                        strcpy(nodename, nodename2);
 
440
                        strcpy(node, nodename2);
439
441
                        goto out;
440
442
                }
441
443
        }
447
449
}
448
450
 
449
451
/* Get any environment variable overrides */
450
 
static int get_env_overrides()
 
452
static int get_env_overrides(void)
451
453
{
452
454
        if (getenv("CMAN_CLUSTER_NAME")) {
453
455
                cluster_name = strdup(getenv("CMAN_CLUSTER_NAME"));
496
498
                expected_votes = 1;
497
499
                votes = 1;
498
500
        }
499
 
        if (getenv("CMAN_DEBUGLOG")) {
500
 
                debug_mask = atoi(getenv("CMAN_DEBUGLOG"));
 
501
        if (getenv("CMAN_DEBUG")) {
 
502
                debug = atoi(getenv("CMAN_DEBUG"));
 
503
                if (debug > 0)
 
504
                        debug = 1;
501
505
        }
502
506
 
503
507
        return 0;
507
511
static int get_nodename(struct objdb_iface_ver0 *objdb)
508
512
{
509
513
        char *nodeid_str = NULL;
510
 
        unsigned int object_handle;
511
 
        unsigned int find_handle;
512
 
        unsigned int node_object_handle;
513
 
        unsigned int alt_object;
 
514
        hdb_handle_t object_handle;
 
515
        hdb_handle_t find_handle;
 
516
        hdb_handle_t node_object_handle;
 
517
        hdb_handle_t alt_object;
 
518
        int broadcast = 0;
 
519
        char *str;
514
520
        int error;
515
521
 
516
522
        if (!getenv("CMAN_NOCONFIG")) {
538
544
                        error = uname(&utsname);
539
545
                        if (error) {
540
546
                                sprintf(error_reason, "cannot get node name, uname failed");
541
 
                                write_cman_pipe("Can't determine local node name");
 
547
                                write_cman_pipe("Can't determine local node name, uname failed");
542
548
                                error = -1;
543
549
                                goto out;
544
550
                        }
545
551
 
546
552
                        if (strlen(utsname.nodename) >= sizeof(nodename)) {
547
553
                                sprintf(error_reason, "node name from uname is too long");
548
 
                                write_cman_pipe("Can't determine local node name");
 
554
                                write_cman_pipe("local node name is too long");
549
555
                                error = -1;
550
556
                                goto out;
551
557
                        }
552
558
 
553
559
                        strcpy(nodename, utsname.nodename);
554
560
                }
555
 
                if (verify_nodename(objdb, nodename))
 
561
                if (verify_nodename(objdb, nodename)) {
 
562
                        write_cman_pipe("Cannot find node name in cluster.conf");
556
563
                        return -1;
 
564
                }
557
565
 
558
566
        }
559
567
 
570
578
 
571
579
        if (objdb->object_find_next(find_handle, &object_handle) == 0) {
572
580
 
573
 
                unsigned int mcast_handle;
574
 
                unsigned int find_handle2;
 
581
                hdb_handle_t mcast_handle;
 
582
                hdb_handle_t find_handle2;
575
583
 
576
584
                if (!mcast_name) {
577
585
 
585
593
 
586
594
                if (!mcast_name) {
587
595
                        mcast_name = default_mcast(nodename, cluster_id);
 
596
 
588
597
                }
 
598
                if (!mcast_name)
 
599
                        return -1;
589
600
 
590
601
                /* See if the user wants our default set of openais services (default=yes) */
591
602
                objdb_get_int(objdb, object_handle, "disable_openais", &disable_openais, 0);
603
614
                objdb_get_int(objdb, object_handle, "port", &portnum, DEFAULT_PORT);
604
615
        }
605
616
 
606
 
        if (add_ifaddr(objdb, mcast_name, nodename, portnum))
 
617
        /* Check for broadcast */
 
618
        if (!objdb_get_string(objdb, object_handle, "broadcast", &str)) {
 
619
                if (strcmp(str, "yes") == 0) {
 
620
                        mcast_name = strdup("255.255.255.255");
 
621
                        if (!mcast_name)
 
622
                                return -1;
 
623
                        broadcast = 1;
 
624
                }
 
625
                free(str);
 
626
        }
 
627
 
 
628
        if (add_ifaddr(objdb, mcast_name, nodename, portnum, broadcast)) {
 
629
                write_cman_pipe(error_reason);
607
630
                return -1;
 
631
        }
608
632
 
609
633
        /* Get all alternative node names */
610
634
        num_nodenames = 1;
611
635
        objdb->object_find_create(node_object_handle,"altname", strlen("altname"), &find_handle);
612
636
        while (objdb->object_find_next(find_handle, &alt_object) == 0) {
613
637
                unsigned int port;
614
 
                char *nodename;
 
638
                char *node;
615
639
                char *mcast;
616
640
 
617
 
                if (objdb_get_string(objdb, alt_object, "name", &nodename)) {
 
641
                if (objdb_get_string(objdb, alt_object, "name", &node)) {
618
642
                        continue;
619
643
                }
620
644
 
624
648
                        mcast = mcast_name;
625
649
                }
626
650
 
627
 
                if (add_ifaddr(objdb, mcast, nodename, portnum))
 
651
                if (add_ifaddr(objdb, mcast, node, portnum, broadcast)) {
 
652
                        write_cman_pipe(error_reason);
628
653
                        return -1;
 
654
                }
629
655
 
630
656
                num_nodenames++;
631
657
        }
638
664
/* These are basically cman overrides to the totem config bits */
639
665
static void add_cman_overrides(struct objdb_iface_ver0 *objdb)
640
666
{
641
 
        unsigned int logger_object_handle;
642
667
        char *logstr;
643
668
        char *logfacility;
644
 
        unsigned int object_handle;
645
 
        unsigned int find_handle;
 
669
        char *loglevel;
 
670
        hdb_handle_t object_handle;
 
671
        hdb_handle_t find_handle;
646
672
        char tmp[256];
647
673
 
648
674
        /* "totem" key already exists, because we have added the interfaces by now */
739
765
        objdb->object_find_destroy(find_handle);
740
766
 
741
767
        logfacility = facility_name_get(SYSLOGFACILITY);
742
 
 
743
 
        logger_object_handle = find_cman_logger(objdb, object_handle);
 
768
        loglevel = priority_name_get(SYSLOGLEVEL);
 
769
 
 
770
        /* enable timestamps on logging */
 
771
        if (objdb_get_string(objdb, object_handle, "timestamp", &logstr)) {
 
772
                objdb->object_key_create(object_handle, "timestamp", strlen("timestamp"),
 
773
                                            "on", strlen("on")+1);
 
774
        }
 
775
 
 
776
        /* configure logfile */
 
777
        if (objdb_get_string(objdb, object_handle, "to_logfile", &logstr)) {
 
778
                objdb->object_key_create(object_handle, "to_logfile", strlen("to_logfile"),
 
779
                                            "yes", strlen("yes")+1);
 
780
        }
 
781
 
 
782
        if (objdb_get_string(objdb, object_handle, "logfile", &logstr)) {
 
783
                objdb->object_key_create(object_handle, "logfile", strlen("logfile"),
 
784
                                            LOGDIR "/corosync.log", strlen(LOGDIR "/corosync.log")+1);
 
785
        }
 
786
 
 
787
        if (objdb_get_string(objdb, object_handle, "logfile_priority", &logstr)) {
 
788
                objdb->object_key_create(object_handle, "logfile_priority", strlen("logfile_priority"),
 
789
                                            loglevel, strlen(loglevel)+1);
 
790
        }
 
791
 
 
792
        /* syslog */
 
793
        if (objdb_get_string(objdb, object_handle, "to_syslog", &logstr)) {
 
794
                objdb->object_key_create(object_handle, "to_syslog", strlen("to_syslog"),
 
795
                                            "yes", strlen("yes")+1);
 
796
        }
744
797
 
745
798
        if (objdb_get_string(objdb, object_handle, "syslog_facility", &logstr)) {
746
799
                objdb->object_key_create(object_handle, "syslog_facility", strlen("syslog_facility"),
747
800
                                            logfacility, strlen(logfacility)+1);
748
801
        }
749
802
 
750
 
        if (objdb_get_string(objdb, object_handle, "to_file", &logstr)) {
751
 
                objdb->object_key_create(object_handle, "to_file", strlen("to_file"),
752
 
                                            "yes", strlen("yes")+1);
753
 
        }
754
 
 
755
 
        if (objdb_get_string(objdb, object_handle, "logfile", &logstr)) {
756
 
                objdb->object_key_create(object_handle, "logfile", strlen("logfile"),
757
 
                                            LOGDIR "/cman.log", strlen(LOGDIR "/cman.log")+1);
758
 
        }
759
 
 
760
 
        if (debug_mask) {
 
803
        if (objdb_get_string(objdb, object_handle, "syslog_priority", &logstr)) {
 
804
                objdb->object_key_create(object_handle, "syslog_priority", strlen("syslog_priority"),
 
805
                                            loglevel, strlen(loglevel)+1);
 
806
        }
 
807
 
 
808
        if (!debug) {
 
809
                hdb_handle_t logger_object_handle;
 
810
 
 
811
                if (!objdb_get_string(objdb, object_handle, "debug", &logstr)) {
 
812
                        if (!strncmp(logstr, "on", 2)) {
 
813
                                debug=1;
 
814
                        }
 
815
                }
 
816
 
 
817
                logger_object_handle = find_cman_logger(objdb, object_handle);
 
818
                if (logger_object_handle > -1) {
 
819
                        if (!objdb_get_string(objdb, logger_object_handle, "debug", &logstr)) {
 
820
                                if (!strncmp(logstr, "on", 2)) {
 
821
                                        debug=1;
 
822
                                }
 
823
                                if (!strncmp(logstr, "off", 3)) {
 
824
                                        debug=0;
 
825
                                }
 
826
                        }
 
827
                }
 
828
        }
 
829
 
 
830
        if (debug) {
761
831
                objdb->object_key_create(object_handle, "to_stderr", strlen("to_stderr"),
762
832
                                            "yes", strlen("yes")+1);
763
 
                objdb->object_key_create(logger_object_handle, "debug", strlen("debug"),
764
 
                                            "on", strlen("on")+1);
765
 
                objdb->object_key_create(logger_object_handle, "syslog_level", strlen("syslog_level"),
766
 
                                            "debug", strlen("debug")+1);
767
 
 
768
 
        }
769
 
        else {
770
 
                char *loglevel;
771
 
                loglevel = priority_name_get(SYSLOGLEVEL);
772
 
                objdb->object_key_create(logger_object_handle, "syslog_level", strlen("syslog_level"),
773
 
                                            loglevel, strlen(loglevel)+1);
774
 
        }
775
 
 
776
 
 
777
 
        /* Don't run under user "ais" */
 
833
        }
 
834
 
 
835
        /* Make sure we allow connections from user/group "ais" */
778
836
        objdb->object_find_create(OBJECT_PARENT_HANDLE, "aisexec", strlen("aisexec"), &find_handle);
779
837
        if (objdb->object_find_next(find_handle, &object_handle) != 0) {
780
838
                objdb->object_create(OBJECT_PARENT_HANDLE, &object_handle,
781
839
                                        "aisexec", strlen("aisexec"));
782
 
 
783
840
        }
784
841
        objdb->object_find_destroy(find_handle);
785
842
        objdb->object_key_create(object_handle, "user", strlen("user"),
786
 
                                    "root", strlen("root") + 1);
 
843
                                    "ais", strlen("ais") + 1);
787
844
        objdb->object_key_create(object_handle, "group", strlen("group"),
788
 
                                    "root", strlen("root") + 1);
 
845
                                    "ais", strlen("ais") + 1);
789
846
 
790
847
        objdb->object_find_create(cluster_parent_handle, "cman", strlen("cman"), &find_handle);
791
848
        if (objdb->object_find_next(find_handle, &object_handle) == 0)
802
859
                        objdb->object_key_create(object_handle, "two_node", strlen("two_node"),
803
860
                                                 str, strlen(str) + 1);
804
861
                }
805
 
                if (debug_mask) {
806
 
                        sprintf(str, "%d", debug_mask);
807
 
                        objdb->object_key_create(object_handle, "debug_mask", strlen("debug_mask"),
808
 
                                                 str, strlen(str) + 1);
809
 
                }
810
862
        }
811
863
        objdb->object_find_destroy(find_handle);
812
864
 
842
894
static int set_noccs_defaults(struct objdb_iface_ver0 *objdb)
843
895
{
844
896
        char tmp[255];
845
 
        unsigned int object_handle;
846
 
        unsigned int find_handle;
 
897
        hdb_handle_t object_handle;
 
898
        hdb_handle_t find_handle;
847
899
 
848
900
        /* Enforce key */
849
 
        key_filename = NOCCS_KEY_FILENAME;
 
901
        key_filename = strdup(NOCCS_KEY_FILENAME);
 
902
        if (!key_filename) {
 
903
                sprintf(error_reason, "cannot allocate memory for key file name");
 
904
                write_cman_pipe("cannot allocate memory for key file name");
 
905
                return -1;
 
906
        }
850
907
 
851
908
        if (!cluster_name)
852
 
                cluster_name = DEFAULT_CLUSTER_NAME;
 
909
                cluster_name = strdup(DEFAULT_CLUSTER_NAME);
 
910
 
 
911
        if (!cluster_name) {
 
912
                sprintf(error_reason, "cannot allocate memory for cluster_name");
 
913
                write_cman_pipe("cannot allocate memory for cluster_name");
 
914
                return -1;
 
915
        }
853
916
 
854
917
        if (!cluster_id)
855
918
                cluster_id = generate_cluster_id(cluster_name);
948
1011
}
949
1012
 
950
1013
/* Move an object/key tree */
951
 
static int copy_config_tree(struct objdb_iface_ver0 *objdb, unsigned int source_object, unsigned int target_parent_object, int always_create)
 
1014
static int copy_config_tree(struct objdb_iface_ver0 *objdb, hdb_handle_t source_object, hdb_handle_t target_parent_object, int always_create)
952
1015
{
953
 
        unsigned int object_handle;
954
 
        unsigned int new_object;
955
 
        unsigned int find_handle;
 
1016
        hdb_handle_t object_handle;
 
1017
        hdb_handle_t new_object;
 
1018
        hdb_handle_t find_handle;
956
1019
        char object_name[1024];
957
 
        int object_name_len;
 
1020
        size_t object_name_len;
958
1021
        void *key_name;
959
 
        int key_name_len;
 
1022
        size_t key_name_len;
960
1023
        void *key_value;
961
 
        int key_value_len;
 
1024
        size_t key_value_len;
962
1025
        int res;
963
1026
 
964
1027
        /* Create new parent object if necessary */
965
1028
        objdb->object_name_get(source_object, object_name, &object_name_len);
966
1029
 
967
1030
        objdb->object_find_create(target_parent_object, object_name, strlen(object_name), &find_handle);
968
 
        if (always_create || objdb->object_find_next(find_handle, &object_handle))
 
1031
        if (always_create || objdb->object_find_next(find_handle, &new_object))
969
1032
                        objdb->object_create(target_parent_object, &new_object, object_name, object_name_len);
970
1033
        objdb->object_find_destroy(find_handle);
971
1034
 
982
1045
        /* Create sub-objects */
983
1046
        res = objdb->object_find_create(source_object, NULL, 0, &find_handle);
984
1047
        if (res) {
985
 
                sprintf(error_reason, "error resetting object iterator for object %d: %d\n", source_object, res);
 
1048
                sprintf(error_reason, "error resetting object iterator for object %ud: %d\n", (unsigned int)source_object, res);
986
1049
                return -1;
987
1050
        }
988
1051
 
1000
1063
 * Copy trees from /cluster where they live in cluster.conf, into the root
1001
1064
 * of the config tree where corosync expects to find them.
1002
1065
 */
1003
 
static int copy_tree_to_root(struct objdb_iface_ver0 *objdb, char *name, int always_create)
 
1066
static int copy_tree_to_root(struct objdb_iface_ver0 *objdb, const char *name, int always_create)
1004
1067
{
1005
 
        unsigned int find_handle;
1006
 
        unsigned int object_handle;
 
1068
        hdb_handle_t find_handle;
 
1069
        hdb_handle_t object_handle;
1007
1070
        int res=0;
1008
1071
 
1009
1072
        objdb->object_find_create(cluster_parent_handle, name, strlen(name), &find_handle);
1017
1080
 
1018
1081
static int get_cman_globals(struct objdb_iface_ver0 *objdb)
1019
1082
{
1020
 
        unsigned int object_handle;
1021
 
        unsigned int find_handle;
 
1083
        hdb_handle_t object_handle;
 
1084
        hdb_handle_t find_handle;
1022
1085
 
1023
1086
        objdb_get_string(objdb, cluster_parent_handle, "name", &cluster_name);
1024
1087
 
1041
1104
        return 0;
1042
1105
}
1043
1106
 
1044
 
static int cmanpre_reloadconfig(struct objdb_iface_ver0 *objdb, int flush, char **error_string)
 
1107
static int cmanpre_reloadconfig(struct objdb_iface_ver0 *objdb, int flush, const char **error_string)
1045
1108
{
1046
1109
        int ret = -1;
1047
 
        unsigned int object_handle;
1048
 
        unsigned int find_handle;
1049
 
        unsigned int cluster_parent_handle_new;
 
1110
        hdb_handle_t object_handle;
 
1111
        hdb_handle_t find_handle;
 
1112
        hdb_handle_t cluster_parent_handle_new;
1050
1113
 
1051
1114
        /* don't reload if we've been told to run configless */
1052
1115
        if (getenv("CMAN_NOCONFIG")) {
1099
1162
        return ret;
1100
1163
}
1101
1164
 
1102
 
static int cmanpre_readconfig(struct objdb_iface_ver0 *objdb, char **error_string)
 
1165
 
 
1166
static hdb_handle_t find_or_create_object(struct objdb_iface_ver0 *objdb, const char *name, hdb_handle_t parent_handle)
 
1167
{
 
1168
        hdb_handle_t find_handle;
 
1169
        hdb_handle_t ret_handle = 0;
 
1170
 
 
1171
        objdb->object_find_create(parent_handle, name, strlen(name), &find_handle);
 
1172
        objdb->object_find_next(find_handle, &ret_handle);
 
1173
        objdb->object_find_destroy(find_handle);
 
1174
 
 
1175
        if (!ret_handle) {
 
1176
                objdb->object_create(parent_handle, &ret_handle, name, strlen(name));
 
1177
        }
 
1178
 
 
1179
        return ret_handle;
 
1180
}
 
1181
 
 
1182
static const char *groupd_compat="groupd_compat";
 
1183
static const char *clvmd_interface="interface";
 
1184
static const char *cman_disallowed="disallowed";
 
1185
static const char *totem_crypto="crypto_accept";
 
1186
 
 
1187
/*
 
1188
 * Flags to set:
 
1189
 * - groupd:
 
1190
 * - clvmd
 
1191
 * - disallowed (on)
 
1192
 * - rgmanager
 
1193
 */
 
1194
static void setup_old_compat(struct objdb_iface_ver0 *objdb, hdb_handle_t cluster_handle)
 
1195
{
 
1196
        hdb_handle_t groupd_handle;
 
1197
        hdb_handle_t clvmd_handle;
 
1198
        hdb_handle_t cman_handle;
 
1199
        hdb_handle_t totem_handle;
 
1200
        char *value;
 
1201
 
 
1202
        /* Set groupd to backwards compatibility mode */
 
1203
        groupd_handle = find_or_create_object(objdb, "group", cluster_handle);
 
1204
        if (objdb->object_key_get(groupd_handle, groupd_compat, strlen(groupd_compat),
 
1205
                                  (void *)&value, NULL) ||
 
1206
            !value) {
 
1207
                objdb->object_key_create(groupd_handle, groupd_compat, strlen(groupd_compat),
 
1208
                                         "1", 2);
 
1209
        }
 
1210
 
 
1211
        /* Make clvmd use cman */
 
1212
        clvmd_handle = find_or_create_object(objdb, "clvmd", cluster_handle);
 
1213
        if (objdb->object_key_get(clvmd_handle, clvmd_interface, strlen(clvmd_interface),
 
1214
                                  (void *)&value, NULL) ||
 
1215
            !value) {
 
1216
                objdb->object_key_create(clvmd_handle, clvmd_interface, strlen(clvmd_interface),
 
1217
                                         "cman", 5);
 
1218
        }
 
1219
 
 
1220
        /* Make cman use disallowed mode */
 
1221
        cman_handle = find_or_create_object(objdb, "cman", cluster_handle);
 
1222
        if (objdb->object_key_get(cman_handle, cman_disallowed, strlen(cman_disallowed),
 
1223
                                  (void *)&value, NULL) ||
 
1224
            !value) {
 
1225
                objdb->object_key_create(cman_handle, cman_disallowed, strlen(cman_disallowed),
 
1226
                                         "1", 2);
 
1227
        }
 
1228
 
 
1229
        /* Make totem use the old communications method */
 
1230
        totem_handle = find_or_create_object(objdb, "totem", OBJECT_PARENT_HANDLE);
 
1231
        if (objdb->object_key_get(totem_handle, totem_crypto, strlen(totem_crypto),
 
1232
                                  (void *)&value, NULL) ||
 
1233
            !value) {
 
1234
                objdb->object_key_create(totem_handle, totem_crypto, strlen(totem_crypto),
 
1235
                                         "old", 4);
 
1236
        }
 
1237
}
 
1238
 
 
1239
static int cmanpre_readconfig(struct objdb_iface_ver0 *objdb, const char **error_string)
1103
1240
{
1104
1241
        int ret = 0;
1105
 
        unsigned int object_handle;
1106
 
        unsigned int find_handle;
 
1242
        hdb_handle_t object_handle;
 
1243
        hdb_handle_t find_handle;
 
1244
        char *str;
1107
1245
 
1108
1246
        if (getenv("CMAN_PIPE"))
1109
1247
                startup_pipe = atoi(getenv("CMAN_PIPE"));
1132
1270
        }
1133
1271
        objdb->object_find_destroy(find_handle);
1134
1272
 
 
1273
        /* Set up STABLE2/RHEL5 compatibility modes */
 
1274
        objdb_get_string(objdb, object_handle, "upgrading", &str);
 
1275
        if (str && strcasecmp(str, "on")==0) {
 
1276
                setup_old_compat(objdb, cluster_parent_handle);
 
1277
        }
 
1278
 
1135
1279
        /* This will create /libccs/@next_handle.
1136
1280
         * next_handle will be atomically incremented by corosync to return ccs_handle down the pipe.
1137
1281
         * We create it in cman-preconfig to avoid an "init" race in libccs.
1170
1314
        }
1171
1315
        *error_string = error_reason;
1172
1316
 
 
1317
 
 
1318
        /* nullify stderr, because cman_tool tells corosync not to.
 
1319
           This helps pass error messages back to the command-line, when
 
1320
           debug is enabled.
 
1321
        */
 
1322
        if (!debug) {
 
1323
                int tmpfd;
 
1324
                tmpfd = open("/dev/null", O_RDWR);
 
1325
                if (tmpfd > -1 && tmpfd != STDERR_FILENO) {
 
1326
                        dup2(tmpfd, STDERR_FILENO);
 
1327
                        close(tmpfd);
 
1328
                }
 
1329
 
 
1330
        }
1173
1331
        return ret;
1174
1332
}
1175
1333
 
1176
1334
/* Write an error message down the CMAN startup pipe so
1177
1335
   that cman_tool can display it */
1178
 
int write_cman_pipe(char *message)
 
1336
int write_cman_pipe(const char *message)
1179
1337
{
1180
1338
        if (startup_pipe)
1181
1339
                return write(startup_pipe, message, strlen(message)+1);