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

« back to all changes in this revision

Viewing changes to exec/util.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Loschwitz
  • Date: 2011-10-19 14:32:18 UTC
  • mfrom: (1.1.6 upstream) (5.1.16 sid)
  • Revision ID: james.westby@ubuntu.com-20111019143218-ew8phl0raqyog844
Tags: 1.4.2-1
* Changed my email address in debian/control
* Add corosync-blackbox to the corosync package
* Imported Upstream version 1.4.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
#include <assert.h>
45
45
 
46
46
#include <corosync/corotypes.h>
 
47
#include <corosync/corodefs.h>
47
48
#include <corosync/list.h>
48
49
#include <corosync/engine/logsys.h>
49
50
#include <corosync/coroipc_types.h>
51
52
 
52
53
LOGSYS_DECLARE_SUBSYS ("MAIN");
53
54
 
 
55
struct service_names {
 
56
        const char *c_name;
 
57
        int32_t c_val;
 
58
};
 
59
 
 
60
static struct service_names servicenames[] =
 
61
{
 
62
        { "EVS", EVS_SERVICE },
 
63
        { "CLM", CLM_SERVICE },
 
64
        { "AMF", AMF_SERVICE },
 
65
        { "CKPT", CKPT_SERVICE },
 
66
        { "EVT", EVT_SERVICE },
 
67
        { "LCK", LCK_SERVICE },
 
68
        { "MSG", MSG_SERVICE },
 
69
        { "CFG", CFG_SERVICE },
 
70
        { "CPG", CPG_SERVICE },
 
71
        { "CMAN", CMAN_SERVICE },
 
72
        { "PCMK", PCMK_SERVICE },
 
73
        { "CONFDB", CONFDB_SERVICE },
 
74
        { "QUORUM", QUORUM_SERVICE },
 
75
        { "PLOAD", PLOAD_SERVICE },
 
76
        { "TMR", TMR_SERVICE },
 
77
        { "VOTEQUORUM", VOTEQUORUM_SERVICE },
 
78
        { "NTF", NTF_SERVICE },
 
79
        { "AMF", AMF_V2_SERVICE },
 
80
        { NULL, -1 }
 
81
};
 
82
 
 
83
const char * short_service_name_get(uint32_t service_id,
 
84
        char *buf, size_t buf_size)
 
85
{
 
86
        uint32_t i;
 
87
 
 
88
        for (i = 0; servicenames[i].c_name != NULL; i++) {
 
89
                if (service_id == servicenames[i].c_val) {
 
90
                        return (servicenames[i].c_name);
 
91
                }
 
92
        }
 
93
        snprintf(buf, buf_size, "%d", service_id);
 
94
        return buf;
 
95
}
 
96
 
54
97
/*
55
98
 * Compare two names.  returns non-zero on match.
56
99
 */
117
160
}
118
161
 
119
162
void setcs_name_t (cs_name_t *name, char *str) {
120
 
        strncpy ((char *)name->value, str, CS_MAX_NAME_LENGTH);
 
163
        strncpy ((char *)name->value, str, sizeof (name->value));
 
164
        ((char *)name->value)[sizeof (name->value) - 1] = '\0';
121
165
        if (strlen ((char *)name->value) > CS_MAX_NAME_LENGTH) {
122
166
                name->length = CS_MAX_NAME_LENGTH;
123
167
        } else {