2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-31 14:25:15 +00:00

We cannot (easily) use clock_gettime(CLOCK_MONOTONIC) directly as

it may be present but not implemented.  Add sudo_gettime_real() and
sudo_gettime_mono() functions to get the real and monotonic times
respectively.  Now sudo_gettime_mono() checks the value of
sysconf(_SC_MONOTONIC_CLOCK) before calling clock_gettime(CLOCK_MONOTONIC)
and falls back on sudo_gettime_real() as needed.  The Mach version
of sudo_gettime_mono() uses mach_absolute_time().

This should fix problems with timestamp files on systems where
the CLOCK_MONOTONIC is defined but not actually implemented.
This commit is contained in:
Todd C. Miller
2015-02-24 11:19:21 -07:00
parent 01a4d6ccbf
commit 5d2e9426b2
12 changed files with 178 additions and 155 deletions

View File

@@ -51,15 +51,6 @@
#include "sudoers.h"
#include "check.h"
/* On Linux, CLOCK_MONOTONIC does not run while suspended. */
#if defined(CLOCK_BOOTTIME)
# define SUDO_CLOCK_MONOTONIC CLOCK_BOOTTIME
#elif defined(CLOCK_MONOTONIC)
# define SUDO_CLOCK_MONOTONIC CLOCK_MONOTONIC
#else
# define SUDO_CLOCK_MONOTONIC CLOCK_REALTIME
#endif
static char timestamp_file[PATH_MAX];
static off_t timestamp_hint = (off_t)-1;
static struct timestamp_entry timestamp_key;
@@ -345,8 +336,8 @@ update_timestamp(struct passwd *pw)
/* Fill in time stamp. */
memcpy(&entry, &timestamp_key, sizeof(struct timestamp_entry));
if (clock_gettime(SUDO_CLOCK_MONOTONIC, &entry.ts) == -1) {
log_warning(0, "clock_gettime(%d)", SUDO_CLOCK_MONOTONIC);
if (sudo_gettime_mono(&entry.ts) == -1) {
log_warning(0, N_("unable to read the clock"));
goto done;
}
@@ -430,8 +421,8 @@ timestamp_status(struct passwd *pw)
timestamp_key.u.ppid = getppid();
}
}
if (clock_gettime(SUDO_CLOCK_MONOTONIC, &timestamp_key.ts) == -1) {
log_warning(0, "clock_gettime(%d)", SUDO_CLOCK_MONOTONIC);
if (sudo_gettime_mono(&timestamp_key.ts) == -1) {
log_warning(0, N_("unable to read the clock"));
status = TS_ERROR;
}