File pacemaker-handle-PID-string-properly.patch of Package pacemaker.openSUSE_Leap_42.3_Update
commit a2a52b9f8fa1de488976ed29899cce708410ff5c
Author: Ken Gaillot <kgaillot@redhat.com>
Date: Fri Sep 22 17:01:19 2017 -0500
Low: crmd,libcrmcommon,libcluster,tools: handle PID as string properly
potential sizing and formatting issues found by
Jan Pokorný <jpokorny@redhat.com>
diff --git a/crmd/main.c b/crmd/main.c
index 6f42644dd..17f12cfa9 100644
--- a/crmd/main.c
+++ b/crmd/main.c
@@ -163,6 +163,7 @@ crmd_init(void)
exit_code = 1;
}
- crm_info("%u stopped: %s (%d)", getpid(), pcmk_strerror(exit_code), exit_code);
+ crm_info("%lu stopped: %s (%d)",
+ (unsigned long) getpid(), pcmk_strerror(exit_code), exit_code);
return crmd_fast_exit(exit_code);
}
diff --git a/crmd/te_utils.c b/crmd/te_utils.c
index 5b13adc1d..dab02d360 100644
--- a/crmd/te_utils.c
+++ b/crmd/te_utils.c
@@ -206,7 +206,8 @@ static void
tengine_stonith_notify(stonith_t * st, stonith_event_t * st_event)
{
if(te_client_id == NULL) {
- te_client_id = crm_strdup_printf("%s.%d", crm_system_name, getpid());
+ te_client_id = crm_strdup_printf("%s.%lu", crm_system_name,
+ (unsigned long) getpid());
}
if (st_event == NULL) {
diff --git a/include/crm/common/internal.h b/include/crm/common/internal.h
index 80eeee65d..c587c5382 100644
--- a/include/crm/common/internal.h
+++ b/include/crm/common/internal.h
@@ -22,6 +22,7 @@
#include <glib.h> /* for gboolean */
#include <dirent.h> /* for struct dirent */
+#include <unistd.h> /* for getpid() */
#include <sys/types.h> /* for uid_t and gid_t */
#include <crm/common/logging.h>
@@ -73,6 +74,12 @@ crm_strlen_zero(const char *s)
return !s || *s == '\0';
}
+static inline char *
+crm_getpid_s()
+{
+ return crm_strdup_printf("%lu", (unsigned long) getpid());
+}
+
/* convenience functions for failure-related node attributes */
#define CRM_FAIL_COUNT_PREFIX "fail-count"
diff --git a/lib/cluster/cpg.c b/lib/cluster/cpg.c
index aef358312..1e6cf7995 100644
--- a/lib/cluster/cpg.c
+++ b/lib/cluster/cpg.c
@@ -315,7 +315,7 @@ pcmk_message_common_cs(cpg_handle_t handle, uint32_t nodeid, uint32_t pid, void
goto badmsg;
} else if (safe_str_eq("identify", data)) {
- char *pid_s = crm_itoa((int) getpid());
+ char *pid_s = crm_getpid_s();
send_cluster_text(crm_class_cluster, pid_s, TRUE, NULL, crm_msg_ais);
free(pid_s);
diff --git a/lib/common/logging.c b/lib/common/logging.c
index 6e8d67b5f..454836758 100644
--- a/lib/common/logging.c
+++ b/lib/common/logging.c
@@ -197,10 +197,11 @@ set_format_string(int method, const char *daemon)
if (uname(&res) == 0) {
offset +=
- snprintf(fmt + offset, FMT_MAX - offset, "%%t [%d] %s %10s: ", getpid(),
- res.nodename, daemon);
+ snprintf(fmt + offset, FMT_MAX - offset, "%%t [%lu] %s %10s: ",
+ (unsigned long) getpid(), res.nodename, daemon);
} else {
- offset += snprintf(fmt + offset, FMT_MAX - offset, "%%t [%d] %10s: ", getpid(), daemon);
+ offset += snprintf(fmt + offset, FMT_MAX - offset, "%%t [%lu] %10s: ",
+ (unsigned long) getpid(), daemon);
}
}
@@ -368,7 +369,8 @@ crm_control_blackbox(int nsig, bool enable)
pid_t pid = getpid();
blackbox_file_prefix = malloc(NAME_MAX);
- snprintf(blackbox_file_prefix, NAME_MAX, "%s/%s-%d", CRM_BLACKBOX_DIR, crm_system_name, pid);
+ snprintf(blackbox_file_prefix, NAME_MAX, "%s/%s-%lu",
+ CRM_BLACKBOX_DIR, crm_system_name, (unsigned long) pid);
}
if (enable && qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_STATE_GET, 0) != QB_LOG_STATE_ENABLED) {
@@ -869,7 +871,7 @@ crm_log_init(const char *entity, uint8_t level, gboolean daemon, gboolean to_std
{
char path[512];
- snprintf(path, 512, "%s-%d", crm_system_name, getpid());
+ snprintf(path, 512, "%s-%lu", crm_system_name, (unsigned long) getpid());
mkdir(path, 0750);
chdir(path);
crm_info("Changed active directory to %s/%s/%s", base, pwent->pw_name, path);
diff --git a/tools/crm_node.c b/tools/crm_node.c
index 9b60c55fd..5e91e8194 100644
--- a/tools/crm_node.c
+++ b/tools/crm_node.c
@@ -150,9 +150,7 @@ int tools_remove_node_cache(const char *node, const char *target)
}
if(safe_str_eq(target, CRM_SYSTEM_CRMD)) {
- admin_uuid = calloc(1, 11);
- snprintf(admin_uuid, 10, "%d", getpid());
- admin_uuid[10] = '\0';
+ admin_uuid = crm_getpid_s();
hello = create_hello_message(admin_uuid, "crm_node", "0", "1");
rc = crm_ipc_send(conn, hello, 0, 0, NULL);
diff --git a/tools/crm_resource.c b/tools/crm_resource.c
index 8bc70962d..6bc7aec6e 100644
--- a/tools/crm_resource.c
+++ b/tools/crm_resource.c
@@ -586,11 +586,7 @@ main(int argc, char **argv)
return crm_exit(EX_USAGE);
}
- our_pid = calloc(1, 11);
- if (our_pid != NULL) {
- snprintf(our_pid, 10, "%d", getpid());
- our_pid[10] = '\0';
- }
+ our_pid = crm_getpid_s();
if (do_force) {
crm_debug("Forcing...");
diff --git a/tools/crm_resource_runtime.c b/tools/crm_resource_runtime.c
index 416f016ee..57b2b97cf 100644
--- a/tools/crm_resource_runtime.c
+++ b/tools/crm_resource_runtime.c
@@ -552,11 +552,7 @@ send_lrm_rsc_op(crm_ipc_t * crmd_channel, const char *op,
crm_xml_add(params, key, "60000"); /* 1 minute */
free(key);
- our_pid = calloc(1, 11);
- if (our_pid != NULL) {
- snprintf(our_pid, 10, "%d", getpid());
- our_pid[10] = '\0';
- }
+ our_pid = crm_getpid_s();
cmd = create_request(op, msg_data, router_node, CRM_SYSTEM_CRMD, crm_system_name, our_pid);
/* crm_log_xml_warn(cmd, "send_lrm_rsc_op"); */
@@ -957,7 +953,7 @@ update_dataset(cib_t *cib, pe_working_set_t * data_set, bool simulate)
}
if(simulate) {
- pid = crm_itoa(getpid());
+ pid = crm_getpid_s();
shadow_cib = cib_shadow_new(pid);
shadow_file = get_shadow_file(pid);
diff --git a/tools/crm_simulate.c b/tools/crm_simulate.c
index 108e35bfe..886255d78 100644
--- a/tools/crm_simulate.c
+++ b/tools/crm_simulate.c
@@ -432,7 +432,7 @@ setup_input(const char *input, const char *output)
}
if (output == NULL) {
- char *pid = crm_itoa(getpid());
+ char *pid = crm_getpid_s();
local_output = get_shadow_file(pid);
temp_shadow = strdup(local_output);
diff --git a/tools/crmadmin.c b/tools/crmadmin.c
index 293c099a8..497edc2dc 100644
--- a/tools/crmadmin.c
+++ b/tools/crmadmin.c
@@ -408,11 +408,7 @@ do_init(void)
mainloop_io_t *source =
mainloop_add_ipc_client(CRM_SYSTEM_CRMD, G_PRIORITY_DEFAULT, 0, NULL, &crm_callbacks);
- admin_uuid = calloc(1, 11);
- if (admin_uuid != NULL) {
- snprintf(admin_uuid, 10, "%d", getpid());
- admin_uuid[10] = '\0';
- }
+ admin_uuid = crm_getpid_s();
crmd_channel = mainloop_get_ipc_client(source);