2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-22 09:57:41 +00:00

Move read_timing_record() into libsudo_iolog

This commit is contained in:
Todd C. Miller 2019-10-24 20:04:32 -06:00
parent 0ab2d8299b
commit b58ecb7e6d
5 changed files with 40 additions and 85 deletions

View File

@ -109,9 +109,10 @@ char *expand_iolog_path(const char *prefix, const char *dir, const char *file, c
/* XXX - prefix these */ /* XXX - prefix these */
bool parse_timing(const char *line, struct timing_closure *timing); bool parse_timing(const char *line, struct timing_closure *timing);
char *parse_delay(const char *cp, struct timespec *delay, const char *decimal_point); char *parse_delay(const char *cp, struct timespec *delay, const char *decimal_point);
int read_timing_record(struct iolog_file *iol, struct timing_closure *timing);
struct iolog_info *parse_logfile(FILE *fp, const char *iolog_dir); struct iolog_info *parse_logfile(FILE *fp, const char *iolog_dir);
void free_iolog_info(struct iolog_info *li);
void adjust_delay(struct timespec *delay, struct timespec *max_delay, double scale_factor); void adjust_delay(struct timespec *delay, struct timespec *max_delay, double scale_factor);
void free_iolog_info(struct iolog_info *li);
/* iolog_fileio.c */ /* iolog_fileio.c */
struct passwd; struct passwd;

View File

@ -362,6 +362,36 @@ bad:
debug_return_bool(false); debug_return_bool(false);
} }
/*
* Read the next record from the timing file.
* Return 0 on success, 1 on EOF and -1 on error.
*/
int
read_timing_record(struct iolog_file *iol, struct timing_closure *timing)
{
char line[LINE_MAX];
const char *errstr;
debug_decl(read_timing_record, SUDO_DEBUG_UTIL)
/* Read next record from timing file. */
if (iolog_gets(iol, line, sizeof(line), &errstr) == NULL) {
/* EOF or error reading timing file, we are done. */
if (iolog_eof(iol))
debug_return_int(1);
sudo_warnx(U_("error reading timing file: %s"), errstr);
debug_return_int(-1);
}
/* Parse timing file record. */
line[strcspn(line, "\n")] = '\0';
if (!parse_timing(line, timing)) {
sudo_warnx(U_("invalid timing file line: %s"), line);
debug_return_int(-1);
}
debug_return_int(0);
}
void void
free_iolog_info(struct iolog_info *li) free_iolog_info(struct iolog_info *li)
{ {

View File

@ -617,38 +617,6 @@ iolog_init(AcceptMessage *msg, struct connection_closure *closure)
debug_return_bool(true); debug_return_bool(true);
} }
/*
* Read the next record from the timing file.
* Return 0 on success, 1 on EOF and -1 on error.
*/
static int
read_timing_record(struct iolog_file *iol, struct timing_closure *timing)
{
char line[LINE_MAX];
const char *errstr;
debug_decl(read_timing_record, SUDO_DEBUG_UTIL)
/* Read next record from timing file. */
if (iolog_gets(iol, line, sizeof(line), &errstr) == NULL) {
/* EOF or error reading timing file, we are done. */
if (iolog_eof(iol))
debug_return_int(1); /* EOF */
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"error reading timing file: %s", errstr);
debug_return_int(-1);
}
/* Parse timing file record. */
line[strcspn(line, "\n")] = '\0';
if (!parse_timing(line, timing)) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO,
"invalid timing file line: %s", line);
debug_return_int(-1);
}
debug_return_int(0);
}
/* /*
* Copy len bytes from src to dst. * Copy len bytes from src to dst.
*/ */

View File

