Add iolog_ prefix to exported functions in iolog_util.c
This commit is contained in:
@@ -106,13 +106,12 @@ struct iolog_path_escape {
|
|||||||
char *expand_iolog_path(const char *prefix, const char *dir, const char *file, char **slashp, const struct iolog_path_escape *escapes, void *closure);
|
char *expand_iolog_path(const char *prefix, const char *dir, const char *file, char **slashp, const struct iolog_path_escape *escapes, void *closure);
|
||||||
|
|
||||||
/* iolog_util.c */
|
/* iolog_util.c */
|
||||||
/* XXX - prefix these */
|
bool iolog_parse_timing(const char *line, struct timing_closure *timing);
|
||||||
bool parse_timing(const char *line, struct timing_closure *timing);
|
char *iolog_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 iolog_read_timing_record(struct iolog_file *iol, struct timing_closure *timing);
|
||||||
int read_timing_record(struct iolog_file *iol, struct timing_closure *timing);
|
struct iolog_info *iolog_parse_loginfo(FILE *fp, const char *iolog_dir);
|
||||||
struct iolog_info *parse_logfile(FILE *fp, const char *iolog_dir);
|
void iolog_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 iolog_free_loginfo(struct iolog_info *li);
|
||||||
void free_iolog_info(struct iolog_info *li);
|
|
||||||
|
|
||||||
/* iolog_fileio.c */
|
/* iolog_fileio.c */
|
||||||
struct passwd;
|
struct passwd;
|
||||||
|
@@ -61,16 +61,16 @@
|
|||||||
static int timing_event_adj;
|
static int timing_event_adj;
|
||||||
|
|
||||||
struct iolog_info *
|
struct iolog_info *
|
||||||
parse_logfile(FILE *fp, const char *logfile)
|
iolog_parse_loginfo(FILE *fp, const char *logfile)
|
||||||
{
|
{
|
||||||
char *buf = NULL, *cp, *ep;
|
char *buf = NULL, *cp, *ep;
|
||||||
const char *errstr;
|
const char *errstr;
|
||||||
size_t bufsize = 0, cwdsize = 0, cmdsize = 0;
|
size_t bufsize = 0, cwdsize = 0, cmdsize = 0;
|
||||||
struct iolog_info *li = NULL;
|
struct iolog_info *li = NULL;
|
||||||
debug_decl(parse_logfile, SUDO_DEBUG_UTIL)
|
debug_decl(iolog_parse_loginfo, SUDO_DEBUG_UTIL)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ID file has three lines:
|
* Info file has three lines:
|
||||||
* 1) a log info line
|
* 1) a log info line
|
||||||
* 2) cwd
|
* 2) cwd
|
||||||
* 3) command with args
|
* 3) command with args
|
||||||
@@ -172,16 +172,16 @@ parse_logfile(FILE *fp, const char *logfile)
|
|||||||
|
|
||||||
bad:
|
bad:
|
||||||
free(buf);
|
free(buf);
|
||||||
free_iolog_info(li);
|
iolog_free_loginfo(li);
|
||||||
debug_return_ptr(NULL);
|
debug_return_ptr(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
adjust_delay(struct timespec *delay, struct timespec *max_delay,
|
iolog_adjust_delay(struct timespec *delay, struct timespec *max_delay,
|
||||||
double scale_factor)
|
double scale_factor)
|
||||||
{
|
{
|
||||||
double seconds;
|
double seconds;
|
||||||
debug_decl(adjust_delay, SUDO_DEBUG_UTIL)
|
debug_decl(iolog_adjust_delay, SUDO_DEBUG_UTIL)
|
||||||
|
|
||||||
if (scale_factor != 1.0) {
|
if (scale_factor != 1.0) {
|
||||||
/* Order is important: we don't want to double the remainder. */
|
/* Order is important: we don't want to double the remainder. */
|
||||||
@@ -212,13 +212,14 @@ adjust_delay(struct timespec *delay, struct timespec *max_delay,
|
|||||||
* in the C locale this may not match the current locale.
|
* in the C locale this may not match the current locale.
|
||||||
*/
|
*/
|
||||||
char *
|
char *
|
||||||
parse_delay(const char *cp, struct timespec *delay, const char *decimal_point)
|
iolog_parse_delay(const char *cp, struct timespec *delay,
|
||||||
|
const char *decimal_point)
|
||||||
{
|
{
|
||||||
char numbuf[(((sizeof(long long) * 8) + 2) / 3) + 2];
|
char numbuf[(((sizeof(long long) * 8) + 2) / 3) + 2];
|
||||||
const char *errstr, *ep;
|
const char *errstr, *ep;
|
||||||
long long llval;
|
long long llval;
|
||||||
size_t len;
|
size_t len;
|
||||||
debug_decl(parse_delay, SUDO_DEBUG_UTIL)
|
debug_decl(iolog_parse_delay, SUDO_DEBUG_UTIL)
|
||||||
|
|
||||||
/* Parse seconds (whole number portion). */
|
/* Parse seconds (whole number portion). */
|
||||||
for (ep = cp; isdigit((unsigned char)*ep); ep++)
|
for (ep = cp; isdigit((unsigned char)*ep); ep++)
|
||||||
@@ -295,11 +296,11 @@ parse_delay(const char *cp, struct timespec *delay, const char *decimal_point)
|
|||||||
* Returns true on success and false on failure.
|
* Returns true on success and false on failure.
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
parse_timing(const char *line, struct timing_closure *timing)
|
iolog_parse_timing(const char *line, struct timing_closure *timing)
|
||||||
{
|
{
|
||||||
unsigned long ulval;
|
unsigned long ulval;
|
||||||
char *cp, *ep;
|
char *cp, *ep;
|
||||||
debug_decl(parse_timing, SUDO_DEBUG_UTIL)
|
debug_decl(iolog_parse_timing, SUDO_DEBUG_UTIL)
|
||||||
|
|
||||||
/* Clear iolog descriptor. */
|
/* Clear iolog descriptor. */
|
||||||
timing->iol = NULL;
|
timing->iol = NULL;
|
||||||
@@ -319,7 +320,7 @@ parse_timing(const char *line, struct timing_closure *timing)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Parse delay, returns the next field or NULL on error. */
|
/* Parse delay, returns the next field or NULL on error. */
|
||||||
if ((cp = parse_delay(cp, &timing->delay, timing->decimal)) == NULL)
|
if ((cp = iolog_parse_delay(cp, &timing->delay, timing->decimal)) == NULL)
|
||||||
goto bad;
|
goto bad;
|
||||||
|
|
||||||
switch (timing->event) {
|
switch (timing->event) {
|
||||||
@@ -367,11 +368,11 @@ bad:
|
|||||||
* Return 0 on success, 1 on EOF and -1 on error.
|
* Return 0 on success, 1 on EOF and -1 on error.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
read_timing_record(struct iolog_file *iol, struct timing_closure *timing)
|
iolog_read_timing_record(struct iolog_file *iol, struct timing_closure *timing)
|
||||||
{
|
{
|
||||||
char line[LINE_MAX];
|
char line[LINE_MAX];
|
||||||
const char *errstr;
|
const char *errstr;
|
||||||
debug_decl(read_timing_record, SUDO_DEBUG_UTIL)
|
debug_decl(iolog_read_timing_record, SUDO_DEBUG_UTIL)
|
||||||
|
|
||||||
/* Read next record from timing file. */
|
/* Read next record from timing file. */
|
||||||
if (iolog_gets(iol, line, sizeof(line), &errstr) == NULL) {
|
if (iolog_gets(iol, line, sizeof(line), &errstr) == NULL) {
|
||||||
@@ -384,7 +385,7 @@ read_timing_record(struct iolog_file *iol, struct timing_closure *timing)
|
|||||||
|
|
||||||
/* Parse timing file record. */
|
/* Parse timing file record. */
|
||||||
line[strcspn(line, "\n")] = '\0';
|
line[strcspn(line, "\n")] = '\0';
|
||||||
if (!parse_timing(line, timing)) {
|
if (!iolog_parse_timing(line, timing)) {
|
||||||
sudo_warnx(U_("invalid timing file line: %s"), line);
|
sudo_warnx(U_("invalid timing file line: %s"), line);
|
||||||
debug_return_int(-1);
|
debug_return_int(-1);
|
||||||
}
|
}
|
||||||
@@ -393,7 +394,7 @@ read_timing_record(struct iolog_file *iol, struct timing_closure *timing)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
free_iolog_info(struct iolog_info *li)
|
iolog_free_loginfo(struct iolog_info *li)
|
||||||
{
|
{
|
||||||
if (li != NULL) {
|
if (li != NULL) {
|
||||||
free(li->cwd);
|
free(li->cwd);
|
||||||
|
@@ -53,7 +53,7 @@ static struct parse_delay_test {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Test parse_delay()
|
* Test iolog_parse_delay()
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
test_parse_delay(int *ntests, int *nerrors)
|
test_parse_delay(int *ntests, int *nerrors)
|
||||||
@@ -63,7 +63,7 @@ test_parse_delay(int *ntests, int *nerrors)
|
|||||||
for (i = 0; i < nitems(parse_delay_tests); i++) {
|
for (i = 0; i < nitems(parse_delay_tests); i++) {
|
||||||
struct timespec delay;
|
struct timespec delay;
|
||||||
struct parse_delay_test *test = &parse_delay_tests[i];
|
struct parse_delay_test *test = &parse_delay_tests[i];
|
||||||
char *cp = parse_delay(test->input, &delay, ".");
|
char *cp = iolog_parse_delay(test->input, &delay, ".");
|
||||||
if (cp == NULL) {
|
if (cp == NULL) {
|
||||||
sudo_warnx("%s:%u failed to parse delay: %s", __func__,
|
sudo_warnx("%s:%u failed to parse delay: %s", __func__,
|
||||||
i, test->input);
|
i, test->input);
|
||||||
@@ -110,7 +110,7 @@ static struct adjust_delay_test {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Test adjust_delay()
|
* Test iolog_adjust_delay()
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
test_adjust_delay(int *ntests, int *nerrors)
|
test_adjust_delay(int *ntests, int *nerrors)
|
||||||
@@ -120,8 +120,9 @@ test_adjust_delay(int *ntests, int *nerrors)
|
|||||||
for (i = 0; i < nitems(adjust_delay_tests); i++) {
|
for (i = 0; i < nitems(adjust_delay_tests); i++) {
|
||||||
struct adjust_delay_test *test = &adjust_delay_tests[i];
|
struct adjust_delay_test *test = &adjust_delay_tests[i];
|
||||||
|
|
||||||
adjust_delay(&test->in_delay, sudo_timespecisset(&test->max_delay) ?
|
iolog_adjust_delay(&test->in_delay,
|
||||||
&test->max_delay : NULL, test->scale_factor);
|
sudo_timespecisset(&test->max_delay) ? &test->max_delay : NULL,
|
||||||
|
test->scale_factor);
|
||||||
if (!sudo_timespeccmp(&test->in_delay, &test->out_delay, ==)) {
|
if (!sudo_timespeccmp(&test->in_delay, &test->out_delay, ==)) {
|
||||||
sudo_warnx("%s:%u want {%lld, %ld}, got {%lld, %ld}", __func__, i,
|
sudo_warnx("%s:%u want {%lld, %ld}, got {%lld, %ld}", __func__, i,
|
||||||
(long long)test->out_delay.tv_sec, test->out_delay.tv_nsec,
|
(long long)test->out_delay.tv_sec, test->out_delay.tv_nsec,
|
||||||
|
@@ -670,7 +670,7 @@ iolog_rewrite(const struct timespec *target, struct connection_closure *closure)
|
|||||||
/* TODO: use iolog_seekto with a callback? */
|
/* TODO: use iolog_seekto with a callback? */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
/* Read next record from timing file. */
|
/* Read next record from timing file. */
|
||||||
if (read_timing_record(&closure->iolog_files[IOFD_TIMING], &timing) != 0)
|
if (iolog_read_timing_record(&closure->iolog_files[IOFD_TIMING], &timing) != 0)
|
||||||
goto done;
|
goto done;
|
||||||
sudo_timespecadd(&timing.delay, &closure->elapsed_time,
|
sudo_timespecadd(&timing.delay, &closure->elapsed_time,
|
||||||
&closure->elapsed_time);
|
&closure->elapsed_time);
|
||||||
|
@@ -141,7 +141,7 @@ iolog_seekto(int iolog_dir_fd, const char *iolog_path,
|
|||||||
|
|
||||||
/* Parse timing file until we reach the target point. */
|
/* Parse timing file until we reach the target point. */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (read_timing_record(&iolog_files[IOFD_TIMING], &timing) != 0)
|
if (iolog_read_timing_record(&iolog_files[IOFD_TIMING], &timing) != 0)
|
||||||
goto bad;
|
goto bad;
|
||||||
sudo_timespecadd(&timing.delay, elapsed_time, elapsed_time);
|
sudo_timespecadd(&timing.delay, elapsed_time, elapsed_time);
|
||||||
if (timing.event < IOFD_TIMING) {
|
if (timing.event < IOFD_TIMING) {
|
||||||
|
@@ -622,7 +622,7 @@ fmt_next_iolog(struct client_closure *closure)
|
|||||||
|
|
||||||
/* TODO: fill write buffer with multiple messages */
|
/* TODO: fill write buffer with multiple messages */
|
||||||
again:
|
again:
|
||||||
switch (read_timing_record(&iolog_files[IOFD_TIMING], timing)) {
|
switch (iolog_read_timing_record(&iolog_files[IOFD_TIMING], timing)) {
|
||||||
case 0:
|
case 0:
|
||||||
/* OK */
|
/* OK */
|
||||||
break;
|
break;
|
||||||
@@ -1045,7 +1045,7 @@ iolog_seekto(int iolog_dir_fd, const char *iolog_path,
|
|||||||
|
|
||||||
/* Parse timing file until we reach the target point. */
|
/* Parse timing file until we reach the target point. */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (read_timing_record(&iolog_files[IOFD_TIMING], &timing) != 0)
|
if (iolog_read_timing_record(&iolog_files[IOFD_TIMING], &timing) != 0)
|
||||||
goto bad;
|
goto bad;
|
||||||
sudo_timespecadd(&timing.delay, elapsed_time, elapsed_time);
|
sudo_timespecadd(&timing.delay, elapsed_time, elapsed_time);
|
||||||
if (timing.event < IOFD_TIMING) {
|
if (timing.event < IOFD_TIMING) {
|
||||||
@@ -1223,7 +1223,7 @@ main(int argc, char *argv[])
|
|||||||
sudo_warn("%s/log", iolog_dir);
|
sudo_warn("%s/log", iolog_dir);
|
||||||
goto bad;
|
goto bad;
|
||||||
}
|
}
|
||||||
if ((log_info = parse_logfile(fp, iolog_dir)) == NULL)
|
if ((log_info = iolog_parse_loginfo(fp, iolog_dir)) == NULL)
|
||||||
goto bad;
|
goto bad;
|
||||||
|
|
||||||
/* Open the I/O log files and seek to restart point if there is one. */
|
/* Open the I/O log files and seek to restart point if there is one. */
|
||||||
|
@@ -95,7 +95,7 @@ validate_iolog_info(const char *logfile)
|
|||||||
sudo_warn("%s", logfile);
|
sudo_warn("%s", logfile);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
info = parse_logfile(fp, logfile);
|
info = iolog_parse_loginfo(fp, logfile);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
if (info == NULL)
|
if (info == NULL)
|
||||||
return false;
|
return false;
|
||||||
@@ -146,7 +146,7 @@ validate_iolog_info(const char *logfile)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
free_iolog_info(info);
|
iolog_free_loginfo(info);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -162,7 +162,7 @@ validate_timing(FILE *fp, int recno, int type, unsigned int p1, unsigned int p2)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
buf[strcspn(buf, "\n")] = '\0';
|
buf[strcspn(buf, "\n")] = '\0';
|
||||||
if (!parse_timing(buf, &timing)) {
|
if (!iolog_parse_timing(buf, &timing)) {
|
||||||
sudo_warnx("invalid timing file line: %s", buf);
|
sudo_warnx("invalid timing file line: %s", buf);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -366,7 +366,7 @@ main(int argc, char *argv[])
|
|||||||
fd = openat(iolog_dir_fd, "log", O_RDONLY, 0);
|
fd = openat(iolog_dir_fd, "log", O_RDONLY, 0);
|
||||||
if (fd == -1 || (fp = fdopen(fd, "r")) == NULL)
|
if (fd == -1 || (fp = fdopen(fd, "r")) == NULL)
|
||||||
sudo_fatal(U_("unable to open %s/%s"), iolog_dir, "log");
|
sudo_fatal(U_("unable to open %s/%s"), iolog_dir, "log");
|
||||||
if ((li = parse_logfile(fp, iolog_dir)) == NULL)
|
if ((li = iolog_parse_loginfo(fp, iolog_dir)) == NULL)
|
||||||
goto done;
|
goto done;
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
printf(_("Replaying sudo session: %s"), li->cmd);
|
printf(_("Replaying sudo session: %s"), li->cmd);
|
||||||
@@ -379,7 +379,7 @@ main(int argc, char *argv[])
|
|||||||
putchar('\n');
|
putchar('\n');
|
||||||
|
|
||||||
/* Done with parsed log file. */
|
/* Done with parsed log file. */
|
||||||
free_iolog_info(li);
|
iolog_free_loginfo(li);
|
||||||
li = NULL;
|
li = NULL;
|
||||||
|
|
||||||
/* Replay session corresponding to iolog_files[]. */
|
/* Replay session corresponding to iolog_files[]. */
|
||||||
@@ -735,7 +735,7 @@ get_timing_record(struct replay_closure *closure)
|
|||||||
int ret;
|
int ret;
|
||||||
debug_decl(get_timing_record, SUDO_DEBUG_UTIL)
|
debug_decl(get_timing_record, SUDO_DEBUG_UTIL)
|
||||||
|
|
||||||
if ((ret = read_timing_record(&iolog_files[IOFD_TIMING], timing)) != 0)
|
if ((ret = iolog_read_timing_record(&iolog_files[IOFD_TIMING], timing)) != 0)
|
||||||
debug_return_int(ret);
|
debug_return_int(ret);
|
||||||
|
|
||||||
/* Record number bytes to read. */
|
/* Record number bytes to read. */
|
||||||
@@ -748,7 +748,7 @@ get_timing_record(struct replay_closure *closure)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Adjust delay using speed factor and max_delay. */
|
/* Adjust delay using speed factor and max_delay. */
|
||||||
adjust_delay(&timing->delay, closure->max_delay, speed_factor);
|
iolog_adjust_delay(&timing->delay, closure->max_delay, speed_factor);
|
||||||
|
|
||||||
/* Schedule the delay event. */
|
/* Schedule the delay event. */
|
||||||
if (sudo_ev_add(closure->evbase, closure->delay_ev, &timing->delay, false) == -1)
|
if (sudo_ev_add(closure->evbase, closure->delay_ev, &timing->delay, false) == -1)
|
||||||
@@ -1319,7 +1319,7 @@ list_session(char *logfile, regex_t *re, const char *user, const char *tty)
|
|||||||
sudo_warn("%s", logfile);
|
sudo_warn("%s", logfile);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if ((li = parse_logfile(fp, logfile)) == NULL)
|
if ((li = iolog_parse_loginfo(fp, logfile)) == NULL)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
/* Match on search expression if there is one. */
|
/* Match on search expression if there is one. */
|
||||||
@@ -1356,7 +1356,7 @@ list_session(char *logfile, regex_t *re, const char *user, const char *tty)
|
|||||||
done:
|
done:
|
||||||
if (fp != NULL)
|
if (fp != NULL)
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
free_iolog_info(li);
|
iolog_free_loginfo(li);
|
||||||
debug_return_int(ret);
|
debug_return_int(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user