From: Michael Paquier Date: Mon, 1 Aug 2022 07:39:30 +0000 (+0900) Subject: Fix error reporting after ioctl() call with pg_upgrade --clone X-Git-Tag: REL_13_8~21 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=aadaaeff4cf8b90c62dbb6cc67f5dd7e5a0297fe;p=thirdparty%2Fpostgresql.git Fix error reporting after ioctl() call with pg_upgrade --clone errno was not reported correctly after attempting to clone a file, leading to incorrect error reports. While scanning through the code, I have not noticed any similar mistakes. Error introduced in 3a769d8. Author: Justin Pryzby Discussion: https://postgr.es/m/20220731134135.GY15006@telsasoft.com Backpatch-through: 12 --- diff --git a/src/bin/pg_upgrade/file.c b/src/bin/pg_upgrade/file.c index 395e53791b6..2bc0f440b6f 100644 --- a/src/bin/pg_upgrade/file.c +++ b/src/bin/pg_upgrade/file.c @@ -57,9 +57,11 @@ cloneFile(const char *src, const char *dst, if (ioctl(dest_fd, FICLONE, src_fd) < 0) { + int save_errno = errno; + unlink(dst); pg_fatal("error while cloning relation \"%s.%s\" (\"%s\" to \"%s\"): %s\n", - schemaName, relName, src, dst, strerror(errno)); + schemaName, relName, src, dst, strerror(save_errno)); } close(src_fd);