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

dest.c: Use monotonic time for cups_enum_dest #1084

Open
wants to merge 1 commit into
base: 2.4.x
Choose a base branch
from

Conversation

zdohnal
Copy link
Member

@zdohnal zdohnal commented Oct 21, 2024

Patch written by Adam Williamson.

gettimeofday() is vulnerable to clock jumps, so it is better to use clock_gettime() to avoid issues with libcups if system changes clock, f.e. in Live CDs.

Copy link
Member

@michaelrsweet michaelrsweet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking we need a CUPS API that returns a monotonic value, probably a double for portability.

double cupsGetClock(void);

If we back-port this to CUPS 2.4.x, we'll want to leave this as private API (_cupsGetClock).

cups/dest.c Outdated
t->t = GetTickCount();
#elif HAVE_CLOCK_MONOTONIC
clock_gettime(CLOCK_MONOTONIC, &t->t);
#elif __sun
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not bother with Solaris-specific functions. We don't have any Solaris testing resources.

cups/dest.c Outdated
cups_gettimeofday(_cups_time_t *t)
{
#if _WIN32
t->t = GetTickCount();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to use GetTickCount64, otherwise we have a 49 day wrap problem.

cups/dest.c Outdated
typedef struct _cups_time_s
{
#if _WIN32
DWORD t;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd actually like to do away with this kind of structure here - let's just use a double to return "elapsed time" and then we can use simple math operations portably across platforms.

@@ -448,6 +450,22 @@ AC_DEFINE_UNQUOTED([CUPS_DEFAULT_SYSTEM_AUTHKEY], ["$CUPS_DEFAULT_SYSTEM_AUTHKEY
AC_SUBST([CUPS_SYSTEM_AUTHKEY])
AC_SUBST([INSTALLXPC])

dnl Check if monotonic clock is available
AC_MSG_CHECKING([for monotonic clock])
AC_LINK_IFELSE([AC_LANG_PROGRAM([
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be enough to check that CLOCK_MONOTONIC is defined. CUPS requires POSIX compliance.

@@ -224,6 +224,8 @@ AC_COMPILE_IFELSE([
dnl See if we have the removefile(3) function for securely removing files
AC_CHECK_FUNCS([removefile])

dnl See if
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

???

cups/dest.c Outdated
#if _WIN32
t->t = GetTickCount();
#elif HAVE_CLOCK_MONOTONIC
clock_gettime(CLOCK_MONOTONIC, &t->t);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if CLOCK_MONOTONIC is defined, that doesn't mean that the platform will support that clock. Check for a non-zero return and fallback on gettimeofday when it fails.

@michaelrsweet michaelrsweet self-assigned this Oct 22, 2024
@michaelrsweet michaelrsweet added bug Something isn't working priority-medium labels Oct 22, 2024
@michaelrsweet michaelrsweet added this to the v2.4.x milestone Oct 22, 2024
@michaelrsweet
Copy link
Member

[master 0350eba] Add cupsGetClock API.

Also in libcups repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority-medium
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants