MCPcopy Create free account
hub / github.com/corosync/corosync / sam_cmap_update_key

Function sam_cmap_update_key

lib/sam.c:143–213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

141};
142
143static cs_error_t sam_cmap_update_key (enum sam_cmap_key_t key, const char *value)
144{
145 cs_error_t err;
146 const char *svalue;
147 uint64_t hc_period, last_hc;
148
149 const char *ssvalue[] = { [SAM_RECOVERY_POLICY_QUIT] = "quit", [SAM_RECOVERY_POLICY_RESTART] = "restart" };
150 char key_name[CMAP_KEYNAME_MAXLEN];
151
152 switch (key) {
153 case SAM_CMAP_KEY_RECOVERY:
154 svalue = ssvalue[SAM_RP_MASK (sam_internal_data.recovery_policy)];
155
156 if (snprintf(key_name, CMAP_KEYNAME_MAXLEN, "%s%s", sam_internal_data.cmap_pid_path,
157 "recovery") >= CMAP_KEYNAME_MAXLEN) {
158
159 err = CS_ERR_NAME_TOO_LONG;
160 goto exit_error;
161 }
162
163 if ((err = cmap_set_string(sam_internal_data.cmap_handle, key_name, svalue)) != CS_OK) {
164 goto exit_error;
165 }
166 break;
167 case SAM_CMAP_KEY_HC_PERIOD:
168 hc_period = sam_internal_data.time_interval;
169
170 if (snprintf(key_name, CMAP_KEYNAME_MAXLEN, "%s%s", sam_internal_data.cmap_pid_path,
171 "poll_period") >= CMAP_KEYNAME_MAXLEN) {
172
173 err = CS_ERR_NAME_TOO_LONG;
174 goto exit_error;
175 }
176
177 if ((err = cmap_set_uint64(sam_internal_data.cmap_handle, key_name, hc_period)) != CS_OK) {
178 goto exit_error;
179 }
180 break;
181 case SAM_CMAP_KEY_LAST_HC:
182 last_hc = cs_timestamp_get();
183
184 if (snprintf(key_name, CMAP_KEYNAME_MAXLEN, "%s%s", sam_internal_data.cmap_pid_path,
185 "last_updated") >= CMAP_KEYNAME_MAXLEN) {
186
187 err = CS_ERR_NAME_TOO_LONG;
188 goto exit_error;
189 }
190 if ((err = cmap_set_uint64(sam_internal_data.cmap_handle, key_name, last_hc)) != CS_OK) {
191 goto exit_error;
192 }
193 break;
194 case SAM_CMAP_KEY_STATE:
195 svalue = value;
196 if (snprintf(key_name, CMAP_KEYNAME_MAXLEN, "%s%s", sam_internal_data.cmap_pid_path,
197 "state") >= CMAP_KEYNAME_MAXLEN) {
198
199 err = CS_ERR_NAME_TOO_LONG;
200 goto exit_error;

Callers 5

sam_cmap_registerFunction · 0.85
sam_parent_handlerFunction · 0.85
sam_registerFunction · 0.85

Calls 3

cmap_set_stringFunction · 0.85
cmap_set_uint64Function · 0.85
cs_timestamp_getFunction · 0.85

Tested by

no test coverage detected