Fix error reporting after ioctl() call with pg_upgrade --clone
authorMichael Paquier
Mon, 1 Aug 2022 07:38:23 +0000 (16:38 +0900)
committerMichael Paquier
Mon, 1 Aug 2022 07:38:23 +0000 (16:38 +0900)
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[email protected]
Backpatch-through: 12

src/bin/pg_upgrade/file.c

index c2ca99dcd864e29855ce23b4e6ae08e2eee18700..079fbda838937f13b8c74e710c90cea751b10ab7 100644 (file)
@@ -57,9 +57,12 @@ 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",
-                schemaName, relName, src, dst, strerror(errno));
+                schemaName, relName, src, dst, strerror(save_errno));
    }
 
    close(src_fd);