From c0d11422dc77eddd1c75ebb49d4a3acdc952886f Mon Sep 17 00:00:00 2001 From: Zen Dodd Date: Sat, 5 Dec 2026 00:18:02 +1000 Subject: [PATCH 1/3] build: fix check prerequisites and test-object cleanup --- Makefile.in | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile.in b/Makefile.in index 46363d1e2..d87b591a2 100644 --- a/Makefile.in +++ b/Makefile.in @@ -69,7 +69,7 @@ CHECK_SYMLINKS = testsuite/tests/metadata/chown-fake.py \ testsuite/tests/transfer/exclude-remote-shell.py # Objects for CHECK_PROGS to clean -CHECK_OBJS=tls.o testrun.o getgroups.o getfsdev.o t_stub.o t_unsafe.o t_chmod_secure.o t_rename_secure.o t_symlink_secure.o t_secure_relpath.o t_acl.o t_hashtable_overflow.o t_iwildmatch.o t_clean_fname.o t_safe_arg.o t_byteorder.o t_byteorder_portable.o trimslash.o wildtest.o +CHECK_OBJS=tls.o testrun.o getgroups.o getfsdev.o t_stub.o t_unsafe.o t_chmod_secure.o t_rename_secure.o t_symlink_secure.o t_secure_relpath.o t_acl.o t_hashtable_overflow.o t_iwildmatch.o t_clean_fname.o t_safe_arg.o t_safe_arg_main.o t_byteorder.o t_byteorder_portable.o trimslash.o wildtest.o # Compile-only feature-shape checks. CHECK_COMPILE_OBJS=syscall-no-at-fdcwd.o syscall-no-o-directory.o \ authenticate-no-o-cloexec.o rsync-no-o-cloexec.o clientserver-no-o-directory.o \ @@ -107,7 +107,7 @@ clientserver-no-o-directory.o: clientserver.c $(HEADERS) $(CC) -I. -I$(srcdir) $(CFLAGS) $(CPPFLAGS) \ -DRSYNC_TEST_NO_O_DIRECTORY -c $(srcdir)/clientserver.c -o $@ -flist-no-o-directory.o: flist.c $(HEADERS) +flist-no-o-directory.o: flist.c $(HEADERS) rounding.h $(CC) -I. -I$(srcdir) $(CFLAGS) $(CPPFLAGS) \ -DRSYNC_TEST_NO_O_DIRECTORY -c $(srcdir)/flist.c -o $@ @@ -478,15 +478,15 @@ COVERAGE_EXCLUDE = -e '(^|/)zlib/' -e '(^|/)popt/' \ check-progs: all $(CHECK_PROGS) $(CHECK_COMPILE_OBJS) $(CHECK_SYMLINKS) .PHONY: check -check: all $(CHECK_PROGS) $(CHECK_COMPILE_OBJS) $(CHECK_SYMLINKS) +check: check-progs "$(srcdir)/testsuite/runtests.py" --rsync-bin="`pwd`/rsync$(EXEEXT)" -j $(CHECK_J) .PHONY: check29 -check29: all $(CHECK_PROGS) $(CHECK_COMPILE_OBJS) $(CHECK_SYMLINKS) +check29: check-progs "$(srcdir)/testsuite/runtests.py" --rsync-bin="`pwd`/rsync$(EXEEXT)" -j $(CHECK_J) --protocol=29 .PHONY: check30 -check30: all $(CHECK_PROGS) $(CHECK_COMPILE_OBJS) $(CHECK_SYMLINKS) +check30: check-progs "$(srcdir)/testsuite/runtests.py" --rsync-bin="`pwd`/rsync$(EXEEXT)" -j $(CHECK_J) --protocol=30 # HTML branch and decision coverage; requires --enable-coverage and gcovr. From bb32fcca91596d7d6ff7ed3772d4ce8ad2c7f86b Mon Sep 17 00:00:00 2001 From: Zen Dodd Date: Sat, 5 Dec 2026 00:18:02 +1000 Subject: [PATCH 2/3] fileio: preserve pending bytes after a failed flush --- Makefile.in | 10 ++- fileio.c | 11 +++- t_fileio_buffer.c | 61 +++++++++++++++++++ .../tests/transfer/fileio-buffer-retry.py | 19 ++++++ 4 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 t_fileio_buffer.c create mode 100644 testsuite/tests/transfer/fileio-buffer-retry.py diff --git a/Makefile.in b/Makefile.in index d87b591a2..ce7289d48 100644 --- a/Makefile.in +++ b/Makefile.in @@ -61,6 +61,7 @@ TLS_OBJ = tls.o syscall.o util2.o t_stub.o lib/compat.o lib/snprintf.o lib/perms CHECK_PROGS = rsync$(EXEEXT) tls$(EXEEXT) getgroups$(EXEEXT) getfsdev$(EXEEXT) \ testrun$(EXEEXT) trimslash$(EXEEXT) t_unsafe$(EXEEXT) t_chmod_secure$(EXEEXT) \ t_byteorder$(EXEEXT) t_byteorder_portable$(EXEEXT) \ + t_fileio_buffer$(EXEEXT) \ t_rename_secure$(EXEEXT) t_symlink_secure$(EXEEXT) t_secure_relpath$(EXEEXT) t_acl$(EXEEXT) t_hashtable_overflow$(EXEEXT) t_iwildmatch$(EXEEXT) t_clean_fname$(EXEEXT) t_safe_arg$(EXEEXT) wildtest$(EXEEXT) simdtest$(EXEEXT) CHECK_SYMLINKS = testsuite/tests/metadata/chown-fake.py \ @@ -69,7 +70,7 @@ CHECK_SYMLINKS = testsuite/tests/metadata/chown-fake.py \ testsuite/tests/transfer/exclude-remote-shell.py # Objects for CHECK_PROGS to clean -CHECK_OBJS=tls.o testrun.o getgroups.o getfsdev.o t_stub.o t_unsafe.o t_chmod_secure.o t_rename_secure.o t_symlink_secure.o t_secure_relpath.o t_acl.o t_hashtable_overflow.o t_iwildmatch.o t_clean_fname.o t_safe_arg.o t_safe_arg_main.o t_byteorder.o t_byteorder_portable.o trimslash.o wildtest.o +CHECK_OBJS=tls.o testrun.o getgroups.o getfsdev.o t_stub.o t_unsafe.o t_chmod_secure.o t_rename_secure.o t_symlink_secure.o t_secure_relpath.o t_acl.o t_hashtable_overflow.o t_iwildmatch.o t_clean_fname.o t_safe_arg.o t_safe_arg_main.o t_fileio_buffer.o fileio-test.o t_byteorder.o t_byteorder_portable.o trimslash.o wildtest.o # Compile-only feature-shape checks. CHECK_COMPILE_OBJS=syscall-no-at-fdcwd.o syscall-no-o-directory.o \ authenticate-no-o-cloexec.o rsync-no-o-cloexec.o clientserver-no-o-directory.o \ @@ -264,6 +265,13 @@ T_UNSAFE_OBJ = t_unsafe.o syscall.o util1.o util2.o t_stub.o lib/compat.o lib/sn t_unsafe$(EXEEXT): $(T_UNSAFE_OBJ) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(T_UNSAFE_OBJ) $(LIBS) +fileio-test.o: fileio.c $(HEADERS) + $(CC) -I. -I$(srcdir) $(CFLAGS) $(CPPFLAGS) -Dwrite=test_fileio_write -c $(srcdir)/fileio.c -o $@ + +T_FILEIO_BUFFER_OBJ = t_fileio_buffer.o fileio-test.o syscall.o util1.o util2.o t_stub.o lib/compat.o lib/snprintf.o lib/wildmatch.o lib/permstring.o +t_fileio_buffer$(EXEEXT): $(T_FILEIO_BUFFER_OBJ) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(T_FILEIO_BUFFER_OBJ) $(LIBS) + t_byteorder$(EXEEXT): t_byteorder.o $(CC) $(CFLAGS) $(LDFLAGS) -o $@ t_byteorder.o diff --git a/fileio.c b/fileio.c index 23ebc5e28..ebdb73e9e 100644 --- a/fileio.c +++ b/fileio.c @@ -204,10 +204,15 @@ int flush_write_file(int f) char *bp = wf_writeBuf; while (wf_writeBufCnt > 0) { - if ((ret = write(f, bp, wf_writeBufCnt)) < 0) { - if (errno == EINTR) + if ((ret = write(f, bp, wf_writeBufCnt)) <= 0) { + int e = ret < 0 ? errno : EIO; + if (ret < 0 && e == EINTR) continue; - return ret; + /* A later flush starts at the buffer's beginning. */ + if (bp != wf_writeBuf) + memmove(wf_writeBuf, bp, wf_writeBufCnt); + errno = e; + return -1; } wf_writeBufCnt -= ret; bp += ret; diff --git a/t_fileio_buffer.c b/t_fileio_buffer.c new file mode 100644 index 000000000..77d923ef7 --- /dev/null +++ b/t_fileio_buffer.c @@ -0,0 +1,61 @@ +#include "rsync.h" + +struct stats stats; +int dry_run = 0, am_root = 0, am_sender = 1, read_only = 0, list_only = 0; +int copy_links = 0, copy_unsafe_links = 0; +short info_levels[COUNT_INFO], debug_levels[COUNT_DEBUG]; + +static char written[32]; +static size_t written_len; +static int attempt; +static int zero_write; + +ssize_t test_fileio_write(int fd, const void *buf, size_t count) +{ + size_t len = count; + + (void)fd; + attempt++; + if (zero_write) + return 0; + if (!zero_write && attempt == 1) + len = 3; + else if (!zero_write && attempt == 2) { + errno = EAGAIN; + return -1; + } + if (len > sizeof written - written_len) + exit(2); + memcpy(written + written_len, buf, len); + written_len += len; + return (ssize_t)len; +} + +int main(int argc, char **argv) +{ + static const char expected[] = "abcdef"; + int expected_error; + + if (argc != 2 || (strcmp(argv[1], "short-error") != 0 + && strcmp(argv[1], "zero-write") != 0)) + return 2; + zero_write = strcmp(argv[1], "zero-write") == 0; + expected_error = zero_write ? EIO : EAGAIN; + if (write_file(-1, 0, 0, expected, sizeof expected - 1) != sizeof expected - 1) + return 3; + if (zero_write) + alarm(2); + errno = 0; + if (flush_write_file(-1) >= 0 || errno != expected_error) + return 4; + alarm(0); + if (zero_write) { + zero_write = 0; + attempt = 2; + } + if (flush_write_file(-1) < 0) + return 5; + if (written_len != sizeof expected - 1 || memcmp(written, expected, written_len) != 0) + return 6; + return 0; +} diff --git a/testsuite/tests/transfer/fileio-buffer-retry.py b/testsuite/tests/transfer/fileio-buffer-retry.py new file mode 100644 index 000000000..90bf11362 --- /dev/null +++ b/testsuite/tests/transfer/fileio-buffer-retry.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 + +import subprocess + +from harness import metadata +from harness.environment import TOOLDIR +from harness.results import test_fail + + +metadata(transports={'pipe'}) + +helper = TOOLDIR / 't_fileio_buffer' +if not helper.is_file(): + test_fail('missing t_fileio_buffer helper') + +for case in ('short-error', 'zero-write'): + result = subprocess.run([str(helper), case], capture_output=True, text=True, timeout=5) + if result.returncode: + test_fail(f'{case} returned {result.returncode}: {result.stderr}') From ec3f40b0e04378b24ed5f42abac872a6dd4c7749 Mon Sep 17 00:00:00 2001 From: Zen Dodd Date: Sat, 5 Dec 2026 00:45:37 +1000 Subject: [PATCH 3/3] testsuite: keep write fault injection out of system headers --- Makefile.in | 2 +- fileio.c | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Makefile.in b/Makefile.in index ce7289d48..c0ee0e654 100644 --- a/Makefile.in +++ b/Makefile.in @@ -266,7 +266,7 @@ t_unsafe$(EXEEXT): $(T_UNSAFE_OBJ) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(T_UNSAFE_OBJ) $(LIBS) fileio-test.o: fileio.c $(HEADERS) - $(CC) -I. -I$(srcdir) $(CFLAGS) $(CPPFLAGS) -Dwrite=test_fileio_write -c $(srcdir)/fileio.c -o $@ + $(CC) -I. -I$(srcdir) $(CFLAGS) $(CPPFLAGS) -DRSYNC_TEST_FILEIO_WRITE -c $(srcdir)/fileio.c -o $@ T_FILEIO_BUFFER_OBJ = t_fileio_buffer.o fileio-test.o syscall.o util1.o util2.o t_stub.o lib/compat.o lib/snprintf.o lib/wildmatch.o lib/permstring.o t_fileio_buffer$(EXEEXT): $(T_FILEIO_BUFFER_OBJ) diff --git a/fileio.c b/fileio.c index ebdb73e9e..d7598df29 100644 --- a/fileio.c +++ b/fileio.c @@ -198,13 +198,20 @@ static char *wf_writeBuf; static size_t wf_writeBufSize; static size_t wf_writeBufCnt; +#ifdef RSYNC_TEST_FILEIO_WRITE +extern ssize_t test_fileio_write(int fd, const void *buf, size_t count); +#define FILEIO_BUFFER_WRITE test_fileio_write +#else +#define FILEIO_BUFFER_WRITE write +#endif + int flush_write_file(int f) { int ret = 0; char *bp = wf_writeBuf; while (wf_writeBufCnt > 0) { - if ((ret = write(f, bp, wf_writeBufCnt)) <= 0) { + if ((ret = FILEIO_BUFFER_WRITE(f, bp, wf_writeBufCnt)) <= 0) { int e = ret < 0 ? errno : EIO; if (ret < 0 && e == EINTR) continue;