From 84498104bfe2a4662221992951e71d2a2f5ceffc Mon Sep 17 00:00:00 2001 From: Achim Leitner Date: Sun, 17 Oct 2021 22:00:24 +0200 Subject: Linux: Handle protected_regular in inplace writes (#241) The Linux fs.protected_regular sysctl setting could cause rsync to fail to write a file in-place with the O_CREAT flag set, so the code now tries an open without O_CREAT when it might help to avoid an EACCES error. A testsuite script is included (and slightly improved by Wayne to ensure that it outputs a SKIP when fs.protected_regular is turned off). --- receiver.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'receiver.c') diff --git a/receiver.c b/receiver.c index 091fcd6f..2cd84351 100644 --- a/receiver.c +++ b/receiver.c @@ -835,6 +835,12 @@ int recv_files(int f_in, int f_out, char *local_name) if (inplace || one_inplace) { fnametmp = one_inplace ? partialptr : fname; fd2 = do_open(fnametmp, O_WRONLY|O_CREAT, 0600); +#ifdef linux + if (fd2 == -1 && errno == EACCES) { + /* Maybe the error was due to protected_regular setting? */ + fd2 = do_open(fname, O_WRONLY, 0600); + } +#endif if (fd2 == -1) { rsyserr(FERROR_XFER, errno, "open %s failed", full_fname(fnametmp)); -- cgit v1.2.1