Hello. At Sun, 20 May 2018 09:05:22 +0900, Michael Paquier <mich...@paquier.xyz> wrote in <20180520000522.gb1...@paquier.xyz> > Hi all, > > This is basically a new thread after what has been discussed for > pg_controldata with its error handling for read(): > https://www.postgresql.org/message-id/CABUevEx8ZRV5Ut_FvP2etXiQppx3xVzm7oOaV3AcdHxX81Yt8Q%40mail.gmail.com > > While reviewing the core code, I have noticed similar weird error > handling for read(). At the same time, some of those places may use an > incorrect errno, as an error is invoked using an errno which may be > overwritten by another system call. I found a funny one in slru.c, > for which I have added a note in the patch. I don't think that this is > worth addressing with more facility, thoughts are welcome. > > Attached is a patch addressing the issues I found.
I see the same issue in snapbuild.c(4 places). | readBytes = read(fd, &ondisk, SnapBuildOnDiskConstantSize); | pgstat_report_wait_end(); | if (readBytes != SnapBuildOnDiskConstantSize) | { | CloseTransientFile(fd); | ereport(ERROR, | (errcode_for_file_access(), | errmsg("could not read file \"%s\", read %d of %d: %m", | path, readBytes, (int) SnapBuildOnDiskConstantSize))); | } and walsender.c (2 places) | if (nread <= 0) | ereport(ERROR, | (errcode_for_file_access(), | errmsg("could not read file \"%s\": %m", | path))); and pg_receivewal.c | if (read(fd, (char *) buf, sizeof(buf)) != sizeof(buf)) | { | fprintf(stderr, _("%s: could not read compressed file \"%s\": %s\n"), | progname, fullpath, strerror(errno)); pg_waldump.c | if (readbytes <= 0) ... | fatal_error("could not read from log file %s, offset %u, length %d: %s", | fname, sendOff, segbytes, strerror(err)); A bit differnt issue, but in pg_waldump.c, search_directory can check uninitialized errno when read returns a non-zero value. regards. -- Kyotaro Horiguchi NTT Open Source Software Center