Nikita Ivanov <niva...@cloudlinux.com> writes: > Summing up the discussion above, I suggest the following patch for TFR() > macro refactoring. (The patch is sequential to the first one I introduced > in the start of the discussion). > >>From 6318bee052900aa93bba6620b53c7cb2290e5001 Mon Sep 17 00:00:00 2001 > From: Nikita Ivanov <niva...@cloudlinux.com> > Date: Mon, 8 Aug 2022 09:30:34 +0300 > Subject: [PATCH] Refactoring: rename TFR() to TEMP_FAILURE_RETRY() > > glibc's unistd.h header provides the same macro with the > subtle difference in type casting. Adjust macro name to the > common standard and define conditionally. > > Signed-off-by: Nikita Ivanov <niva...@cloudlinux.com> > --- > chardev/char-fd.c | 2 +- > chardev/char-pipe.c | 12 +++++++++--- > hw/9pfs/9p-local.c | 6 ++++-- > include/qemu/osdep.h | 6 ++++-- > net/l2tpv3.c | 8 +++++--- > net/tap-linux.c | 2 +- > net/tap.c | 10 ++++++---- > os-posix.c | 2 +- > qga/commands-posix.c | 2 +- > tests/qtest/libqtest.c | 2 +- > util/main-loop.c | 2 +- > util/osdep.c | 2 +- > 12 files changed, 35 insertions(+), 21 deletions(-) > > diff --git a/chardev/char-fd.c b/chardev/char-fd.c > index cf78454841..7f5ed9aba3 100644 > --- a/chardev/char-fd.c > +++ b/chardev/char-fd.c > @@ -198,7 +198,7 @@ int qmp_chardev_open_file_source(char *src, int flags, > Error **errp) > { > int fd = -1; > > - TFR(fd = qemu_open_old(src, flags, 0666)); > + TEMP_FAILURE_RETRY(fd = qemu_open_old(src, flags, 0666)); > if (fd == -1) { > error_setg_file_open(errp, errno, src); > } > diff --git a/chardev/char-pipe.c b/chardev/char-pipe.c > index 66d3b85091..aed97e306b 100644 > --- a/chardev/char-pipe.c > +++ b/chardev/char-pipe.c > @@ -131,8 +131,12 @@ static void qemu_chr_open_pipe(Chardev *chr, > > filename_in = g_strdup_printf("%s.in", filename); > filename_out = g_strdup_printf("%s.out", filename); > - TFR(fd_in = qemu_open_old(filename_in, O_RDWR | O_BINARY)); > - TFR(fd_out = qemu_open_old(filename_out, O_RDWR | O_BINARY)); > + TEMP_FAILURE_RETRY( > + fd_in = qemu_open_old(filename_in, O_RDWR | O_BINARY) > + ); > + TEMP_FAILURE_RETRY( > + fd_out = qemu_open_old(filename_out, O_RDWR | O_BINARY) > + );
Style question: do we want the ");" on its own line? I think we generally don't do that for function and function-like macro calls. > g_free(filename_in); > g_free(filename_out); > if (fd_in < 0 || fd_out < 0) { > @@ -142,7 +146,9 @@ static void qemu_chr_open_pipe(Chardev *chr, > if (fd_out >= 0) { > close(fd_out); > } > - TFR(fd_in = fd_out = qemu_open_old(filename, O_RDWR | O_BINARY)); > + TEMP_FAILURE_RETRY( > + fd_in = fd_out = qemu_open_old(filename, O_RDWR | O_BINARY) > + ); > if (fd_in < 0) { > error_setg_file_open(errp, errno, filename); > return; > diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c > index c90ab947ba..e803c05d0c 100644 > --- a/hw/9pfs/9p-local.c > +++ b/hw/9pfs/9p-local.c > @@ -470,7 +470,7 @@ static ssize_t local_readlink(FsContext *fs_ctx, > V9fsPath *fs_path, > if (fd == -1) { > return -1; > } > - TFR(tsize = read(fd, (void *)buf, bufsz)); > + TEMP_FAILURE_RETRY(tsize = read(fd, (void *)buf, bufsz)); > close_preserve_errno(fd); > } else if ((fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) || > (fs_ctx->export_flags & V9FS_SM_NONE)) { > @@ -906,7 +906,9 @@ static int local_symlink(FsContext *fs_ctx, const char > *oldpath, > } > /* Write the oldpath (target) to the file. */ > oldpath_size = strlen(oldpath); > - TFR(write_size = write(fd, (void *)oldpath, oldpath_size)); > + TEMP_FAILURE_RETRY( > + write_size = write(fd, (void *)oldpath, oldpath_size) > + ); > close_preserve_errno(fd); > > if (write_size != oldpath_size) { > diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h > index b1c161c035..55f2927d8b 100644 > --- a/include/qemu/osdep.h > +++ b/include/qemu/osdep.h > @@ -242,8 +242,10 @@ void QEMU_ERROR("code path is reachable") > #if !defined(ESHUTDOWN) > #define ESHUTDOWN 4099 > #endif > - > -#define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR) > +#if !defined(TEMP_FAILURE_RETRY) > +#define TEMP_FAILURE_RETRY(expr) \ > + do { if ((expr) != -1) break; } while (errno == EINTR) > +#endif GLibc's version is # define TEMP_FAILURE_RETRY(expression) \ (__extension__ \ ({ long int __result; \ do __result = (long int) (expression); \ while (__result == -1L && errno == EINTR); \ __result; })) The difference isn't just "type casting", it's also statement vs. expression. Is it a good idea to have the macro expand into a statement on some hosts, and into an expression on others? Sure, CI should catch any uses as expression, but delaying compile errors to CI wastes developer time. > > /* time_t may be either 32 or 64 bits depending on the host OS, and > * can be either signed or unsigned, so we can't just hardcode a [...]