Check clock_gettime() return value and warn if it fails.

Currently, the timestamp will be ignored if clock_gettime() fails.
This commit is contained in:
Todd C. Miller
2015-02-24 09:53:50 -07:00
parent 23f4e49f4d
commit 01a4d6ccbf
2 changed files with 12 additions and 4 deletions

View File

@@ -460,8 +460,10 @@ __dso_public int sudo_sig2str(int signo, char *signame);
# define sig2str(_a, _b) sudo_sig2str((_a), (_b)) # define sig2str(_a, _b) sudo_sig2str((_a), (_b))
#endif /* HAVE_SIG2STR */ #endif /* HAVE_SIG2STR */
#ifndef HAVE_CLOCK_GETTIME #ifndef HAVE_CLOCK_GETTIME
# if !defined(CLOCK_REALTIME)
# define CLOCK_REALTIME 0 # define CLOCK_REALTIME 0
# ifdef __MACH__ # endif
# if defined(__MACH__) && !defined(CLOCK_MONOTONIC)
# define CLOCK_MONOTONIC 1 # define CLOCK_MONOTONIC 1
# endif # endif
__dso_public int sudo_clock_gettime(clockid_t clock_id, struct timespec *tp); __dso_public int sudo_clock_gettime(clockid_t clock_id, struct timespec *tp);

View File

@@ -345,7 +345,10 @@ update_timestamp(struct passwd *pw)
/* Fill in time stamp. */ /* Fill in time stamp. */
memcpy(&entry, &timestamp_key, sizeof(struct timestamp_entry)); memcpy(&entry, &timestamp_key, sizeof(struct timestamp_entry));
clock_gettime(SUDO_CLOCK_MONOTONIC, &entry.ts); if (clock_gettime(SUDO_CLOCK_MONOTONIC, &entry.ts) == -1) {
log_warning(0, "clock_gettime(%d)", SUDO_CLOCK_MONOTONIC);
goto done;
}
/* Open time stamp file and lock it for exclusive access. */ /* Open time stamp file and lock it for exclusive access. */
if (timestamp_uid != 0) if (timestamp_uid != 0)
@@ -427,7 +430,10 @@ timestamp_status(struct passwd *pw)
timestamp_key.u.ppid = getppid(); timestamp_key.u.ppid = getppid();
} }
} }
clock_gettime(SUDO_CLOCK_MONOTONIC, &timestamp_key.ts); if (clock_gettime(SUDO_CLOCK_MONOTONIC, &timestamp_key.ts) == -1) {
log_warning(0, "clock_gettime(%d)", SUDO_CLOCK_MONOTONIC);
status = TS_ERROR;
}
/* If the time stamp dir is missing there is nothing to do. */ /* If the time stamp dir is missing there is nothing to do. */
if (status == TS_MISSING) if (status == TS_MISSING)