git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 0/2] use gettimeofday for current time

From
Paul Eggert <eggert@cs.ucla.edu>
Date
Mar 19, 2023, 06:43 UTC
Message-ID
<20230319064353.686226-1-eggert@cs.ucla.edu>

In recent GNU/Linux versions on rare occasions the 'time' function returns a value that is one second less than the seconds component of the timestamp that would be returned by gettimeofday, clock_gettime with CLOCK_REALTIME, 'stat' on a recently modified file, etc.

If a program calls both 'time' and any of these other functions, the system clock will appear to jump backwards by a second temporarily. This can lead to confusing or inconsistent output.

A simple workaround for Git is to use 'gettimeofday' instead of 'time'. Although other options are possible (see the commit message of patch 0002), simplest is probably best.

Paul Eggert (2):
  git-compat-util: time_now for current time
  git-compat-util: use gettimeofday for current time
 archive.c                          | 2 +-
 blame.c                            | 2 +-
 builtin/bugreport.c                | 2 +-
 builtin/credential-cache--daemon.c | 4 ++--
 builtin/diagnose.c                 | 2 +-
 builtin/fast-import.c              | 2 +-
 builtin/fsmonitor--daemon.c        | 4 ++--
 builtin/gc.c                       | 2 +-
 builtin/log.c                      | 2 +-
 builtin/receive-pack.c             | 2 +-
 builtin/reflog.c                   | 2 +-
 commit-graph.c                     | 4 ++--
 compat/nedmalloc/malloc.c.h        | 2 +-
 credential.c                       | 4 ++--
 date.c                             | 6 +++---
 git-compat-util.h                  | 8 ++++++++
 http-backend.c                     | 2 +-
 http-push.c                        | 6 +++---
 rerere.c                           | 2 +-
 run-command.c                      | 4 ++--
 t/helper/test-chmtime.c            | 4 ++--
 t/helper/test-simple-ipc.c         | 4 ++--
 22 files changed, 40 insertions(+), 32 deletions(-)

-- 2.39.2

Next: Paul Eggert
Message 1 of 19 in “use gettimeofday for current time”
  1. 0/2 use gettimeofday for current timePaul Eggert, Mar 19, 2023
  2. 2/2 git-compat-util: use gettimeofday for current timePaul Eggert, Mar 19, 2023
  3. Eric WongMar 19, 2023
  4. Junio C HamanoMar 20, 2023
  5. Junio C HamanoMar 20, 2023
  6. Paul EggertMar 20, 2023
  7. Junio C HamanoMar 20, 2023
  8. Taylor BlauMar 20, 2023
  9. Taylor BlauMar 20, 2023
  10. 1/2 git-compat-util: time_now for current timePaul Eggert, Mar 19, 2023
  11. git-compat-util: use gettimeofday(2) for time(2)Junio C Hamano, Mar 20, 2023
  12. Paul EggertMar 20, 2023
  13. Junio C HamanoMar 21, 2023
  14. Konstantin KhomoutovMar 21, 2023
  15. Junio C HamanoMar 21, 2023
  16. Jeff KingMar 21, 2023
  17. Taylor BlauMar 21, 2023
  18. Junio C HamanoMar 21, 2023
  19. Jeff KingMar 22, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.