tcmd: close ifd and ofd once in cmd_pipe() - neatvi - [fork] simple vi-type editor with UTF-8 support
(HTM) git clone git://src.adamsgaard.dk/neatvi
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
(DIR) commit 29c43728954a02c8bfbd74722a456793481280b8
(DIR) parent 5e1f787eec332dcdf9f3608c0745551d5de72ad4
(HTM) Author: Ali Gholami Rudi <ali@rudi.ir>
Date: Sun, 12 Dec 2021 23:38:22 +0330
cmd: close ifd and ofd once in cmd_pipe()
Diffstat:
M cmd.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
---
(DIR) diff --git a/cmd.c b/cmd.c
t@@ -82,16 +82,20 @@ char *cmd_pipe(char *cmd, char *ibuf, int iproc, int oproc)
int ret = read(fds[0].fd, buf, sizeof(buf));
if (ret > 0)
sbuf_mem(sb, buf, ret);
- if (ret <= 0)
+ if (ret <= 0) {
close(fds[0].fd);
+ fds[0].fd = -1;
+ }
continue;
}
if (fds[1].revents & POLLOUT) {
int ret = write(fds[1].fd, ibuf + nw, slen - nw);
if (ret > 0)
nw += ret;
- if (ret <= 0 || nw == slen)
+ if (ret <= 0 || nw == slen) {
close(fds[1].fd);
+ fds[1].fd = -1;
+ }
continue;
}
if (fds[2].revents & POLLIN) {
t@@ -101,15 +105,19 @@ char *cmd_pipe(char *cmd, char *ibuf, int iproc, int oproc)
if ((unsigned char) buf[i] == TK_CTL('c'))
kill(pid, SIGINT);
}
- if (fds[0].revents & (POLLERR | POLLHUP | POLLNVAL))
+ if (fds[0].revents & (POLLERR | POLLHUP | POLLNVAL)) {
+ close(fds[0].fd);
fds[0].fd = -1;
- if (fds[1].revents & (POLLERR | POLLHUP | POLLNVAL))
+ }
+ if (fds[1].revents & (POLLERR | POLLHUP | POLLNVAL)) {
+ close(fds[1].fd);
fds[1].fd = -1;
+ }
if (fds[2].revents & (POLLERR | POLLHUP | POLLNVAL))
fds[2].fd = -1;
}
- close(ifd);
- close(ofd);
+ close(fds[0].fd);
+ close(fds[1].fd);
waitpid(pid, NULL, 0);
if (!iproc) {
term_init();