diff --git a/time-1.8-Prefer-clock_gettime-CLOCK_MONOTONIC.patch b/time-1.8-Prefer-clock_gettime-CLOCK_MONOTONIC.patch new file mode 100644 index 0000000000000000000000000000000000000000..ec5c8aa43fc7c3b07ca0618ce02b408ee7d7c695 --- /dev/null +++ b/time-1.8-Prefer-clock_gettime-CLOCK_MONOTONIC.patch @@ -0,0 +1,108 @@ +From a3c400a8553b598bc2fd01eb0f63c5748b2147e1 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= +Date: Wed, 8 Nov 2017 17:02:42 +0100 +Subject: [PATCH] Prefer clock_gettime(CLOCK_MONOTONIC) +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +gettimeofday() reports wrong elapsed real time if a time step was +inserted while running a program. This can happen on initial time +adjustment from NTP server or by manual adjustement by date command. + +This patch uses clock_gettime(CLOCK_MONOTONIC) instead (if available) +that does not suffer from the issue. + + + +Signed-off-by: Petr Písař +--- + configure.ac | 3 +++ + src/resuse.c | 27 +++++++++++++++++++++++++-- + 2 files changed, 28 insertions(+), 2 deletions(-) + +diff --git a/configure.ac b/configure.ac +index ede8fd5..d2950bd 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -72,6 +72,9 @@ dnl Checks for library functions. + AC_FUNC_VPRINTF + AC_FUNC_WAIT3 + AC_CHECK_FUNCS(strerror) ++AC_SEARCH_LIBS(clock_gettime, [rt]) ++test "$ac_cv_search_clock_gettime" != "no" && \ ++ AC_DEFINE([HAVE_CLOCK_GETTIME], [1], [System provides clock_gettime() call]) + + + # What memory units are reported by getrusage(2) ? +diff --git a/src/resuse.c b/src/resuse.c +index d2ab870..ec54863 100644 +--- a/src/resuse.c ++++ b/src/resuse.c +@@ -26,7 +26,14 @@ + #include + #include + +-#if !HAVE_WAIT3 ++#if HAVE_WAIT3 ++# if HAVE_CLOCK_GETTIME ++# ifndef _POSIX_C_SOURCE ++# define _POSIX_C_SOURCE 199309L ++# endif ++# include ++# endif ++#else + # include + # ifndef HZ + # include +@@ -51,7 +58,14 @@ resuse_start (resp) + RESUSE *resp; + { + #if HAVE_WAIT3 ++#if HAVE_CLOCK_GETTIME ++ struct timespec res; ++ clock_gettime(CLOCK_MONOTONIC, &res); ++ resp->start.tv_sec = res.tv_sec; ++ resp->start.tv_usec = res.tv_nsec / 1000; ++#else + gettimeofday (&resp->start, (struct timezone *) 0); ++#endif /* !HAVE_CLOCK_GETTIME */ + #else + long value; + struct tms tms; +@@ -59,7 +73,7 @@ resuse_start (resp) + value = times (&tms); + resp->start.tv_sec = value / HZ; + resp->start.tv_usec = value % HZ * (1000000 / HZ); +-#endif ++#endif /* !HAVE_WAIT3 */ + } + + /* Wait for and fill in data on child process PID. +@@ -79,6 +93,9 @@ resuse_end (pid, resp) + int status; + + #if HAVE_WAIT3 ++#if HAVE_CLOCK_GETTIME ++ struct timespec res; ++#endif + pid_t caught; + + /* Ignore signals, but don't ignore the children. When wait3 +@@ -89,7 +106,13 @@ resuse_end (pid, resp) + return 0; + } + ++#if HAVE_CLOCK_GETTIME ++ clock_gettime(CLOCK_MONOTONIC, &res); ++ resp->elapsed.tv_sec = res.tv_sec; ++ resp->elapsed.tv_usec = res.tv_nsec / 1000; ++#else + gettimeofday (&resp->elapsed, (struct timezone *) 0); ++#endif + #else /* !HAVE_WAIT3 */ + long value; + struct tms tms; +-- +2.13.6 + diff --git a/time-1.9-Close-outfp-before-exec.patch b/time-1.9-Close-outfp-before-exec.patch new file mode 100644 index 0000000000000000000000000000000000000000..3902bb6139c8a26db7b43e6dcce832098c9b4967 --- /dev/null +++ b/time-1.9-Close-outfp-before-exec.patch @@ -0,0 +1,34 @@ +From 6a5c4499aab677d19157c7adcf598d14267283c1 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= +Date: Mon, 16 Nov 2020 17:45:04 +0100 +Subject: [PATCH] Close outfp before exec +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +When called with --outfile, we open an output file to which +we log timing results. Close that descriptor in the child +fork before exec'ing the process to be timed. + +Reported-by: Ed Santiago +Signed-off-by: Petr Písař +--- + src/time.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/src/time.c b/src/time.c +index f76265a..2f2b702 100644 +--- a/src/time.c ++++ b/src/time.c +@@ -738,6 +738,8 @@ run_command (cmd, resp) + error (EXIT_CANCELED, errno, "cannot fork"); + else if (pid == 0) + { /* If child. */ ++ if (outfp != stderr) ++ fclose(outfp); + /* Don't cast execvp arguments; that causes errors on some systems, + versus merely warnings if the cast is left off. */ + execvp (cmd[0], cmd); +-- +2.25.4 + diff --git a/time-1.9.tar.gz b/time-1.9.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..f8202398685911c31cd2491b01585a43db6b427c Binary files /dev/null and b/time-1.9.tar.gz differ diff --git a/time.spec b/time.spec new file mode 100644 index 0000000000000000000000000000000000000000..59cd000c2d0f1c726b8d92cedea006601a3f2b28 --- /dev/null +++ b/time.spec @@ -0,0 +1,110 @@ +%define anolis_release 1 + +Summary: A GNU utility for monitoring a program's use of system resources +Name: time +Version: 1.9 +Release: %{anolis_release}%{?dist} +# src/time.c: GPLv3+ +# COPYING: GPLv3 text +# doc/time.texi: GFDL +# doc/fdl.texi: GFDL 1.3 text +# doc/time.info: GFDL +# lib/stdnoreturn.in.h: GPLv3+ +# lib/strerror-override.c: GPLv3+ +# lib/error.h: GPLv3+ +## Not in a binary package +# tests/init.sh: GPLv3+ +# INSTALL: FSFAP +# configure: FSFUL +# build-aux/config.guess: GPLv3+ with exceptions +# build-aux/install-sh: MIT and Public Domain +# build-aux/config.rpath: FSFULLR +# build-aux/test-driver: GPLv2+ with exceptions +# build-aux/update-copyright: GPLv3+ +# build-aux/useless-if-before-free: GPLv3+ +# build-aux/vc-list-files: GPLv3+ +# build-aux/missing: GPLv2+ with exceptions +# build-aux/compile: GPLv2+ with exceptions +# build-aux/config.sub: GPLv3+ with exceptions +# build-aux/gitlog-to-changelog: GPLv3+ +# build-aux/git-version-gen: GPLv3+ +# build-aux/texinfo.tex: GPLv3+ with exceptions and GPL+ +# build-aux/depcomp: GPLv2+ with exceptions +# build-aux/mdate-sh: GPLv2+ with exceptions +# GNUmakefile: GPLv3+ +# m4/asm-underscore.m4: FSFULLR +# m4/gnulib-cache.m4: GPLv3+ with exceptions +# m4/host-cpu-c-abi.m4: FSFULLR +# m4/longlong.m4: FSFULLR +# m4/ssize_t.m4: FSFULLR +# m4/stdnoreturn.m4: FSFULLR +# maint.mk: GPLv3+ +# tests/time-posix-quiet.sh: GPLv3+ +License: GPLv3+ and GFDL +Url: https://www.gnu.org/software/%{name}/ +Source0: https://ftp.gnu.org/gnu/%{name}/%{name}-%{version}.tar.gz +# Fix measuring time when a clock experiences a jump. +# +Patch0: time-1.8-Prefer-clock_gettime-CLOCK_MONOTONIC.patch +# Do not leak a file descriptor of the --output argument to a command, +# proposed to an upstream, +# +Patch3: time-1.9-Close-outfp-before-exec.patch +BuildRequires: autoconf +BuildRequires: automake +BuildRequires: bash +BuildRequires: coreutils +BuildRequires: gcc +BuildRequires: gnupg2 +BuildRequires: make +BuildRequires: sed +BuildRequires: texinfo + +%description +The GNU time utility runs another program, collects information about +the resources used by that program while it is running, and displays +the results. + +%package doc +Summary: Documentation files for %{name} +Requires: %{name} = %{EVR} +BuildArch: noarch + +%description doc +The %{name}-doc package contains documentation files for %{name}. + +%prep +%setup -q +%patch0 -p1 +%patch3 -p1 +# Correct version VERSION flag for doc/time.texi +# +printf '%{version}\n' > .tarball-version +autoreconf -fi + +%build +%configure +%{make_build} + +%install +%{make_install} +# Remove info index, it's updated by file triggers +rm -f $RPM_BUILD_ROOT%{_infodir}/dir +%generate_compatibility_deps + +%check +%{make_build} check + +%files +%license COPYING +%{_bindir}/time +%{_infodir}/time.info* +%dir %{abidir} +%{abidir}/time-option.list + +%files doc +%doc AUTHORS ChangeLog NEWS README + +%changelog +* Mon Mar 20 2023 Yuanhong Peng - 1.9-1 +- Init from upstream