-
Notifications
You must be signed in to change notification settings - Fork 195
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
base: 2.4.x
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
config-scripts/cups-common.m4
Outdated
@@ -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([ |
There was a problem hiding this comment.
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.
config-scripts/cups-common.m4
Outdated
@@ -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 |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
[master 0350eba] Add cupsGetClock API. Also in libcups repository. |
3256ace
to
8e7e192
Compare
Patch written by Adam Williamson.
gettimeofday()
is vulnerable to clock jumps, so it is better to useclock_gettime()
to avoid issues with libcups if system changes clock, f.e. in Live CDs.