2.0.3-0.1.rc3 (rev. 1) - Fix failure to build due to obsolete ftime(3)

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
This commit is contained in:
Jan Pokorný 2019-11-14 18:46:00 +01:00
parent a6f0854f3f
commit 3499ac9197
No known key found for this signature in database
GPG Key ID: 61BBB23A9E8F8DE2
2 changed files with 310 additions and 5 deletions

View File

@ -0,0 +1,304 @@
From 00076ab6adeaf5f28b2f3b233cf6e41bc70bc89e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= <jpokorny@redhat.com>
Date: Thu, 14 Nov 2019 17:31:47 +0100
Subject: [PATCH] Build: restore buildability in the face of obsolete ftime(3)
Since the usage of ftime(3) used to be opt-in only and since
clock_gettime(3) is mandated with POSIX 2001, we can simply
look at whether CLOCK_MONOTONIC is defined to be used as an
identifier for the particular clock (kind exactly suitable
for this context). Dropping some old cruft being a bonus.
Restores out-of-the-box buildability with recent enough glibc.
References:
https://sourceware.org/git/?p=glibc.git;a=commit;h=2b5fea833bcd0f651579afd16ed7842770ecbae1
https://src.fedoraproject.org/rpms/glibc/c/ebf75398f06dd27357d8a5321e8e5959633b8182?branch=master
(for a Fedora Rawhide follow-the-upstream update that lead to this
discovery)
---
configure.ac | 23 +++++----
daemons/execd/Makefile.am | 2 +-
daemons/execd/execd_commands.c | 89 ++++++++++++++++++----------------
3 files changed, 60 insertions(+), 54 deletions(-)
diff --git a/configure.ac b/configure.ac
index bd92b803f..f732613b9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -875,19 +875,15 @@ else
LIBADD_DL=${lt_cv_dlopen_libs}
fi
-dnl FreeBSD needs -lcompat for ftime() used by lrmd.c
-AC_CHECK_LIB([compat], [ftime], [COMPAT_LIBS='-lcompat'])
-AC_SUBST(COMPAT_LIBS)
-
dnl ========================================================================
dnl Headers
dnl ========================================================================
-dnl Some distributions insert #warnings into deprecated headers such as
-dnl timeb.h. If we will enable fatal warnings for the build, then enable
-dnl them for the header checks as well, otherwise the build could fail
-dnl even though the header check succeeds. (We should probably be doing
-dnl this in more places.)
+# Some distributions insert #warnings into deprecated headers such as
+# timeb.h used at some point in past. If we will enable fatal warnings
+# for the build, then enable them for the header checks as well, otherwise
+# the build could fail even though the header check succeeds.
+# (We should probably be doing this in more places.)
if test "x${enable_fatal_warnings}" = xyes ; then
cc_temp_flags "$CFLAGS $WERROR"
fi
@@ -923,7 +919,6 @@ AC_CHECK_HEADERS(sys/signalfd.h)
AC_CHECK_HEADERS(sys/sockio.h)
AC_CHECK_HEADERS(sys/stat.h)
AC_CHECK_HEADERS(sys/time.h)
-AC_CHECK_HEADERS(sys/timeb.h)
AC_CHECK_HEADERS(sys/types.h)
AC_CHECK_HEADERS(sys/utsname.h)
AC_CHECK_HEADERS(sys/wait.h)
@@ -961,6 +956,14 @@ if test "$pf_cv_var_progname" = "yes"; then
AC_DEFINE(HAVE___PROGNAME,1,[ ])
fi
+dnl ========================================================================
+dnl Generic declarations
+dnl ========================================================================
+
+AC_CHECK_DECLS([CLOCK_MONOTONIC], [], [], [[
+ #include <time.h>
+]])
+
dnl ========================================================================
dnl Structures
dnl ========================================================================
diff --git a/daemons/execd/Makefile.am b/daemons/execd/Makefile.am
index 210a7842f..54c9ad492 100644
--- a/daemons/execd/Makefile.am
+++ b/daemons/execd/Makefile.am
@@ -26,7 +26,7 @@ pacemaker_execd_LDFLAGS = $(LDFLAGS_HARDENED_EXE)
pacemaker_execd_LDADD = $(top_builddir)/lib/common/libcrmcommon.la \
$(top_builddir)/lib/services/libcrmservice.la \
- $(top_builddir)/lib/fencing/libstonithd.la ${COMPAT_LIBS}
+ $(top_builddir)/lib/fencing/libstonithd.la
pacemaker_execd_SOURCES = pacemaker-execd.c execd_commands.c \
execd_alerts.c
diff --git a/daemons/execd/execd_commands.c b/daemons/execd/execd_commands.c
index 2d0917d9b..b733e6b1f 100644
--- a/daemons/execd/execd_commands.c
+++ b/daemons/execd/execd_commands.c
@@ -10,6 +10,11 @@
#include <crm_internal.h>
#include <glib.h>
+
+#if HAVE_DECL_CLOCK_MONOTONIC
+#include <time.h> /* clock_gettime */
+#endif
+
#include <unistd.h>
#include <crm/crm.h>
@@ -21,10 +26,6 @@
#include "pacemaker-execd.h"
-#ifdef HAVE_SYS_TIMEB_H
-# include <sys/timeb.h>
-#endif
-
#define EXIT_REASON_MAX_LEN 128
GHashTable *rsc_list = NULL;
@@ -57,16 +58,16 @@ typedef struct lrmd_cmd_s {
char *output;
char *userdata_str;
-#ifdef HAVE_SYS_TIMEB_H
+#if HAVE_DECL_CLOCK_MONOTONIC && defined(CLOCK_MONOTONIC)
/* Recurring and systemd operations may involve more than one executor
* command per operation, so they need info about the original and the most
* recent.
*/
- struct timeb t_first_run; /* Timestamp of when op first ran */
- struct timeb t_run; /* Timestamp of when op most recently ran */
- struct timeb t_first_queue; /* Timestamp of when op first was queued */
- struct timeb t_queue; /* Timestamp of when op most recently was queued */
- struct timeb t_rcchange; /* Timestamp of last rc change */
+ struct timespec t_first_run; /* Timestamp of when op first ran */
+ struct timespec t_run; /* Timestamp of when op most recently ran */
+ struct timespec t_first_queue; /* Timestamp of when op first was queued */
+ struct timespec t_queue; /* Timestamp of when op most recently was queued */
+ struct timespec t_rcchange; /* Timestamp of last rc change */
#endif
int first_notify_sent;
@@ -94,7 +95,7 @@ log_finished(lrmd_cmd_t * cmd, int exec_time, int queue_time)
if (safe_str_eq(cmd->action, "monitor")) {
log_level = LOG_DEBUG;
}
-#ifdef HAVE_SYS_TIMEB_H
+#if HAVE_DECL_CLOCK_MONOTONIC && defined(CLOCK_MONOTONIC)
do_crm_log(log_level,
"finished - rsc:%s action:%s call_id:%d %s%s exit-code:%d exec-time:%dms queue-time:%dms",
cmd->rsc_id, cmd->action, cmd->call_id, cmd->last_pid ? "pid:" : "", pid_str,
@@ -233,9 +234,9 @@ stonith_recurring_op_helper(gpointer data)
* to be executed */
rsc->recurring_ops = g_list_remove(rsc->recurring_ops, cmd);
rsc->pending_ops = g_list_append(rsc->pending_ops, cmd);
-#ifdef HAVE_SYS_TIMEB_H
- ftime(&cmd->t_queue);
- if (cmd->t_first_queue.time == 0) {
+#if HAVE_DECL_CLOCK_MONOTONIC && defined(CLOCK_MONOTONIC)
+ clock_gettime(CLOCK_MONOTONIC, &cmd->t_queue);
+ if (cmd->t_first_queue.tv_sec == 0) {
cmd->t_first_queue = cmd->t_queue;
}
#endif
@@ -360,9 +361,9 @@ schedule_lrmd_cmd(lrmd_rsc_t * rsc, lrmd_cmd_t * cmd)
}
rsc->pending_ops = g_list_append(rsc->pending_ops, cmd);
-#ifdef HAVE_SYS_TIMEB_H
- ftime(&cmd->t_queue);
- if (cmd->t_first_queue.time == 0) {
+#if HAVE_DECL_CLOCK_MONOTONIC && defined(CLOCK_MONOTONIC)
+ clock_gettime(CLOCK_MONOTONIC, &cmd->t_queue);
+ if (cmd->t_first_queue.tv_sec == 0) {
cmd->t_first_queue = cmd->t_queue;
}
#endif
@@ -424,7 +425,7 @@ send_client_notify(gpointer key, gpointer value, gpointer user_data)
client->name, client->id, msg, rc);
}
-#ifdef HAVE_SYS_TIMEB_H
+#if HAVE_DECL_CLOCK_MONOTONIC && defined(CLOCK_MONOTONIC)
/*!
* \internal
* \brief Return difference between two times in milliseconds
@@ -432,21 +433,25 @@ send_client_notify(gpointer key, gpointer value, gpointer user_data)
* \param[in] now More recent time (or NULL to use current time)
* \param[in] old Earlier time
*
- * \return milliseconds difference (or 0 if old is NULL or has time zero)
+ * \return milliseconds difference (or 0 if old is NULL or has tv_sec zero)
+ *
+ * \note Can overflow on 32bit machines when the differences is around
+ * 50 days or more.
*/
static int
-time_diff_ms(struct timeb *now, struct timeb *old)
+time_diff_ms(struct timespec *now, struct timespec *old)
{
- struct timeb local_now = { 0, };
+ struct timespec local_now = { 0, };
if (now == NULL) {
- ftime(&local_now);
+ clock_gettime(CLOCK_MONOTONIC, &local_now);
now = &local_now;
}
- if ((old == NULL) || (old->time == 0)) {
+ if ((old == NULL) || (old->tv_sec == 0)) {
return 0;
}
- return (now->time - old->time) * 1000 + now->millitm - old->millitm;
+ return (now->tv_sec - old->tv_sec) * 1000
+ + (now->tv_nsec - old->tv_nsec) / 1000;
}
/*!
@@ -484,7 +489,7 @@ send_cmd_complete_notify(lrmd_cmd_t * cmd)
int queue_time = 0;
xmlNode *notify = NULL;
-#ifdef HAVE_SYS_TIMEB_H
+#if HAVE_DECL_CLOCK_MONOTONIC && defined(CLOCK_MONOTONIC)
exec_time = time_diff_ms(NULL, &cmd->t_run);
queue_time = time_diff_ms(&cmd->t_run, &cmd->t_queue);
#endif
@@ -519,9 +524,9 @@ send_cmd_complete_notify(lrmd_cmd_t * cmd)
crm_xml_add_int(notify, F_LRMD_CALLID, cmd->call_id);
crm_xml_add_int(notify, F_LRMD_RSC_DELETED, cmd->rsc_deleted);
-#ifdef HAVE_SYS_TIMEB_H
- crm_xml_add_ll(notify, F_LRMD_RSC_RUN_TIME, (long long) cmd->t_run.time);
- crm_xml_add_ll(notify, F_LRMD_RSC_RCCHANGE_TIME, (long long) cmd->t_rcchange.time);
+#if HAVE_DECL_CLOCK_MONOTONIC && defined(CLOCK_MONOTONIC)
+ crm_xml_add_ll(notify, F_LRMD_RSC_RUN_TIME, (long long) cmd->t_run.tv_sec);
+ crm_xml_add_ll(notify, F_LRMD_RSC_RCCHANGE_TIME, (long long) cmd->t_rcchange.tv_sec);
crm_xml_add_int(notify, F_LRMD_RSC_EXEC_TIME, exec_time);
crm_xml_add_int(notify, F_LRMD_RSC_QUEUE_TIME, queue_time);
#endif
@@ -592,7 +597,7 @@ cmd_reset(lrmd_cmd_t * cmd)
{
cmd->lrmd_op_status = 0;
cmd->last_pid = 0;
-#ifdef HAVE_SYS_TIMEB_H
+#if HAVE_DECL_CLOCK_MONOTONIC && defined(CLOCK_MONOTONIC)
memset(&cmd->t_run, 0, sizeof(cmd->t_run));
memset(&cmd->t_queue, 0, sizeof(cmd->t_queue));
#endif
@@ -831,9 +836,9 @@ action_complete(svc_action_t * action)
action->id);
return;
}
-#ifdef HAVE_SYS_TIMEB_H
+#if HAVE_DECL_CLOCK_MONOTONIC && defined(CLOCK_MONOTONIC)
if (cmd->exec_rc != action->rc) {
- ftime(&cmd->t_rcchange);
+ clock_gettime(CLOCK_MONOTONIC, &cmd->t_rcchange);
}
#endif
@@ -876,7 +881,7 @@ action_complete(svc_action_t * action)
goagain = true;
} else {
-#ifdef HAVE_SYS_TIMEB_H
+#if HAVE_DECL_CLOCK_MONOTONIC && defined(CLOCK_MONOTONIC)
int time_sum = time_diff_ms(NULL, &cmd->t_first_run);
int timeout_left = cmd->timeout_orig - time_sum;
@@ -912,13 +917,11 @@ action_complete(svc_action_t * action)
}
#endif
- /* Wrapping this section in ifdef implies that systemd resources are not
- * fully supported on platforms without sys/timeb.h. Since timeb is
- * obsolete, we should eventually prefer a clock_gettime() implementation
- * (wrapped in its own ifdef) with timeb as a fallback.
- */
- if(goagain) {
-#ifdef HAVE_SYS_TIMEB_H
+ /* Wrapping this section in ifdef implies that systemd resources
+ are not fully supported on platforms without CLOCK_MONOTONIC,
+ which is most likely contradiction, but for completeness... */
+ if (goagain) {
+#if HAVE_DECL_CLOCK_MONOTONIC && defined(CLOCK_MONOTONIC)
int time_sum = time_diff_ms(NULL, &cmd->t_first_run);
int timeout_left = cmd->timeout_orig - time_sum;
int delay = cmd->timeout_orig / 10;
@@ -1344,11 +1347,11 @@ lrmd_rsc_execute(lrmd_rsc_t * rsc)
rsc->pending_ops = g_list_remove_link(rsc->pending_ops, first);
g_list_free_1(first);
-#ifdef HAVE_SYS_TIMEB_H
- if (cmd->t_first_run.time == 0) {
- ftime(&cmd->t_first_run);
+#if HAVE_DECL_CLOCK_MONOTONIC && defined(CLOCK_MONOTONIC)
+ if (cmd->t_first_run.tv_sec == 0) {
+ clock_gettime(CLOCK_MONOTONIC, &cmd->t_first_run);
}
- ftime(&cmd->t_run);
+ clock_gettime(CLOCK_MONOTONIC, &cmd->t_run);
#endif
}
--
2.24.0.rc1

View File

@ -143,7 +143,7 @@ Url: http://www.clusterlabs.org
Source0: https://github.com/%{github_owner}/%{name}/archive/%{commit}/%{name}-%{shortcommit}.tar.gz
Source1: https://github.com/%{github_owner}/%{nagios_name}/archive/%{nagios_hash}/%{nagios_name}-%{nagios_hash}.tar.gz
# ---
# patches go here
Patch0: Build-restore-buildability-in-the-face-of-obsolete-ftime.patch
Requires: resource-agents
Requires: %{name}-libs%{?_isa} = %{version}-%{release}
@ -188,7 +188,7 @@ BuildRequires: asciidoc inkscape publican
%endif
# git-style patch application
#BuildRequires: git
BuildRequires: git
Provides: pcmk-cluster-manager = %{version}-%{release}
Provides: pcmk-cluster-manager%{?_isa} = %{version}-%{release}
@ -348,9 +348,9 @@ monitor resources.
%prep
%setup -q -a 1 -n %{name}-%{commit}
#global __scm git_am
#__scm_setup_git
#autopatch -p1
%global __scm git_am
%__scm_setup_git
%autopatch -p1
%build
@ -714,6 +714,7 @@ exit 0
- Update for new upstream tarball for release candidate: Pacemaker-2.0.3-rc3,
for full details, see included ChangeLog file or
https://github.com/ClusterLabs/pacemaker/releases/tag/Pacemaker-2.0.3-rc3
- Fix failure to build due to using obsolete ftime(3)
* Wed Nov 06 2019 Jan Pokorný <jpokorny+rpm-pacemaker@redhat.com> - 2.0.3-0.1.rc2
- Update for new upstream tarball for release candidate: Pacemaker-2.0.3-rc2,