Skip to content

Commit 3de66ee

Browse files
committed
Refactor: libcrmcommon: New pcmk__generate_uuid()
Signed-off-by: Reid Wahl <[email protected]>
1 parent bbf49a8 commit 3de66ee

File tree

10 files changed

+43
-16
lines changed

10 files changed

+43
-16
lines changed

daemons/based/based_remote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ cib_handle_remote_msg(pcmk__client_t *client, xmlNode *command)
391391
pcmk__xe_set(command, PCMK__XA_CIB_USER, client->user);
392392

393393
if (pcmk__xe_get(command, PCMK__XA_CIB_CALLID) == NULL) {
394-
char *call_uuid = crm_generate_uuid();
394+
char *call_uuid = pcmk__generate_uuid();
395395

396396
/* fix the command */
397397
pcmk__xe_set(command, PCMK__XA_CIB_CALLID, call_uuid);

daemons/controld/controld_schedulerd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ handle_disconnect(void)
9191

9292
if (pcmk__is_set(controld_globals.fsa_input_register, R_PE_REQUIRED)) {
9393
int rc = pcmk_ok;
94-
char *uuid_str = crm_generate_uuid();
94+
char *uuid_str = pcmk__generate_uuid();
9595

9696
crm_crit("Lost connection to the scheduler "
9797
QB_XS " CIB will be saved to " PCMK_SCHEDULER_INPUT_DIR "/pe-core-%s.bz2",

daemons/controld/controld_transition.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ do_te_control(long long action,
6363
}
6464

6565
if (controld_globals.te_uuid == NULL) {
66-
controld_globals.te_uuid = crm_generate_uuid();
66+
controld_globals.te_uuid = pcmk__generate_uuid();
6767
crm_info("Registering TE UUID: %s", controld_globals.te_uuid);
6868
}
6969

daemons/fenced/fenced_remote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ create_remote_stonith_op(const char *client, xmlNode *request, gboolean peer)
11911191
if (peer && dev) {
11921192
op->id = pcmk__xe_get_copy(dev, PCMK__XA_ST_REMOTE_OP);
11931193
} else {
1194-
op->id = crm_generate_uuid();
1194+
op->id = pcmk__generate_uuid();
11951195
}
11961196

11971197
g_hash_table_replace(stonith_remote_op_list, op->id, op);

include/crm/common/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ pcmk__flag_text(uint64_t flag_group, uint64_t flags)
247247
// miscellaneous utilities (from utils.c)
248248

249249
void pcmk__daemonize(const char *name, const char *pidfile);
250+
char *pcmk__generate_uuid(void);
250251
void pcmk__panic(const char *reason);
251252
pid_t pcmk__locate_sbd(void);
252253
void pcmk__sleep_ms(unsigned int ms);

lib/cib/cib_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ cib_file_new(const char *cib_location)
667667
return NULL;
668668
}
669669

670-
private->id = crm_generate_uuid();
670+
private->id = pcmk__generate_uuid();
671671
private->filename = filename;
672672

673673
cib->variant = cib_file;

lib/cluster/membership.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ pcmk__get_node(unsigned int id, const char *uname, const char *xml_id,
985985
}
986986

987987
if (node == NULL) {
988-
char *uniqueid = crm_generate_uuid();
988+
char *uniqueid = pcmk__generate_uuid();
989989

990990
node = pcmk__assert_alloc(1, sizeof(pcmk__node_status_t));
991991

@@ -1465,7 +1465,7 @@ cluster_node_cib_cache_refresh_helper(xmlNode *xml_node, void *user_data)
14651465
node = find_cib_cluster_node(id, uname);
14661466

14671467
if (node == NULL) {
1468-
char *uniqueid = crm_generate_uuid();
1468+
char *uniqueid = pcmk__generate_uuid();
14691469

14701470
node = pcmk__assert_alloc(1, sizeof(pcmk__node_status_t));
14711471

lib/common/ipc_server.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ client_from_connection(qb_ipcs_connection_t *c, void *key, uid_t uid_client)
180180
}
181181
}
182182

183-
client->id = crm_generate_uuid();
183+
client->id = pcmk__generate_uuid();
184184
if (key == NULL) {
185185
key = client->id;
186186
}

lib/common/utils.c

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -327,22 +327,48 @@ pcmk__daemonize(const char *name, const char *pidfile)
327327
pcmk__open_devnull(O_WRONLY); // stderr (fd 2)
328328
}
329329

330+
/* @FIXME uuid.h is an optional header per configure.ac, and we include it
331+
* conditionally above. But uuid_generate() and uuid_unparse() depend on it, on
332+
* many or perhaps all systems with libuuid. So it's not clear how it would ever
333+
* be optional in practice.
334+
*
335+
* Note that these functions are not POSIX, although there is probably no good
336+
* portable alternative.
337+
*
338+
* We do list libuuid as a build dependency in INSTALL.md already.
339+
*/
340+
330341
#ifdef HAVE_UUID_UUID_H
331-
# include <uuid/uuid.h>
332-
#endif
342+
#include <uuid/uuid.h>
343+
#endif // HAVE_UUID_UUID_H
333344

345+
/*!
346+
* \internal
347+
* \brief Generate a 37-byte (36 bytes plus null terminator) UUID string
348+
*
349+
* \return Newly allocated UUID string
350+
*
351+
* \note The caller is responsible for freeing the return value using \c free().
352+
*/
334353
char *
335-
crm_generate_uuid(void)
354+
pcmk__generate_uuid(void)
336355
{
337-
unsigned char uuid[16];
338-
char *buffer = malloc(37); /* Including NUL byte */
356+
uuid_t uuid;
357+
358+
// uuid_unparse() converts a UUID to a 37-byte string (including null byte)
359+
char *buffer = pcmk__assert_alloc(37, sizeof(char));
339360

340-
pcmk__mem_assert(buffer);
341361
uuid_generate(uuid);
342362
uuid_unparse(uuid, buffer);
343363
return buffer;
344364
}
345365

366+
char *
367+
crm_generate_uuid(void)
368+
{
369+
return pcmk__generate_uuid();
370+
}
371+
346372
/*!
347373
* \internal
348374
* \brief Sleep for given milliseconds

lib/common/xml_io.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ pcmk__xml_write_temp_file(const xmlNode *xml, const char *desc,
619619
CRM_CHECK((xml != NULL) && (desc != NULL), return);
620620

621621
if (filename == NULL) {
622-
uuid = crm_generate_uuid();
622+
uuid = pcmk__generate_uuid();
623623
filename = uuid;
624624
}
625625
path = pcmk__assert_asprintf("%s/%s", pcmk__get_tmpdir(), filename);
@@ -642,7 +642,7 @@ save_xml_to_file(const xmlNode *xml, const char *desc, const char *filename)
642642
char *f = NULL;
643643

644644
if (filename == NULL) {
645-
char *uuid = crm_generate_uuid();
645+
char *uuid = pcmk__generate_uuid();
646646

647647
f = pcmk__assert_asprintf("%s/%s", pcmk__get_tmpdir(), uuid);
648648
filename = f;

0 commit comments

Comments
 (0)