mirror of
https://github.com/sudo-project/sudo.git
synced 2025-09-01 06:45:10 +00:00
Use a monotonic timer that only runs while not suspended for the
iolog timing values and write nsec-precision entries.
This commit is contained in:
@@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/time.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#ifdef HAVE_STRING_H
|
#ifdef HAVE_STRING_H
|
||||||
@@ -67,7 +66,7 @@ struct iolog_details {
|
|||||||
static struct iolog_details iolog_details;
|
static struct iolog_details iolog_details;
|
||||||
static bool iolog_compress = false;
|
static bool iolog_compress = false;
|
||||||
static bool warned = false;
|
static bool warned = false;
|
||||||
static struct timeval last_time;
|
static struct timespec last_time;
|
||||||
static unsigned int sessid_max = SESSID_MAX;
|
static unsigned int sessid_max = SESSID_MAX;
|
||||||
static mode_t iolog_filemode = S_IRUSR|S_IWUSR;
|
static mode_t iolog_filemode = S_IRUSR|S_IWUSR;
|
||||||
static mode_t iolog_dirmode = S_IRWXU;
|
static mode_t iolog_dirmode = S_IRWXU;
|
||||||
@@ -785,7 +784,7 @@ iolog_deserialize_info(struct iolog_details *details, char * const user_info[],
|
|||||||
*/
|
*/
|
||||||
static bool
|
static bool
|
||||||
write_info_log(char *pathbuf, size_t len, struct iolog_details *details,
|
write_info_log(char *pathbuf, size_t len, struct iolog_details *details,
|
||||||
char * const argv[], struct timeval *now)
|
char * const argv[], struct timespec *now)
|
||||||
{
|
{
|
||||||
char * const *av;
|
char * const *av;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
@@ -958,7 +957,7 @@ sudoers_io_open(unsigned int version, sudo_conv_t conversation,
|
|||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
/* Write log file with user and command details. */
|
/* Write log file with user and command details. */
|
||||||
if (gettimeofday(&last_time, NULL) == -1) {
|
if (sudo_gettime_awake(&last_time) == -1) {
|
||||||
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO,
|
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO,
|
||||||
"%s: unable to get time of day", __func__);
|
"%s: unable to get time of day", __func__);
|
||||||
goto done;
|
goto done;
|
||||||
@@ -1056,7 +1055,7 @@ sudoers_io_version(int verbose)
|
|||||||
static int
|
static int
|
||||||
sudoers_io_log(const char *buf, unsigned int len, int idx)
|
sudoers_io_log(const char *buf, unsigned int len, int idx)
|
||||||
{
|
{
|
||||||
struct timeval now, delay;
|
struct timespec now, delay;
|
||||||
char tbuf[1024];
|
char tbuf[1024];
|
||||||
const char *errstr = NULL;
|
const char *errstr = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
@@ -1068,7 +1067,7 @@ sudoers_io_log(const char *buf, unsigned int len, int idx)
|
|||||||
debug_return_int(-1);
|
debug_return_int(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gettimeofday(&now, NULL) == -1) {
|
if (sudo_gettime_awake(&now) == -1) {
|
||||||
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO,
|
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO,
|
||||||
"%s: unable to get time of day", __func__);
|
"%s: unable to get time of day", __func__);
|
||||||
errstr = strerror(errno);
|
errstr = strerror(errno);
|
||||||
@@ -1081,9 +1080,9 @@ sudoers_io_log(const char *buf, unsigned int len, int idx)
|
|||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
/* Write timing file entry. */
|
/* Write timing file entry. */
|
||||||
sudo_timevalsub(&now, &last_time, &delay);
|
sudo_timespecsub(&now, &last_time, &delay);
|
||||||
len = (unsigned int)snprintf(tbuf, sizeof(tbuf), "%d %lld.%06ld %u\n",
|
len = (unsigned int)snprintf(tbuf, sizeof(tbuf), "%d %lld.%09ld %u\n",
|
||||||
idx, (long long)delay.tv_sec, delay.tv_usec, len);
|
idx, (long long)delay.tv_sec, delay.tv_nsec, len);
|
||||||
if (len >= sizeof(tbuf)) {
|
if (len >= sizeof(tbuf)) {
|
||||||
/* Not actually possible due to the size of tbuf[]. */
|
/* Not actually possible due to the size of tbuf[]. */
|
||||||
errstr = strerror(EOVERFLOW);
|
errstr = strerror(EOVERFLOW);
|
||||||
@@ -1098,7 +1097,7 @@ sudoers_io_log(const char *buf, unsigned int len, int idx)
|
|||||||
|
|
||||||
done:
|
done:
|
||||||
last_time.tv_sec = now.tv_sec;
|
last_time.tv_sec = now.tv_sec;
|
||||||
last_time.tv_usec = now.tv_usec;
|
last_time.tv_nsec = now.tv_nsec;
|
||||||
|
|
||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
if (errstr != NULL && !warned) {
|
if (errstr != NULL && !warned) {
|
||||||
@@ -1149,14 +1148,14 @@ sudoers_io_log_stderr(const char *buf, unsigned int len)
|
|||||||
static int
|
static int
|
||||||
sudoers_io_change_winsize(unsigned int lines, unsigned int cols)
|
sudoers_io_change_winsize(unsigned int lines, unsigned int cols)
|
||||||
{
|
{
|
||||||
struct timeval now, delay;
|
struct timespec now, delay;
|
||||||
unsigned int len;
|
unsigned int len;
|
||||||
char tbuf[1024];
|
char tbuf[1024];
|
||||||
const char *errstr = NULL;
|
const char *errstr = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
debug_decl(sudoers_io_change_winsize, SUDOERS_DEBUG_PLUGIN)
|
debug_decl(sudoers_io_change_winsize, SUDOERS_DEBUG_PLUGIN)
|
||||||
|
|
||||||
if (gettimeofday(&now, NULL) == -1) {
|
if (sudo_gettime_awake(&now) == -1) {
|
||||||
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO,
|
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO,
|
||||||
"%s: unable to get time of day", __func__);
|
"%s: unable to get time of day", __func__);
|
||||||
errstr = strerror(errno);
|
errstr = strerror(errno);
|
||||||
@@ -1164,9 +1163,9 @@ sudoers_io_change_winsize(unsigned int lines, unsigned int cols)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Write window change event to the timing file. */
|
/* Write window change event to the timing file. */
|
||||||
sudo_timevalsub(&now, &last_time, &delay);
|
sudo_timespecsub(&now, &last_time, &delay);
|
||||||
len = (unsigned int)snprintf(tbuf, sizeof(tbuf), "%d %lld.%06ld %u %u\n",
|
len = (unsigned int)snprintf(tbuf, sizeof(tbuf), "%d %lld.%09ld %u %u\n",
|
||||||
IOFD_TIMING, (long long)delay.tv_sec, delay.tv_usec, lines, cols);
|
IOFD_TIMING, (long long)delay.tv_sec, delay.tv_nsec, lines, cols);
|
||||||
if (len >= sizeof(tbuf)) {
|
if (len >= sizeof(tbuf)) {
|
||||||
/* Not actually possible due to the size of tbuf[]. */
|
/* Not actually possible due to the size of tbuf[]. */
|
||||||
errstr = strerror(EOVERFLOW);
|
errstr = strerror(EOVERFLOW);
|
||||||
@@ -1181,7 +1180,7 @@ sudoers_io_change_winsize(unsigned int lines, unsigned int cols)
|
|||||||
|
|
||||||
done:
|
done:
|
||||||
last_time.tv_sec = now.tv_sec;
|
last_time.tv_sec = now.tv_sec;
|
||||||
last_time.tv_usec = now.tv_usec;
|
last_time.tv_nsec = now.tv_nsec;
|
||||||
|
|
||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
if (errstr != NULL && !warned) {
|
if (errstr != NULL && !warned) {
|
||||||
|
Reference in New Issue
Block a user