When creating a new file, open_file() returns it with the offset after
the header it has just written, but on opening an existing file it will
return it with the offset at 0.
_read_bindings_file() reads sequentially from the returned fd, so on a
newly created bindings file the header check in _check_bindings_file()
hits EOF and declares the file bad. Without -B this is masked by
rewriting the file, but "multipath -B" may not write it and aborts:
ERROR: bad settings in read-only bindings file /etc/multipath/bindings
fatal configuration error, aborting
This affects the first "multipath -B" on any system without a bindings
file, such as an installer environment.
The wwids and prkeys code paths seek before every access and are
unaffected.
Fixes: 7eaeb33ae9f7 ("multipathd: watch bindings file with inotify + timestamp")
Signed-off-by: Alex Brett <[email protected]>
Assisted-by: Claude:claude-opus-5-5
---
libmultipath/file.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/libmultipath/file.c b/libmultipath/file.c
index ce9ff610..215a48cd 100644
--- a/libmultipath/file.c
+++ b/libmultipath/file.c
@@ -159,6 +159,11 @@ open_file(const char *file, int *can_write, const char
*header)
goto fail;
}
fsync(fd);
+ if (lseek(fd, 0, SEEK_SET) < 0) {
+ condlog(0, "Cannot rewind file %s : %s", file,
+ strerror(errno));
+ goto fail;
+ }
condlog(3, "Initialized new file [%s]", file);
}
--
2.53.0