@ -166,37 +166,6 @@ client_closure_free(struct client_closure *closure)
debug_return; debug_return;
} }
/*
* Read the next record from the timing file.
* Return 0 on success, 1 on EOF and -1 on error.
* TODO: share with logsrvd
*/
int
read_timing_record(struct iolog_file *iol, struct timing_closure *timing)
{
char line[LINE_MAX];
const char *errstr;
debug_decl(read_timing_record, SUDO_DEBUG_UTIL)
/* Read next record from timing file. */
if (iolog_gets(iol, line, sizeof(line), &errstr) == NULL) {
/* EOF or error reading timing file, we are done. */
if (iolog_eof(iol))
debug_return_int(1);
sudo_warnx(U_("error reading timing file: %s"), errstr);
debug_return_int(-1);
}
/* Parse timing file record. */
line[strcspn(line, "\n")] = '\0';
if (!parse_timing(line, timing)) {
sudo_warnx(U_("invalid timing file line: %s"), line);
debug_return_int(-1);
}
debug_return_int(0);
}
/* /*
* Read the next I/O buffer as described by closure->timing. * Read the next I/O buffer as described by closure->timing.
*/ */

View File

@ -727,29 +727,16 @@ restore_terminal_size(void)
* Read the next record from the timing file and schedule a delay * Read the next record from the timing file and schedule a delay
* event with the specified timeout. * event with the specified timeout.
* Return 0 on success, 1 on EOF and -1 on error. * Return 0 on success, 1 on EOF and -1 on error.
* XXX - duplicated in sendlog
*/ */
static int static int
read_timing_record(struct replay_closure *closure) get_timing_record(struct replay_closure *closure)
{ {
struct timing_closure *timing = &closure->timing; struct timing_closure *timing = &closure->timing;
char line[LINE_MAX]; int ret;
const char *errstr; debug_decl(get_timing_record, SUDO_DEBUG_UTIL)
debug_decl(read_timing_record, SUDO_DEBUG_UTIL)
/* Read next record from timing file. */ if ((ret = read_timing_record(&iolog_files[IOFD_TIMING], timing)) != 0)
if (iolog_gets(&iolog_files[IOFD_TIMING], line, sizeof(line), &errstr) == NULL) { debug_return_int(ret);
/* EOF or error reading timing file, we are done. */
if (iolog_eof(&iolog_files[IOFD_TIMING]))
debug_return_int(1);
sudo_fatalx(U_("error reading timing file: %s"), errstr);
debug_return_int(-1);
}
/* Parse timing file record. */
line[strcspn(line, "\n")] = '\0';
if (!parse_timing(line, timing))
sudo_fatalx(U_("invalid timing file line: %s"), line);
/* Record number bytes to read. */ /* Record number bytes to read. */
if (timing->event != IO_EVENT_WINSIZE && if (timing->event != IO_EVENT_WINSIZE &&
@ -780,7 +767,7 @@ next_timing_record(struct replay_closure *closure)
debug_decl(next_timing_record, SUDO_DEBUG_UTIL) debug_decl(next_timing_record, SUDO_DEBUG_UTIL)
again: again:
switch (read_timing_record(closure)) { switch (get_timing_record(closure)) {
case 0: case 0:
/* success */ /* success */
if (closure->timing.event == IO_EVENT_SUSPEND && if (closure->timing.event == IO_EVENT_SUSPEND &&
@ -1030,7 +1017,7 @@ replay_session(int iolog_dir_fd, const char *iolog_dir,
/* Allocate the delay closure and read the first timing record. */ /* Allocate the delay closure and read the first timing record. */
closure = replay_closure_alloc(iolog_dir_fd, iolog_dir, max_delay, decimal, closure = replay_closure_alloc(iolog_dir_fd, iolog_dir, max_delay, decimal,
interactive, suspend_wait); interactive, suspend_wait);
if (read_timing_record(closure) != 0) { if (get_timing_record(closure) != 0) {
ret = 1; ret = 1;
goto done; goto done;
} }
@ -1121,7 +1108,7 @@ write_output(int fd, int what, void *v)
if (iobuf->off == iobuf->len) { if (iobuf->off == iobuf->len) {
/* Write complete, go to next timing entry if possible. */ /* Write complete, go to next timing entry if possible. */
switch (read_timing_record(closure)) { switch (get_timing_record(closure)) {
case 0: case 0:
/* success */ /* success */
break; break;