Re: Fix some error handling for read() and errno
От | Kyotaro HORIGUCHI |
---|---|
Тема | Re: Fix some error handling for read() and errno |
Дата | |
Msg-id | 20180522.165100.182725143.horiguchi.kyotaro@lab.ntt.co.jp обсуждение исходный текст |
Ответ на | Fix some error handling for read() and errno (Michael Paquier <michael@paquier.xyz>) |
Ответы |
Re: Fix some error handling for read() and errno
|
Список | pgsql-hackers |
Hello. At Sun, 20 May 2018 09:05:22 +0900, Michael Paquier <michael@paquier.xyz> wrote in <20180520000522.GB1603@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
В списке pgsql-hackers по дате отправления: