Skip to content

Commit 22d753a

Browse files
committed
iolog_open: Compressed I/O logs can't be opened "r+" or "w+.
gzdopen() will fail for mode "r+" and "w+" so convert to "r" or "w" and require the caller to check the compressed flag.
1 parent 73a59b4 commit 22d753a

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

lib/iolog/iolog_open.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ static unsigned char const gzip_magic[2] = {0x1f, 0x8b};
4141
* Open the specified I/O log file and store in iol.
4242
* Stores the open file handle which has the close-on-exec flag set.
4343
* Also locks the file if iofd is IOFD_TIMING and mode is writable.
44+
* The "r+" and "w+" modes are not supported for compressed logs
45+
* so the "+" will be stripped before calling gzdopen().
4446
*/
4547
bool
4648
iolog_open(struct iolog_file *iol, int dfd, int iofd, const char *mode)
@@ -102,6 +104,12 @@ iolog_open(struct iolog_file *iol, int dfd, int iofd, const char *mode)
102104
iol->compressed = true;
103105
}
104106
}
107+
/*
108+
* Compressed logs don't support random access, gzdopen() will
109+
* fail for mode "r+". Caller must check the compressed flag.
110+
*/
111+
if (iol->compressed)
112+
mode = *mode == 'r' ? "r" : "w";
105113
if (fcntl(fd, F_SETFD, FD_CLOEXEC) != -1) {
106114
#ifdef HAVE_ZLIB_H
107115
if (iol->compressed)

0 commit comments

Comments
 (0)