So that O_RDONLY open commands (such as from copy_range) do not
block forever waiting on a non-existent writer.
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Jan Tulak <jtulak@redhat.com>
[sandeen: initialize st per djwong's suggestion]
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
struct fs_path *fs_path)
{
struct fs_path *fsp;
+ struct stat st = { 0 };
int fd;
int oflags;
if (flags & IO_NOFOLLOW)
oflags |= O_NOFOLLOW;
+ /*
+ * if we've been passed a pipe to open, don't block waiting for a
+ * reader or writer to appear. We want to either succeed or error out
+ * immediately.
+ */
+ if (stat(path, &st) < 0 && errno != ENOENT) {
+ perror("stat");
+ return -1;
+ }
+ if (S_ISFIFO(st.st_mode))
+ oflags |= O_NONBLOCK;
+
fd = open(path, oflags, mode);
if (fd < 0) {
if (errno == EISDIR &&