Browse Source

Avoid SIGWINCH interruptions of NNN_PIPE IO (#659)

Fixes #656
master
lvgx GitHub 4 years ago
parent
commit
7a1a4e293e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 4 deletions
  1. +16
    -4
      src/nnn.c

+ 16
- 4
src/nnn.c View File

@@ -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) static void readpipe(int fd, char **path, char **lastname, char **lastdir)
{ {
int r; int r;
char ctx, *nextpath = NULL; char ctx, *nextpath = NULL;
ssize_t len = read(fd, g_buf, 1);
ssize_t len = read_nointr(fd, g_buf, 1);


if (len != 1) if (len != 1)
return; return;
@@ -4317,14 +4326,14 @@ static void readpipe(int fd, char **path, char **lastname, char **lastdir)
return; return;
} }


len = read(fd, g_buf, 1);
len = read_nointr(fd, g_buf, 1);
if (len != 1) if (len != 1)
return; return;


char op = g_buf[0]; char op = g_buf[0];


if (op == 'c') { if (op == 'c') {
len = read(fd, g_buf, PATH_MAX);
len = read_nointr(fd, g_buf, PATH_MAX);
if (len <= 0) if (len <= 0)
return; return;


@@ -4415,7 +4424,10 @@ static bool run_selected_plugin(char **path, const char *file, char *runfile, ch
_exit(EXIT_SUCCESS); _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); readpipe(rfd, path, lastname, lastdir);
close(rfd); close(rfd);


Loading…
Cancel
Save