Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove/replace time calls #3328

Open
wants to merge 3 commits into
base: devel
Choose a base branch
from

Conversation

matt335672
Copy link
Member

@matt335672 matt335672 commented Dec 4, 2024

Edit: No longer draft.

This does not need to be back-ported to v0.10. It's mostly a tidy-up looking to the future.

This PR removes g_time1() and g_time2() and replaces g_time3() with the more descriptively named g_get_elapsed_ms()

Each function is addressed in a separate commit in this PR.

g_time1() is not year 2038 compliant on systems with 32-bit integers. It can be trivially replaced with time() which is a standard C library function, so that is done here.

g_time2() is no longer used.

g_time3() is a little more complex:-

  • The gettimeofday() call it uses is obsoleted in POSIX.1-2008. Here we use clock_gettime(CLOCK_MONOTONIC, )
  • To comply with the C standard on integer overflow, the function needs to return an unsigned integer type. Expressions (or sub-expressions) used to calculate elapsed time must also used unsigned arithmetic.

@matt335672 matt335672 force-pushed the fix_time_calls branch 3 times, most recently from 4bf6595 to 32ba1d0 Compare December 4, 2024 16:04
@matt335672 matt335672 marked this pull request as ready for review December 4, 2024 16:10
This is not year 2038 compliant on systems with 32-bit integers.

The call can be replaced with the standard C time() call. On
POSIX systems, time_t is guaranteed to be an integer type.
This is currently unused in xrdp
The function as specified used gettimeofday() which is susceptible
to manual time changes, and is obsoleted in POSIX.1-2008. The
replacement uses clock_gettime(CLOCK_MONOTONIC, ) which is not
susceptible to manual time changes (at least on Linux) and cannot run
backwards.

Also, on systems with 32-bit integers, the value returned by this
function wraps around every 49.7 days. To cope with a wraparound in
a way compliant with the C standard, this value needs to return an
unsigned integer type rather than a signed integer type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant