Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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_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 \
Expand Down Expand Up @@ -107,7 +108,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 $@

Expand Down Expand Up @@ -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) -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)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(T_FILEIO_BUFFER_OBJ) $(LIBS)

t_byteorder$(EXEEXT): t_byteorder.o
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ t_byteorder.o

Expand Down Expand Up @@ -478,15 +486,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.
Expand Down
18 changes: 15 additions & 3 deletions fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,28 @@ 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 (errno == EINTR)
if ((ret = FILEIO_BUFFER_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;
Expand Down
61 changes: 61 additions & 0 deletions t_fileio_buffer.c
Original file line number Diff line number Diff line change
@@ -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;
}
19 changes: 19 additions & 0 deletions testsuite/tests/transfer/fileio-buffer-retry.py
Original file line number Diff line number Diff line change
@@ -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}')
Loading