nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Error message when writing to a FIFO


From: André Kugland
Subject: Error message when writing to a FIFO
Date: Mon, 27 Sep 2021 06:38:15 +0000

When nano tries to write to a FIFO, it calls fsync, which returns EINVAL.

From the man page for fsync:

ERRORS

[...]

EROFS, EINVAL
             fd is bound to a special file (e.g., a pipe, FIFO, or socket) which does
             not support synchronization.

Here’s a patch for this:

--- PATCH STARTS HERE ---
diff --git a/src/files.c b/src/files.c
index 400cbb10..842928a2 100644
--- a/src/files.c
+++ b/src/files.c
@@ -1956,7 +1956,16 @@ bool write_file(const char *name, FILE *thefile, bool tmp,
#endif
 
       /* Ensure the data has reached the disk before reporting it as written. */
-       if (fflush(thefile) != 0 || fsync(fileno(thefile)) != 0) {
+       errno = 0;
+       fflush(thefile);
+
+#ifndef NANO_TINY
+       if (errno == 0 && !S_ISFIFO(st.st_mode)) {
+               fsync(fileno(thefile));
+       }
+#endif
+
+       if (errno != 0) {
               statusline(ALERT, _("Error writing %s: %s"), realname, strerror(errno));
               fclose(thefile);
               goto cleanup_and_exit;
--- PATCH ENDS HERE ---

André Kugland

reply via email to

[Prev in Thread] Current Thread [Next in Thread]