* Redirection bugs, and fixes
@ 1996-05-08 15:30 Zefram
1996-05-08 22:43 ` Zoltan Hidvegi
0 siblings, 1 reply; 2+ messages in thread
From: Zefram @ 1996-05-08 15:30 UTC (permalink / raw)
To: Z Shell workers mailing list
-----BEGIN PGP SIGNED MESSAGE-----
There are a few remaining bugs in redirection, particularly in closing
already redirected fds. The patch below fixes all the problems I know
about in this area. The patch to utils.c below fixes a little problem
with movefd(), that it would always move its argument, even if it was
already >=10.
The incantation to demonstrate one of the bugs fixed here is:
% echo foo >file >&-
% echo bar
% cat file >/dev/tty
bar
%
I've posted most of this code before, but it hasn't got into the
baseline yet. Some of the code is new -- a slightly improved version
of the old patch. This patch is against 2.6-beta17.
On other issues (does anyone read these rambling commentaries I post?),
as I now have some free time again, and the baseline is now up to date
with my multitudinous ZLE patches, I plan to work seriously on making
ZLE 8-bit clean. If anyone else has done a significant amount of work
in this area, please let me know.
And one more thing: I noticed that Src/.indent.pro disappeared between
beta16 and beta17. I don't think it was in any of the hzoli releases.
I don't use indent myself, but this seems a rather silly change. Zoltan,
was there some reason for removing this?
-zefram
Index: Src/exec.c
*** Src/exec.c:1.1.1.8 Tue May 7 23:24:16 1996
--- Src/exec.c Tue May 7 23:55:44 1996
***************
*** 909,944 ****
void
closemn(struct multio **mfds, int fd)
{
! if (mfds[fd]) {
! if (mfds[fd]->ct > 1) {
! struct multio *mn = mfds[fd];
! char buf[TCBUFSIZE];
! int len, i;
!
! if (zfork()) {
! for (i = 0; i < mn->ct; i++)
! zclose(mn->fds[i]);
! zclose(mn->pipe);
! return;
! }
! /* pid == 0 */
! closeallelse(mn);
! if (mn->rflag) {
! /* tee process */
! while ((len = read(mn->pipe, buf, TCBUFSIZE)) > 0)
! for (i = 0; i < mn->ct; i++)
! write(mn->fds[i], buf, len);
! } else {
! /* cat process */
! for (i = 0; i < mn->ct; i++)
! while ((len = read(mn->fds[i], buf, TCBUFSIZE)) > 0)
! write(mn->pipe, buf, len);
! }
! _exit(0);
! }
! mfds[fd] = NULL;
}
}
/* close all the mnodes (failure) */
--- 909,944 ----
void
closemn(struct multio **mfds, int fd)
{
! struct multio *mn = mfds[fd];
! char buf[TCBUFSIZE];
! int len, i;
! if (!mfds[fd] || mfds[fd]->ct < 2)
! return;
!
! if (zfork()) {
! for (i = 0; i < mn->ct; i++)
! zclose(mn->fds[i]);
! zclose(mn->pipe);
! mn->ct = 1;
! mn->fds[0] = fd;
! return;
! }
!
! /* pid == 0 */
! closeallelse(mn);
! if (mn->rflag) {
! /* tee process */
! while ((len = read(mn->pipe, buf, TCBUFSIZE)) > 0)
! for (i = 0; i < mn->ct; i++)
! write(mn->fds[i], buf, len);
! } else {
! /* cat process */
! for (i = 0; i < mn->ct; i++)
! while ((len = read(mn->fds[i], buf, TCBUFSIZE)) > 0)
! write(mn->pipe, buf, len);
}
+ _exit(0);
}
/* close all the mnodes (failure) */
***************
*** 1428,1434 ****
init_io();
break;
case CLOSE:
! if (!forked && fn->fd1 < 10)
save[fn->fd1] = movefd(fn->fd1);
closemn(mfds, fn->fd1);
zclose(fn->fd1);
--- 1428,1434 ----
init_io();
break;
case CLOSE:
! if (!forked && fn->fd1 < 10 && save[fn->fd1] == -1)
save[fn->fd1] = movefd(fn->fd1);
closemn(mfds, fn->fd1);
zclose(fn->fd1);
***************
*** 1437,1443 ****
case MERGEOUT:
if (fn->fd2 == FD_COPROC)
fn->fd2 = (fn->type == MERGEOUT) ? coprocout : coprocin;
! closemn(mfds, fn->fd1);
fil = dup(fn->fd2);
if (fil == -1) {
char fdstr[4];
--- 1437,1444 ----
case MERGEOUT:
if (fn->fd2 == FD_COPROC)
fn->fd2 = (fn->type == MERGEOUT) ? coprocout : coprocin;
! else if(fn->fd2 < 10)
! closemn(mfds, fn->fd2);
fil = dup(fn->fd2);
if (fil == -1) {
char fdstr[4];
Index: Src/utils.c
*** Src/utils.c:1.1.1.7 Tue May 7 23:24:36 1996
--- Src/utils.c Tue May 7 23:55:46 1996
***************
*** 859,871 ****
{
int fe;
! if (fd == -1)
return fd;
#ifdef F_DUPFD
fe = fcntl(fd, F_DUPFD, 10);
#else
! if ((fe = dup(fd)) < 10)
! fe = movefd(fe);
#endif
close(fd);
fdtable[fd] = 0;
--- 859,870 ----
{
int fe;
! if (fd == -1 || fd >= 10)
return fd;
#ifdef F_DUPFD
fe = fcntl(fd, F_DUPFD, 10);
#else
! fe = movefd(dup(fd));
#endif
close(fd);
fdtable[fd] = 0;
-----BEGIN PGP SIGNATURE-----
Version: 2.6.2
iQCVAwUBMY/tEnD/+HJTpU/hAQEqoQP/SL1+I0gCqrbAXGier3eD4lnLqMtfoFVj
TIWW75o/CIvBWzJwZnPrD78oBM+AmKjL015CwTnQy6G8FnAE/er/amNqmwHWR2u/
s6+9z0/D6xppoBbmQrkQldLzH4AcENCuFcqoMlXnehMDsUhHV/yRXMBjGRQwEsfL
fab64op3XtQ=
=441j
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Redirection bugs, and fixes
1996-05-08 15:30 Redirection bugs, and fixes Zefram
@ 1996-05-08 22:43 ` Zoltan Hidvegi
0 siblings, 0 replies; 2+ messages in thread
From: Zoltan Hidvegi @ 1996-05-08 22:43 UTC (permalink / raw)
To: Zefram; +Cc: zsh-workers
> There are a few remaining bugs in redirection, particularly in closing
> already redirected fds. The patch below fixes all the problems I know
> about in this area. The patch to utils.c below fixes a little problem
> with movefd(), that it would always move its argument, even if it was
> already >=10.
Thanks, I'll have a look at. Somehow I missed your previous patches about
that.
> On other issues (does anyone read these rambling commentaries I post?),
Yes, I read them (even I do not always reply).
> as I now have some free time again, and the baseline is now up to date
> with my multitudinous ZLE patches, I plan to work seriously on making
> ZLE 8-bit clean. If anyone else has done a significant amount of work
> in this area, please let me know.
Go ahead. I think in zle it is better to use raw 8-bit data in line which
can even contain nulls if ll is used everywhere. The raw 8-bit input
should be converted to zsh format each time it gets in touch with any
other part of zsh. There is a metafy function for that which can generate
a converted version in various ways. See the comment before metafy() in
utils.c for detals.
> And one more thing: I noticed that Src/.indent.pro disappeared between
> beta16 and beta17. I don't think it was in any of the hzoli releases.
> I don't use indent myself, but this seems a rather silly change. Zoltan,
> was there some reason for removing this?
There was no reason, it was an accident. I always used zsh globbing to
generate releases and I do not have GLOB_DOTS set by default. I'll put it
back in the next release.
Zoltan
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1996-05-09 0:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-05-08 15:30 Redirection bugs, and fixes Zefram
1996-05-08 22:43 ` Zoltan Hidvegi
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).