~ampelbein/ubuntu/oneiric/heartbeat/lp-770743

« back to all changes in this revision

Viewing changes to heartbeat/heartbeat.c

  • Committer: Bazaar Package Importer
  • Author(s): Ante Karamatic
  • Date: 2009-08-10 19:29:25 UTC
  • mfrom: (5.2.3 experimental)
  • Revision ID: james.westby@ubuntu.com-20090810192925-9zy2llcbgavbskf7
Tags: 2.99.2+sles11r9-5ubuntu1
* New upstream snapshot
* Adjusted heartbeat.install and rules for documentation path

Show diffs side-by-side

added added

removed removed

Lines of Context:
570
570
        int                     j;
571
571
        char    *shost;
572
572
 
573
 
        if ( (shost = cl_strdup(h)) == NULL) {
 
573
        if ( (shost = strdup(h)) == NULL) {
574
574
                return NULL;
575
575
        }
576
576
        g_strdown(shost);
578
578
                if (strcmp(shost, config->nodes[j].nodename) == 0)
579
579
                        break;
580
580
        }
581
 
        cl_free(shost);
 
581
        free(shost);
582
582
        if (j == config->nodecount) {
583
583
                return NULL;
584
584
        } else {
679
679
                                break;
680
680
 
681
681
                case 0:         /* Child */
682
 
                                close(watchdogfd);
 
682
                                hb_close_watchdog();
683
683
                                curproc = &procinfo->info[fifoproc];
684
 
                                cl_malloc_setstats(&curproc->memstats);
685
684
                                cl_msg_setstats(&curproc->msgstats);
686
685
                                curproc->type = PROC_HBFIFO;
687
686
                                while (curproc->pid != getpid()) {
798
797
                                break;
799
798
 
800
799
                case 0:         /* Child */
801
 
                                close(watchdogfd);
 
800
                                hb_close_watchdog();
802
801
                                curproc = &procinfo->info[ourproc];
803
 
                                cl_malloc_setstats(&curproc->memstats);
804
802
                                cl_msg_setstats(&curproc->msgstats);
805
803
                                curproc->type = PROC_HBWRITE;
806
804
                                while (curproc->pid != getpid()) {
832
830
                                break;
833
831
 
834
832
                case 0:         /* Child */
835
 
                                close(watchdogfd);
 
833
                                hb_close_watchdog();
836
834
                                curproc = &procinfo->info[ourproc];
837
 
                                cl_malloc_setstats(&curproc->memstats);
838
835
                                cl_msg_setstats(&curproc->msgstats);
839
836
                                curproc->type = PROC_HBREAD;
840
837
                                while (curproc->pid != getpid()) {
1008
1005
        ourproc = procinfo->nprocs;
1009
1006
        curproc = &procinfo->info[ourproc];
1010
1007
        curproc->type = PROC_MST_CONTROL;
1011
 
        cl_malloc_setstats(&curproc->memstats);
1012
1008
        cl_msg_setstats(&curproc->msgstats);
1013
1009
        NewTrackedProc(getpid(), 0, PT_LOGVERBOSE, GINT_TO_POINTER(ourproc)
1014
1010
        ,       &CoreProcessTrackOps);
1514
1510
        int                     allstarted;
1515
1511
        int                     j;
1516
1512
        GMainLoop*              mainloop;
1517
 
        long                    memstatsinterval;
1518
1513
        guint                   id;
1519
1514
 
1520
1515
        write_hostcachefile = G_main_add_tempproc_trigger(PRI_WRITECACHE
1619
1614
        ,       NULL);
1620
1615
        G_main_setall_id(id, "init deadtime passed", config->warntime_ms, 50);
1621
1616
 
1622
 
        /* Dump out memory stats periodically... */
1623
 
        memstatsinterval = (debug_level ? 10*60*1000 : ONEDAY*1000);
1624
 
        id=Gmain_timeout_add_full(PRI_DUMPSTATS, memstatsinterval
1625
 
        ,       hb_dump_all_proc_stats, NULL, NULL);
1626
 
        G_main_setall_id(id, "memory stats", 5000, 100);
1627
 
 
1628
1617
        /* Audit clients for liveness periodically */
1629
1618
        id=Gmain_timeout_add_full(PRI_AUDITCLIENT, 9*1000
1630
1619
        ,       api_audit_clients, NULL, NULL);
1680
1669
                        ,       (unsigned long)m);
1681
1670
                }
1682
1671
                memset(m->msg_body, 0, m->msg_len);
1683
 
                cl_free(m->msg_buf);
 
1672
                free(m->msg_buf);
1684
1673
                memset(m, 0, sizeof(*m));
1685
 
                cl_free(m);
 
1674
                free(m);
1686
1675
        }else{
1687
1676
                refcnt--;
1688
1677
                m->msg_private = GINT_TO_POINTER(refcnt);
1708
1697
        }
1709
1698
 
1710
1699
 
1711
 
        if ((hdr = (IPC_Message*)cl_malloc(sizeof(*hdr)))  == NULL) {
 
1700
        if ((hdr = (IPC_Message*)malloc(sizeof(*hdr)))  == NULL) {
1712
1701
                return NULL;
1713
1702
        }
1714
1703
        
1715
1704
        memset(hdr, 0, sizeof(*hdr));
1716
1705
 
1717
 
        if ((copy = (char*)cl_malloc(ch->msgpad + len))
 
1706
        if ((copy = (char*)malloc(ch->msgpad + len))
1718
1707
            == NULL) {
1719
 
                cl_free(hdr);
 
1708
                free(hdr);
1720
1709
                return NULL;
1721
1710
        }
1722
1711
        memcpy(copy + ch->msgpad, data, len);
2261
2250
        if (msg){
2262
2251
                hist->lowseq = hist->seqnos[slot];
2263
2252
                hist->msgq[slot] = NULL;
2264
 
                if (!cl_is_allocated(msg)) {
 
2253
                if (!msg) {
2265
2254
                        cl_log(LOG_CRIT,
2266
2255
                               "Unallocated slotmsg in %s",
2267
2256
                               __FUNCTION__);
2522
2511
                        goto errexit;
2523
2512
                }
2524
2513
                
2525
 
                nodes[i] = cl_malloc(nodelen + 1);
 
2514
                nodes[i] = malloc(nodelen + 1);
2526
2515
                if (nodes[i] == NULL){
2527
2516
                        cl_log(LOG_ERR, "%s: malloc failed", __FUNCTION__);
2528
2517
                        goto errexit;
2541
2530
 errexit:
2542
2531
        for (j = 0; j < i ; j++){
2543
2532
                if (nodes[j]){
2544
 
                        cl_free(nodes[j]);
 
2533
                        free(nodes[j]);
2545
2534
                        nodes[j] =NULL;
2546
2535
                }
2547
2536
        }
2613
2602
                if (hb_add_one_node(nodes[i])!= HA_OK){
2614
2603
                        cl_log(LOG_ERR, "Add node %s failed", nodes[i]);
2615
2604
                }
2616
 
                cl_free(nodes[i]);
 
2605
                free(nodes[i]);
2617
2606
                nodes[i]=NULL;
2618
2607
        }
2619
2608
        G_main_set_trigger(write_hostcachefile);
2806
2795
        }
2807
2796
 out:
2808
2797
        for (i = 0; i < num; i++){
2809
 
                cl_free(nodes[i]);
 
2798
                free(nodes[i]);
2810
2799
                nodes[i]= NULL; 
2811
2800
        }
2812
2801
        
3057
3046
                }
3058
3047
                for (i = 0; i< num; i++){
3059
3048
                        if (nodes[i]) {
3060
 
                                cl_free(nodes[i]);
 
3049
                                free(nodes[i]);
3061
3050
                                nodes[i] = NULL;
3062
3051
                        }
3063
3052
                }
3082
3071
        
3083
3072
                for (i = 0; i < delnum; i++){
3084
3073
                        if (delnodes[i]){
3085
 
                                cl_free(delnodes[i]);
 
3074
                                free(delnodes[i]);
3086
3075
                                delnodes[i] = NULL;
3087
3076
                        }
3088
3077
                }
4127
4116
                (void)open(devnull, O_WRONLY);  /* Stderr: fd 2 */
4128
4117
                cmdsize = STRLEN_CONST(CMDPREFIX)+strlen(centry->command)+1;
4129
4118
 
4130
 
                cmdexec = cl_malloc(cmdsize);
 
4119
                cmdexec = malloc(cmdsize);
4131
4120
                if (cmdexec != NULL) {
4132
4121
                        strlcpy(cmdexec, CMDPREFIX, cmdsize);
4133
4122
                        strlcat(cmdexec, centry->command, cmdsize);
4192
4181
        return ct;
4193
4182
}
4194
4183
 
4195
 
void
4196
 
hb_dump_proc_stats(volatile struct process_info * proc)
4197
 
{
4198
 
        const char *    ct;
4199
 
        unsigned long   curralloc;
4200
 
        volatile cl_mem_stats_t *ms;
4201
 
 
4202
 
        if (!proc) {
4203
 
                return;
4204
 
        }
4205
 
 
4206
 
        ct = core_proc_name(proc->type);
4207
 
 
4208
 
        cl_log(LOG_INFO, "MSG stats: %ld/%ld ms age %ld [pid%d/%s]"
4209
 
        ,       proc->msgstats.allocmsgs, proc->msgstats.totalmsgs
4210
 
        ,       longclockto_ms(sub_longclock(time_longclock()
4211
 
        ,               proc->msgstats.lastmsg))
4212
 
        ,       (int) proc->pid, ct);
4213
 
 
4214
 
        
4215
 
        ms = &proc->memstats;
4216
 
        if (ms->numalloc > ms->numfree) {
4217
 
                curralloc = ms->numalloc - ms->numfree;
4218
 
        }else{
4219
 
                curralloc = 0;
4220
 
        }
4221
 
 
4222
 
        cl_log(LOG_INFO, "cl_malloc stats: %lu/%lu  %lu/%lu [pid%d/%s]"
4223
 
        ,       curralloc, ms->numalloc
4224
 
        ,       ms->nbytes_alloc, ms->nbytes_req, (int) proc->pid, ct);
4225
 
 
4226
 
        cl_log(LOG_INFO, "RealMalloc stats: %lu total malloc bytes."
4227
 
        " pid [%d/%s]", ms->mallocbytes, (int) proc->pid, ct);
4228
 
 
4229
 
#ifdef HAVE_MALLINFO
4230
 
        cl_log(LOG_INFO, "Current arena value: %lu", ms->arena);
4231
 
#endif
4232
 
}
4233
 
 
4234
 
 
4235
4184
/*
4236
4185
 *      Restart heartbeat - we never return from this...
4237
4186
 */
4571
4520
                                ,       "FIFO message [type %s] written rc=%ld"
4572
4521
                                , type, (long) writerc);
4573
4522
                        }
4574
 
                        cl_free(smsg);
 
4523
                        free(smsg);
4575
4524
                }
