Introduction
Introduction Statistics Contact Development Disclaimer Help
tcmd: close ifd and ofd once in cmd_pipe() - neatvi - [fork] simple vi-type edi…
git clone git://src.adamsgaard.dk/neatvi
Log
Files
Refs
README
---
commit 29c43728954a02c8bfbd74722a456793481280b8
parent 5e1f787eec332dcdf9f3608c0745551d5de72ad4
Author: Ali Gholami Rudi <[email protected]>
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(-)
---
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 opr…
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();
You are viewing proxied material from mx1.adamsgaard.dk. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.