>From 13b0256010f7d9f6a33eb5ec3d4b9482392ebe67 Mon Sep 17 00:00:00 2001 From: Brand Huntsman Date: Wed, 15 May 2019 18:51:41 -0600 Subject: [PATCH 3/3] files: prompt before blocking on an empty FIFO Prevents nano from hanging when user accidentally opens an empty FIFO. Signed-off-by: Brand Huntsman --- src/files.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/files.c b/src/files.c index 07403853..c916cf46 100644 --- a/src/files.c +++ b/src/files.c @@ -29,6 +29,7 @@ #endif #include #include +#include #define LOCKBUFSIZE 8192 @@ -976,7 +977,29 @@ int open_file(const char *filename, bool newfie, bool quiet, FILE **f) } /* Try opening the file. */ - fd = open(full_filename, O_RDONLY); + if (S_ISFIFO(fileinfo.st_mode)) { + fd = open(full_filename, O_RDONLY | O_NONBLOCK); + if (fd != -1) { + struct pollfd fds = { fd, -1, 0 }; + if (poll(&fds, 1, 1) != 1 || !(fds.revents & POLLIN)) { + titlebar(NULL); + + if (openfile->filename[0] == '\0') { + blank_edit(); + wrefresh(edit); + } + + if (do_yesno_prompt(FALSE, _("Do you want to wait until the FIFO receives data?")) == 1) { + blank_bottombars(); + statusbar(_("Reading FIFO...")); + + fds.revents = 0; + poll(&fds, 1, -1); + } + } + } + } else + fd = open(full_filename, O_RDONLY); if (fd == -1) statusline(ALERT, _("Error reading %s: %s"), filename, strerror(errno)); -- 2.21.0