4576
4525
                if (ffd > 0) {
4577
4526
                        if (close(ffd) < 0) {
4660
4609
        return TRUE;
4661
4610
}
4662
4611
 
4663
 
gboolean
4664
 
hb_dump_all_proc_stats(gpointer p)
4665
 
{
4666
 
        int     j;
4667
 
 
4668
 
        cl_log(LOG_INFO, "Daily informational memory statistics");
4669
 
 
4670
 
        hb_add_deadtime(2000);
4671
 
 
4672
 
        for (j=0; j < procinfo->nprocs; ++j) {
4673
 
                hb_dump_proc_stats(procinfo->info+j);
4674
 
        }
4675
 
        
4676
 
        hb_pop_deadtime(NULL);
4677
 
        
4678
 
        cl_log(LOG_INFO, "These are nothing to worry about.");
4679
 
        return TRUE;
4680
 
}
4681
 
 
4682
4612
static gboolean
4683
4613
EmergencyShutdown(gpointer p)
4684
4614
{
4788
4718
        api_heartbeat_monitor(msg, msgtype, iface);
4789
4719
}
4790
4720
 
 
4721
extern const char *get_hg_version(void);
4791
4722
 
4792
4723
static void
4793
4724
printversion(void)
4794
4725
{       
4795
 
        printf("%s\n", VERSION);
 
4726
        printf("%s (%s)\n", VERSION, get_hg_version());
4796
4727
        return;
4797
4728
}
4798
4729
/*
4844
4775
        long            running_hb_pid =  cl_read_pidfile(PIDFILE);
4845
4776
        int             generic_error = LSB_EXIT_GENERIC;
4846
4777
 
4847
 
        cl_malloc_forced_for_glib();
4848
4778
        num_hb_media_types = 0;
4849
4779
        /* A precautionary measure */
4850
4780
        getrlimit(RLIMIT_NOFILE, &oflimits);
4865
4795
        /* Weird enum (bitfield) */
4866
4796
        g_log_set_always_fatal((GLogLevelFlags)0); /*value out of range*/  
4867
4797
 
4868
 
        if ((tmp_cmdname = cl_strdup(argv[0])) == NULL) {
 
4798
        if ((tmp_cmdname = strdup(argv[0])) == NULL) {
4869
4799
                cl_perror("Out of memory in main.");
4870
4800
                exit(1);
4871
4801
        }
4976
4906
        }
4977
4907
        set_proc_title("%s", cmdname);
4978
4908
 
4979
 
        hbmedia_types = cl_malloc(sizeof(struct hbmedia_types **));
 
4909
        hbmedia_types = malloc(sizeof(struct hbmedia_types **));
4980
4910
 
4981
4911
        if (hbmedia_types == NULL) {
4982
4912
                cl_log(LOG_ERR, "Allocation of hbmedia_types failed.");
5179
5109
                if (ANYDEBUG) {
5180
5110
                        cl_log(LOG_DEBUG
5181
5111
                        ,       "HA configuration OK.  Heartbeat starting.");
 
5112
                        cl_log(LOG_INFO
 
5113
                        ,       "Heartbeat Hg Version: %s", get_hg_version());
5182
5114
                }
5183
5115
                if (verbose) {
5184
5116
                        dump_config();
5957
5889
        process_clustermsg(msg, NULL);
5958
5890
 
5959
5891
        send_to_all_media(smsg, len);
5960
 
        cl_free(smsg);
 
5892
        free(smsg);
5961
5893
 
5962
5894
        /*  Throw away "msg" here if it's not saved above */
5963
5895
        if (cseq == NULL) {
6172
6104
                if (msg == NULL) {
6173
6105
                        continue;
6174
6106
                }
6175
 
                if (!cl_is_allocated(msg)) {
 
6107
                if (!msg) {
6176
6108
                        cl_log(LOG_CRIT
6177
6109
                        ,       "Unallocated message in audit_xmit_hist");
6178
6110
                        doabort=TRUE;
6207
6139
                        ,       "Too small stringlen in audit_xmit_hist");
6208
6140
                        doabort=TRUE;
6209
6141
                }
6210
 
                if (!cl_is_allocated(msg->names)) {
 
6142
                if (!msg->names) {
6211
6143
                        cl_log(LOG_CRIT
6212
6144
                        ,       "Unallocated msg->names in audit_xmit_hist");
6213
6145
                        doabort=TRUE;
6214
6146
                }
6215
 
                if (!cl_is_allocated(msg->nlens)) {
 
6147
                if (!msg->nlens) {
6216
6148
                        cl_log(LOG_CRIT
6217
6149
                        ,       "Unallocated msg->nlens in audit_xmit_hist");
6218
6150
                        doabort=TRUE;
6219
6151
                }
6220
 
                if (!cl_is_allocated(msg->values)) {
 
6152
                if (!msg->values) {
6221
6153
                        cl_log(LOG_CRIT
6222
6154
                        ,       "Unallocated msg->values in audit_xmit_hist");
6223
6155
                        doabort=TRUE;
6224
6156
                }
6225
 
                if (!cl_is_allocated(msg->vlens)) {
 
6157
                if (!msg->vlens) {
6226
6158
                        cl_log(LOG_CRIT
6227
6159
                        ,       "Unallocated msg->vallens in audit_xmit_hist");
6228
6160
                        doabort=TRUE;
6256
6188
        int     slot;
6257
6189
        struct ha_msg* slotmsg;
6258
6190
 
6259
 
        if (!cl_is_allocated(msg)) {
 
6191
        if (!msg) {
6260
6192
                cl_log(LOG_CRIT, "Unallocated message in add2_xmit_hist");
6261
6193
                abort();
6262
6194
        }
6273
6205
                /* Lowseq is less than the lowest recorded seqno */
6274
6206
                hist->lowseq = hist->seqnos[slot];
6275
6207
                hist->msgq[slot] = NULL;
6276
 
                if (!cl_is_allocated(slotmsg)) {
 
6208
                if (!slotmsg) {
6277
6209
                        cl_log(LOG_CRIT
6278
6210
                        ,       "Unallocated slotmsg in add2_xmit_hist");
6279
6211
                }else{
6466
6398
                                hist->lastrexmit[msgslot] = now;
6467
6399
                                send_to_all_media(smsg
6468
6400
                                  ,     len);
6469
 
                                cl_free(smsg);
 
6401
                                free(smsg);
6470
6402
                        }
6471
6403
 
6472
6404
                }