aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar lvgx <l@vgx.fr>2020-06-19 03:40:37 +0200
committerGravatar GitHub <noreply@github.com>2020-06-19 07:10:37 +0530
commit7a1a4e293e7b3497346eee99294fe24658cbf145 (patch)
tree5af25ee73d64e45db8795e5979344eae2bd3ee2b
parent9b5b2b544c50f5c564df9b5b43785568c7ea9dd1 (diff)
downloadnnn-7a1a4e293e7b3497346eee99294fe24658cbf145.tar.gz
Avoid SIGWINCH interruptions of NNN_PIPE IO (#659)
Fixes #656
-rw-r--r--src/nnn.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/nnn.c b/src/nnn.c
index 5c89346..5bd7d6a 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -4300,11 +4300,20 @@ static void rmlistpath()
}
}
+static ssize_t read_nointr(int fd, void *buf, size_t count)
+{
+ ssize_t len;
+ do{
+ len = read(fd, buf, count);
+ } while (len == -1 && errno == EINTR);
+ return len;
+}
+
static void readpipe(int fd, char **path, char **lastname, char **lastdir)
{
int r;
char ctx, *nextpath = NULL;
- ssize_t len = read(fd, g_buf, 1);
+ ssize_t len = read_nointr(fd, g_buf, 1);
if (len != 1)
return;
@@ -4317,14 +4326,14 @@ static void readpipe(int fd, char **path, char **lastname, char **lastdir)
return;
}
- len = read(fd, g_buf, 1);
+ len = read_nointr(fd, g_buf, 1);
if (len != 1)
return;
char op = g_buf[0];
if (op == 'c') {
- len = read(fd, g_buf, PATH_MAX);
+ len = read_nointr(fd, g_buf, PATH_MAX);
if (len <= 0)
return;
@@ -4415,7 +4424,10 @@ static bool run_selected_plugin(char **path, const char *file, char *runfile, ch
_exit(EXIT_SUCCESS);
}
- int rfd = open(g_pipepath, O_RDONLY);
+ int rfd;
+ do {
+ rfd = open(g_pipepath, O_RDONLY);
+ } while (rfd == -1 && errno == EINTR);
readpipe(rfd, path, lastname, lastdir);
close(rfd);