| 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(-)
--- |
| 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(); |