mirror of
https://github.com/sudo-project/sudo.git
synced 2025-08-22 01:49:11 +00:00
Rename buffer.c -> logsrv_util.c and add iolog_seekto()
This commit is contained in:
parent
b58ecb7e6d
commit
728ed2100b
4
MANIFEST
4
MANIFEST
@ -251,10 +251,10 @@ logsrvd/Makefile.in
|
||||
logsrvd/log_server.pb-c.c
|
||||
logsrvd/log_server.pb-c.h
|
||||
logsrvd/log_server.proto
|
||||
logsrvd/buffer.c
|
||||
logsrvd/buffer.h
|
||||
logsrvd/eventlog.c
|
||||
logsrvd/iolog_writer.c
|
||||
logsrvd/logsrv_util.c
|
||||
logsrvd/logsrv_util.h
|
||||
logsrvd/logsrvd.c
|
||||
logsrvd/logsrvd.h
|
||||
logsrvd/logsrvd_conf.c
|
||||
|
@ -927,7 +927,7 @@ iolog_write_info_file(int dfd, const char *parent, struct iolog_info *log_info,
|
||||
const char *
|
||||
iolog_fd_to_name(int iofd)
|
||||
{
|
||||
const char *ret = NULL;
|
||||
const char *ret;
|
||||
debug_decl(iolog_fd_to_name, SUDO_DEBUG_UTIL)
|
||||
|
||||
switch (iofd) {
|
||||
@ -950,6 +950,7 @@ iolog_fd_to_name(int iofd)
|
||||
ret = "timing";
|
||||
break;
|
||||
default:
|
||||
ret = "unknown";
|
||||
sudo_debug_printf(SUDO_DEBUG_ERROR, "%s: unexpected iofd %d",
|
||||
__func__, iofd);
|
||||
break;
|
||||
|
@ -107,10 +107,10 @@ SHELL = @SHELL@
|
||||
|
||||
PROGS = sudo_logsrvd sudo_sendlog
|
||||
|
||||
LOGSRVD_OBJS = log_server.pb-c.o buffer.o eventlog.o iolog_writer.o \
|
||||
LOGSRVD_OBJS = log_server.pb-c.o logsrv_util.o eventlog.o iolog_writer.o \
|
||||
logsrvd.o logsrvd_conf.o protobuf-c.o
|
||||
|
||||
SENDLOG_OBJS = log_server.pb-c.o buffer.o protobuf-c.o sendlog.o
|
||||
SENDLOG_OBJS = log_server.pb-c.o logsrv_util.o protobuf-c.o sendlog.o
|
||||
|
||||
IOBJS = $(LOGSRVD_OBJS:.o=.i) $(SENDLOG_OBJS:.o=.i)
|
||||
|
||||
@ -211,35 +211,21 @@ realclean: distclean
|
||||
cleandir: realclean
|
||||
|
||||
# Autogenerated dependencies, do not modify
|
||||
buffer.o: $(srcdir)/buffer.c $(incdir)/compat/stdbool.h \
|
||||
$(incdir)/sudo_compat.h $(incdir)/sudo_debug.h \
|
||||
$(incdir)/sudo_fatal.h $(incdir)/sudo_gettext.h \
|
||||
$(incdir)/sudo_queue.h $(incdir)/sudo_util.h $(srcdir)/buffer.h \
|
||||
$(top_builddir)/config.h
|
||||
$(CC) -c $(CPPFLAGS) $(CFLAGS) $(ASAN_CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(srcdir)/buffer.c
|
||||
buffer.i: $(srcdir)/buffer.c $(incdir)/compat/stdbool.h \
|
||||
$(incdir)/sudo_compat.h $(incdir)/sudo_debug.h \
|
||||
$(incdir)/sudo_fatal.h $(incdir)/sudo_gettext.h \
|
||||
$(incdir)/sudo_queue.h $(incdir)/sudo_util.h $(srcdir)/buffer.h \
|
||||
$(top_builddir)/config.h
|
||||
$(CC) -E -o $@ $(CPPFLAGS) $<
|
||||
buffer.plog: buffer.i
|
||||
rm -f $@; pvs-studio --cfg $(PVS_CFG) --sourcetree-root $(top_srcdir) --skip-cl-exe yes --source-file $(srcdir)/buffer.c --i-file $< --output-file $@
|
||||
eventlog.o: $(srcdir)/eventlog.c $(devdir)/log_server.pb-c.h \
|
||||
$(incdir)/compat/stdbool.h $(incdir)/sudo_compat.h \
|
||||
$(incdir)/sudo_debug.h $(incdir)/sudo_fatal.h \
|
||||
$(incdir)/sudo_gettext.h $(incdir)/sudo_iolog.h \
|
||||
$(incdir)/sudo_queue.h $(incdir)/sudo_util.h $(srcdir)/buffer.h \
|
||||
$(srcdir)/logsrvd.h $(srcdir)/protobuf-c/protobuf-c.h \
|
||||
$(top_builddir)/config.h
|
||||
$(incdir)/sudo_queue.h $(incdir)/sudo_util.h \
|
||||
$(srcdir)/logsrv_util.h $(srcdir)/logsrvd.h \
|
||||
$(srcdir)/protobuf-c/protobuf-c.h $(top_builddir)/config.h
|
||||
$(CC) -c $(CPPFLAGS) $(CFLAGS) $(ASAN_CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(srcdir)/eventlog.c
|
||||
eventlog.i: $(srcdir)/eventlog.c $(devdir)/log_server.pb-c.h \
|
||||
$(incdir)/compat/stdbool.h $(incdir)/sudo_compat.h \
|
||||
$(incdir)/sudo_debug.h $(incdir)/sudo_fatal.h \
|
||||
$(incdir)/sudo_gettext.h $(incdir)/sudo_iolog.h \
|
||||
$(incdir)/sudo_queue.h $(incdir)/sudo_util.h $(srcdir)/buffer.h \
|
||||
$(srcdir)/logsrvd.h $(srcdir)/protobuf-c/protobuf-c.h \
|
||||
$(top_builddir)/config.h
|
||||
$(incdir)/sudo_queue.h $(incdir)/sudo_util.h \
|
||||
$(srcdir)/logsrv_util.h $(srcdir)/logsrvd.h \
|
||||
$(srcdir)/protobuf-c/protobuf-c.h $(top_builddir)/config.h
|
||||
$(CC) -E -o $@ $(CPPFLAGS) $<
|
||||
eventlog.plog: eventlog.i
|
||||
rm -f $@; pvs-studio --cfg $(PVS_CFG) --sourcetree-root $(top_srcdir) --skip-cl-exe yes --source-file $(srcdir)/eventlog.c --i-file $< --output-file $@
|
||||
@ -247,14 +233,14 @@ iolog_writer.o: $(srcdir)/iolog_writer.c $(devdir)/log_server.pb-c.h \
|
||||
$(incdir)/compat/stdbool.h $(incdir)/sudo_compat.h \
|
||||
$(incdir)/sudo_debug.h $(incdir)/sudo_iolog.h \
|
||||
$(incdir)/sudo_queue.h $(incdir)/sudo_util.h \
|
||||
$(srcdir)/buffer.h $(srcdir)/logsrvd.h \
|
||||
$(srcdir)/logsrv_util.h $(srcdir)/logsrvd.h \
|
||||
$(srcdir)/protobuf-c/protobuf-c.h $(top_builddir)/config.h
|
||||
$(CC) -c $(CPPFLAGS) $(CFLAGS) $(ASAN_CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(srcdir)/iolog_writer.c
|
||||
iolog_writer.i: $(srcdir)/iolog_writer.c $(devdir)/log_server.pb-c.h \
|
||||
$(incdir)/compat/stdbool.h $(incdir)/sudo_compat.h \
|
||||
$(incdir)/sudo_debug.h $(incdir)/sudo_iolog.h \
|
||||
$(incdir)/sudo_queue.h $(incdir)/sudo_util.h \
|
||||
$(srcdir)/buffer.h $(srcdir)/logsrvd.h \
|
||||
$(srcdir)/logsrv_util.h $(srcdir)/logsrvd.h \
|
||||
$(srcdir)/protobuf-c/protobuf-c.h $(top_builddir)/config.h
|
||||
$(CC) -E -o $@ $(CPPFLAGS) $<
|
||||
iolog_writer.plog: iolog_writer.i
|
||||
@ -267,13 +253,29 @@ log_server.pb-c.i: $(srcdir)/log_server.pb-c.c $(devdir)/log_server.pb-c.h \
|
||||
$(CC) -E -o $@ $(CPPFLAGS) $<
|
||||
log_server.pb-c.plog: log_server.pb-c.i
|
||||
rm -f $@; pvs-studio --cfg $(PVS_CFG) --sourcetree-root $(top_srcdir) --skip-cl-exe yes --source-file $(srcdir)/log_server.pb-c.c --i-file $< --output-file $@
|
||||
logsrv_util.o: $(srcdir)/logsrv_util.c $(incdir)/compat/stdbool.h \
|
||||
$(incdir)/sudo_compat.h $(incdir)/sudo_debug.h \
|
||||
$(incdir)/sudo_fatal.h $(incdir)/sudo_gettext.h \
|
||||
$(incdir)/sudo_iolog.h $(incdir)/sudo_queue.h \
|
||||
$(incdir)/sudo_util.h $(srcdir)/logsrv_util.h \
|
||||
$(top_builddir)/config.h
|
||||
$(CC) -c $(CPPFLAGS) $(CFLAGS) $(ASAN_CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(srcdir)/logsrv_util.c
|
||||
logsrv_util.i: $(srcdir)/logsrv_util.c $(incdir)/compat/stdbool.h \
|
||||
$(incdir)/sudo_compat.h $(incdir)/sudo_debug.h \
|
||||
$(incdir)/sudo_fatal.h $(incdir)/sudo_gettext.h \
|
||||
$(incdir)/sudo_iolog.h $(incdir)/sudo_queue.h \
|
||||
$(incdir)/sudo_util.h $(srcdir)/logsrv_util.h \
|
||||
$(top_builddir)/config.h
|
||||
$(CC) -E -o $@ $(CPPFLAGS) $<
|
||||
logsrv_util.plog: logsrv_util.i
|
||||
rm -f $@; pvs-studio --cfg $(PVS_CFG) --sourcetree-root $(top_srcdir) --skip-cl-exe yes --source-file $(srcdir)/logsrv_util.c --i-file $< --output-file $@
|
||||
logsrvd.o: $(srcdir)/logsrvd.c $(devdir)/log_server.pb-c.h \
|
||||
$(incdir)/compat/getopt.h $(incdir)/compat/stdbool.h \
|
||||
$(incdir)/sudo_compat.h $(incdir)/sudo_conf.h \
|
||||
$(incdir)/sudo_debug.h $(incdir)/sudo_event.h \
|
||||
$(incdir)/sudo_fatal.h $(incdir)/sudo_gettext.h \
|
||||
$(incdir)/sudo_iolog.h $(incdir)/sudo_queue.h $(incdir)/sudo_rand.h \
|
||||
$(incdir)/sudo_util.h $(srcdir)/buffer.h $(srcdir)/logsrvd.h \
|
||||
$(incdir)/sudo_util.h $(srcdir)/logsrv_util.h $(srcdir)/logsrvd.h \
|
||||
$(srcdir)/protobuf-c/protobuf-c.h $(top_builddir)/config.h \
|
||||
$(top_builddir)/pathnames.h
|
||||
$(CC) -c $(CPPFLAGS) $(CFLAGS) $(ASAN_CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(srcdir)/logsrvd.c
|
||||
@ -283,7 +285,7 @@ logsrvd.i: $(srcdir)/logsrvd.c $(devdir)/log_server.pb-c.h \
|
||||
$(incdir)/sudo_debug.h $(incdir)/sudo_event.h \
|
||||
$(incdir)/sudo_fatal.h $(incdir)/sudo_gettext.h \
|
||||
$(incdir)/sudo_iolog.h $(incdir)/sudo_queue.h $(incdir)/sudo_rand.h \
|
||||
$(incdir)/sudo_util.h $(srcdir)/buffer.h $(srcdir)/logsrvd.h \
|
||||
$(incdir)/sudo_util.h $(srcdir)/logsrv_util.h $(srcdir)/logsrvd.h \
|
||||
$(srcdir)/protobuf-c/protobuf-c.h $(top_builddir)/config.h \
|
||||
$(top_builddir)/pathnames.h
|
||||
$(CC) -E -o $@ $(CPPFLAGS) $<
|
||||
@ -294,18 +296,18 @@ logsrvd_conf.o: $(srcdir)/logsrvd_conf.c $(devdir)/log_server.pb-c.h \
|
||||
$(incdir)/sudo_compat.h $(incdir)/sudo_debug.h \
|
||||
$(incdir)/sudo_fatal.h $(incdir)/sudo_gettext.h \
|
||||
$(incdir)/sudo_iolog.h $(incdir)/sudo_queue.h \
|
||||
$(incdir)/sudo_util.h $(srcdir)/buffer.h $(srcdir)/logsrvd.h \
|
||||
$(srcdir)/protobuf-c/protobuf-c.h $(top_builddir)/config.h \
|
||||
$(top_builddir)/pathnames.h
|
||||
$(incdir)/sudo_util.h $(srcdir)/logsrv_util.h \
|
||||
$(srcdir)/logsrvd.h $(srcdir)/protobuf-c/protobuf-c.h \
|
||||
$(top_builddir)/config.h $(top_builddir)/pathnames.h
|
||||
$(CC) -c $(CPPFLAGS) $(CFLAGS) $(ASAN_CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(srcdir)/logsrvd_conf.c
|
||||
logsrvd_conf.i: $(srcdir)/logsrvd_conf.c $(devdir)/log_server.pb-c.h \
|
||||
$(incdir)/compat/getaddrinfo.h $(incdir)/compat/stdbool.h \
|
||||
$(incdir)/sudo_compat.h $(incdir)/sudo_debug.h \
|
||||
$(incdir)/sudo_fatal.h $(incdir)/sudo_gettext.h \
|
||||
$(incdir)/sudo_iolog.h $(incdir)/sudo_queue.h \
|
||||
$(incdir)/sudo_util.h $(srcdir)/buffer.h $(srcdir)/logsrvd.h \
|
||||
$(srcdir)/protobuf-c/protobuf-c.h $(top_builddir)/config.h \
|
||||
$(top_builddir)/pathnames.h
|
||||
$(incdir)/sudo_util.h $(srcdir)/logsrv_util.h \
|
||||
$(srcdir)/logsrvd.h $(srcdir)/protobuf-c/protobuf-c.h \
|
||||
$(top_builddir)/config.h $(top_builddir)/pathnames.h
|
||||
$(CC) -E -o $@ $(CPPFLAGS) $<
|
||||
logsrvd_conf.plog: logsrvd_conf.i
|
||||
rm -f $@; pvs-studio --cfg $(PVS_CFG) --sourcetree-root $(top_srcdir) --skip-cl-exe yes --source-file $(srcdir)/logsrvd_conf.c --i-file $< --output-file $@
|
||||
@ -321,7 +323,7 @@ sendlog.o: $(srcdir)/sendlog.c $(devdir)/log_server.pb-c.h \
|
||||
$(incdir)/sudo_conf.h $(incdir)/sudo_debug.h $(incdir)/sudo_event.h \
|
||||
$(incdir)/sudo_fatal.h $(incdir)/sudo_gettext.h \
|
||||
$(incdir)/sudo_iolog.h $(incdir)/sudo_queue.h $(incdir)/sudo_util.h \
|
||||
$(srcdir)/buffer.h $(srcdir)/protobuf-c/protobuf-c.h \
|
||||
$(srcdir)/logsrv_util.h $(srcdir)/protobuf-c/protobuf-c.h \
|
||||
$(srcdir)/sendlog.h $(top_builddir)/config.h
|
||||
$(CC) -c $(CPPFLAGS) $(CFLAGS) $(ASAN_CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(srcdir)/sendlog.c
|
||||
sendlog.i: $(srcdir)/sendlog.c $(devdir)/log_server.pb-c.h \
|
||||
@ -330,7 +332,7 @@ sendlog.i: $(srcdir)/sendlog.c $(devdir)/log_server.pb-c.h \
|
||||
$(incdir)/sudo_conf.h $(incdir)/sudo_debug.h $(incdir)/sudo_event.h \
|
||||
$(incdir)/sudo_fatal.h $(incdir)/sudo_gettext.h \
|
||||
$(incdir)/sudo_iolog.h $(incdir)/sudo_queue.h $(incdir)/sudo_util.h \
|
||||
$(srcdir)/buffer.h $(srcdir)/protobuf-c/protobuf-c.h \
|
||||
$(srcdir)/logsrv_util.h $(srcdir)/protobuf-c/protobuf-c.h \
|
||||
$(srcdir)/sendlog.h $(top_builddir)/config.h
|
||||
$(CC) -E -o $@ $(CPPFLAGS) $<
|
||||
sendlog.plog: sendlog.i
|
||||
|
@ -662,6 +662,7 @@ iolog_rewrite(const struct timespec *target, struct connection_closure *closure)
|
||||
debug_decl(iolog_rewrite, SUDO_DEBUG_UTIL)
|
||||
|
||||
/* Parse timing file until we reach the target point. */
|
||||
/* TODO: use iolog_seekto with a callback? */
|
||||
for (;;) {
|
||||
/* Read next record from timing file. */
|
||||
if (read_timing_record(&closure->iolog_files[IOFD_TIMING], &timing) != 0)
|
||||
@ -803,9 +804,6 @@ bool
|
||||
iolog_restart(RestartMessage *msg, struct connection_closure *closure)
|
||||
{
|
||||
struct timespec target;
|
||||
struct timing_closure timing;
|
||||
bool compressed = false;
|
||||
off_t pos;
|
||||
int iofd;
|
||||
debug_decl(iolog_restart, SUDO_DEBUG_UTIL)
|
||||
|
||||
@ -828,68 +826,21 @@ iolog_restart(RestartMessage *msg, struct connection_closure *closure)
|
||||
}
|
||||
|
||||
/* Open existing I/O log files. */
|
||||
if (!iolog_open_all(closure->iolog_dir_fd, closure->details.iolog_path,
|
||||
closure->iolog_files, "r+"))
|
||||
goto bad;
|
||||
|
||||
/* Compressed logs don't support random access, so rewrite them. */
|
||||
for (iofd = 0; iofd < IOFD_MAX; iofd++) {
|
||||
closure->iolog_files[iofd].enabled = true;
|
||||
if (!iolog_open(&closure->iolog_files[iofd], closure->iolog_dir_fd,
|
||||
iofd, "r+")) {
|
||||
if (errno != ENOENT) {
|
||||
sudo_debug_printf(
|
||||
SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO,
|
||||
"unable to open %s/%s", closure->details.iolog_path,
|
||||
iolog_fd_to_name(iofd));
|
||||
goto bad;
|
||||
}
|
||||
}
|
||||
if (closure->iolog_files[iofd].compressed)
|
||||
compressed = true;
|
||||
}
|
||||
if (!closure->iolog_files[IOFD_TIMING].enabled) {
|
||||
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
|
||||
"missing timing file in %s", closure->details.iolog_path);
|
||||
goto bad;
|
||||
}
|
||||
if (compressed) {
|
||||
/* Compressed logs don't support random access, need to rewrite them. */
|
||||
debug_return_bool(iolog_rewrite(&target, closure));
|
||||
}
|
||||
|
||||
/* Parse timing file until we reach the target point. */
|
||||
/* XXX - split up */
|
||||
for (;;) {
|
||||
if (read_timing_record(&closure->iolog_files[IOFD_TIMING], &timing) != 0)
|
||||
if (!iolog_seekto(closure->iolog_dir_fd, closure->details.iolog_path,
|
||||
closure->iolog_files, &closure->elapsed_time, &target))
|
||||
goto bad;
|
||||
sudo_timespecadd(&timing.delay, &closure->elapsed_time,
|
||||
&closure->elapsed_time);
|
||||
if (timing.event < IOFD_TIMING) {
|
||||
if (!closure->iolog_files[timing.event].enabled) {
|
||||
/* Missing log file. */
|
||||
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
|
||||
"iofd %d referenced but not open", timing.event);
|
||||
goto bad;
|
||||
}
|
||||
pos = iolog_seek(&closure->iolog_files[timing.event],
|
||||
timing.u.nbytes, SEEK_CUR);
|
||||
if (pos == -1) {
|
||||
sudo_debug_printf(
|
||||
SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO,
|
||||
"seek(%d, %lld, SEEK_CUR", timing.event,
|
||||
(long long)timing.u.nbytes);
|
||||
goto bad;
|
||||
}
|
||||
}
|
||||
if (sudo_timespeccmp(&closure->elapsed_time, &target, >=)) {
|
||||
if (sudo_timespeccmp(&closure->elapsed_time, &target, ==))
|
||||
break;
|
||||
|
||||
/* Mismatch between resume point and stored log. */
|
||||
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
|
||||
"resume point mismatch, target [%lld, %ld], have [%lld, %ld]",
|
||||
(long long)target.tv_sec, target.tv_nsec,
|
||||
(long long)closure->elapsed_time.tv_sec,
|
||||
closure->elapsed_time.tv_nsec);
|
||||
goto bad;
|
||||
}
|
||||
}
|
||||
/* Must seek or flush before switching from read -> write. */
|
||||
if (iolog_seek(&closure->iolog_files[IOFD_TIMING], 0, SEEK_CUR) == -1) {
|
||||
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO,
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <errno.h>
|
||||
#ifdef HAVE_STDBOOL_H
|
||||
# include <stdbool.h>
|
||||
#else
|
||||
@ -31,6 +32,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "sudo_gettext.h" /* must be included before sudo_compat.h */
|
||||
@ -38,7 +40,8 @@
|
||||
#include "sudo_debug.h"
|
||||
#include "sudo_util.h"
|
||||
#include "sudo_fatal.h"
|
||||
#include "buffer.h"
|
||||
#include "sudo_iolog.h"
|
||||
#include "logsrv_util.h"
|
||||
|
||||
/*
|
||||
* Round 32-bit unsigned length to the next highest power of two.
|
||||
@ -94,3 +97,80 @@ expand_buf(struct connection_buffer *buf, unsigned int needed)
|
||||
|
||||
debug_return_bool(true);
|
||||
}
|
||||
|
||||
/*
|
||||
* Open any I/O log files that are present.
|
||||
* The timing file must always exist.
|
||||
*/
|
||||
bool
|
||||
iolog_open_all(int dfd, const char *iolog_dir, struct iolog_file *iolog_files,
|
||||
const char *mode)
|
||||
{
|
||||
int iofd;
|
||||
debug_decl(iolog_open_all, SUDO_DEBUG_UTIL)
|
||||
|
||||
for (iofd = 0; iofd < IOFD_MAX; iofd++) {
|
||||
iolog_files[iofd].enabled = true;
|
||||
if (!iolog_open(&iolog_files[iofd], dfd, iofd, mode)) {
|
||||
if (errno != ENOENT) {
|
||||
sudo_warn(U_("unable to open %s/%s"), iolog_dir,
|
||||
iolog_fd_to_name(iofd));
|
||||
debug_return_bool(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!iolog_files[IOFD_TIMING].enabled) {
|
||||
sudo_warn(U_("unable to open %s/%s"), iolog_dir,
|
||||
iolog_fd_to_name(IOFD_TIMING));
|
||||
debug_return_bool(false);
|
||||
}
|
||||
debug_return_bool(true);
|
||||
}
|
||||
|
||||
/*
|
||||
* Seek to the specified point in time in the I/O logs.
|
||||
*/
|
||||
bool
|
||||
iolog_seekto(int iolog_dir_fd, const char *iolog_path,
|
||||
struct iolog_file *iolog_files, struct timespec *elapsed_time,
|
||||
const struct timespec *target)
|
||||
{
|
||||
struct timing_closure timing;
|
||||
off_t pos;
|
||||
debug_decl(iolog_seekto, SUDO_DEBUG_UTIL)
|
||||
|
||||
/* Parse timing file until we reach the target point. */
|
||||
for (;;) {
|
||||
if (read_timing_record(&iolog_files[IOFD_TIMING], &timing) != 0)
|
||||
goto bad;
|
||||
sudo_timespecadd(&timing.delay, elapsed_time, elapsed_time);
|
||||
if (timing.event < IOFD_TIMING) {
|
||||
if (!iolog_files[timing.event].enabled) {
|
||||
/* Missing log file. */
|
||||
sudo_warn(U_("missing I/O log file %s/%s"), iolog_path,
|
||||
iolog_fd_to_name(timing.event));
|
||||
goto bad;
|
||||
}
|
||||
pos = iolog_seek(&iolog_files[timing.event], timing.u.nbytes,
|
||||
SEEK_CUR);
|
||||
if (pos == -1) {
|
||||
sudo_warn(U_("%s/%s: unable to seek forward %zu"), iolog_path,
|
||||
iolog_fd_to_name(timing.event), timing.u.nbytes);
|
||||
goto bad;
|
||||
}
|
||||
}
|
||||
if (sudo_timespeccmp(elapsed_time, target, >=)) {
|
||||
if (sudo_timespeccmp(elapsed_time, target, ==))
|
||||
break;
|
||||
|
||||
/* Mismatch between resume point and stored log. */
|
||||
sudo_warnx(U_("unable to find resume point [%lld, %ld] in %s/%s"),
|
||||
(long long)target->tv_sec, target->tv_nsec, iolog_path,
|
||||
"timing");
|
||||
goto bad;
|
||||
}
|
||||
}
|
||||
debug_return_bool(true);
|
||||
bad:
|
||||
debug_return_bool(false);
|
||||
}
|
@ -14,8 +14,11 @@
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef SUDO_BUFFER_H
|
||||
#define SUDO_BUFFER_H
|
||||
#ifndef SUDO_LOGSRV_UTIL_H
|
||||
#define SUDO_LOGSRV_UTIL_H
|
||||
|
||||
/* Default port to listen on */
|
||||
#define DEFAULT_PORT_STR "30344"
|
||||
|
||||
/* Maximum message size (2Mb) */
|
||||
#define MESSAGE_SIZE_MAX (2 * 1024 * 1024)
|
||||
@ -27,8 +30,12 @@ struct connection_buffer {
|
||||
unsigned int off;
|
||||
};
|
||||
|
||||
/* buffer.c */
|
||||
/* logsrv_util.c */
|
||||
struct iolog_file;
|
||||
bool expand_buf(struct connection_buffer *buf, unsigned int needed);
|
||||
bool iolog_open_all(int dfd, const char *iolog_dir, struct iolog_file *iolog_files, const char *mode);
|
||||
bool iolog_seekto(int iolog_dir_fd, const char *iolog_path, struct iolog_file *iolog_files, struct timespec *elapsed_time, const struct timespec *target);
|
||||
unsigned int bufsize_roundup(unsigned int len);
|
||||
|
||||
#endif /* SUDO_BUFFER_H */
|
||||
|
||||
#endif /* SUDO_LOGSRV_UTIL_H */
|
@ -21,11 +21,9 @@
|
||||
# error protobuf-c version 1.30 or higher required
|
||||
#endif
|
||||
|
||||
#include "buffer.h"
|
||||
#include "logsrv_util.h"
|
||||
|
||||
/* Default listen address (port 30344 on all interfaces). */
|
||||
/* XXX: share with client */
|
||||
#define DEFAULT_PORT_STR "30344"
|
||||
#define DEFAULT_LISTEN_ADDR "*:" DEFAULT_PORT_STR
|
||||
|
||||
/* How often to send an ACK to the client (commit point) in seconds */
|
||||
|
@ -1010,6 +1010,7 @@ bad:
|
||||
debug_return_bool(false);
|
||||
}
|
||||
|
||||
#if 0
|
||||
/*
|
||||
* Open the I/O log files and seek to the specified point in time.
|
||||
* TODO: share with logsrvd restart code
|
||||
@ -1079,34 +1080,7 @@ iolog_seekto(int iolog_dir_fd, const char *iolog_path,
|
||||
bad:
|
||||
debug_return_bool(false);
|
||||
}
|
||||
|
||||
/*
|
||||
* Open any I/O log files that are present.
|
||||
* The timing file must always exist.
|
||||
*/
|
||||
static bool
|
||||
iolog_open_all(int dfd, const char *iolog_dir)
|
||||
{
|
||||
int iofd;
|
||||
debug_decl(iolog_open_all, SUDO_DEBUG_UTIL)
|
||||
|
||||
for (iofd = 0; iofd < IOFD_MAX; iofd++) {
|
||||
iolog_files[iofd].enabled = true;
|
||||
if (!iolog_open(&iolog_files[iofd], dfd, iofd, "r")) {
|
||||
if (errno != ENOENT) {
|
||||
sudo_warn(U_("unable to open %s/%s"), iolog_dir,
|
||||
iolog_fd_to_name(iofd));
|
||||
debug_return_bool(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!iolog_files[IOFD_TIMING].enabled) {
|
||||
sudo_warn(U_("unable to open %s/%s"), iolog_dir,
|
||||
iolog_fd_to_name(IOFD_TIMING));
|
||||
debug_return_bool(false);
|
||||
}
|
||||
debug_return_bool(true);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Parse a timespec on the command line of the form
|
||||
@ -1170,6 +1144,7 @@ main(int argc, char *argv[])
|
||||
struct timespec restart = { 0, 0 };
|
||||
struct timespec elapsed = { 0, 0 };
|
||||
const char *iolog_id = NULL;
|
||||
const char *open_mode = "r";
|
||||
int ch, sock, iolog_dir_fd, fd;
|
||||
FILE *fp;
|
||||
debug_decl_vars(main, SUDO_DEBUG_MAIN)
|
||||
@ -1211,6 +1186,7 @@ main(int argc, char *argv[])
|
||||
case 'r':
|
||||
if (!parse_timespec(&restart, optarg))
|
||||
goto bad;
|
||||
open_mode = "r+";
|
||||
break;
|
||||
case 1:
|
||||
help();
|
||||
@ -1250,13 +1226,11 @@ main(int argc, char *argv[])
|
||||
goto bad;
|
||||
|
||||
/* Open the I/O log files and seek to restart point if there is one. */
|
||||
if (sudo_timespecisset(&restart)) {
|
||||
if (!iolog_seekto(iolog_dir_fd, iolog_dir, &elapsed, &restart)) {
|
||||
sudo_warnx(U_("unable to find restart point in %s"), iolog_dir);
|
||||
if (!iolog_open_all(iolog_dir_fd, iolog_dir, iolog_files, open_mode))
|
||||
goto bad;
|
||||
}
|
||||
} else {
|
||||
if (!iolog_open_all(iolog_dir_fd, iolog_dir))
|
||||
if (sudo_timespecisset(&restart)) {
|
||||
if (!iolog_seekto(iolog_dir_fd, iolog_dir, iolog_files, &elapsed,
|
||||
&restart))
|
||||
goto bad;
|
||||
}
|
||||
|
||||
|
@ -21,10 +21,7 @@
|
||||
# error protobuf-c version 1.30 or higher required
|
||||
#endif
|
||||
|
||||
#include "buffer.h"
|
||||
|
||||
/* XXX: share with server */
|
||||
#define DEFAULT_PORT_STR "30344"
|
||||
#include "logsrv_util.h"
|
||||
|
||||
enum client_state {
|
||||
ERROR,
|
||||
|
Loading…
x
Reference in New Issue
Block a user