--- contrib/pgcrypto/random.c +++ contrib/pgcrypto/random.c @@ -42,21 +42,28 @@ #include static int -safe_read(int fd, void *buf, size_t count) -{ - int done = 0; - char *p = buf; - int res; +safe_read(int fd, void *buf, size_t count) { +#define NULL_MAX 16 + int done = 0; + char *p = buf; + int res, nulcount; - while (count) - { + nulcount = 0; + while (count) { res = read(fd, p, count); - if (res <= 0) - { + if (res < 0) { + elog(WARNING, "RAND_DEV!%d res=%d errno=%d" + , count, res, errno); if (errno == EINTR) continue; return -1; - } + } else if (res == 0) { + elog(WARNING, "RAND_DEV!%d NULL nulcount=%d" + , count, nulcount); + if (nulcount++ > NULL_MAX) + return -1; + usleep(1 << nulcount); + } else nulcount = 0; p += res; done += res; count -= res;