9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] rc bug?
@ 2009-11-26 16:58 roger peppe
  0 siblings, 0 replies; 2+ messages in thread
From: roger peppe @ 2009-11-26 16:58 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

this seems to be a good day for me to be finding old bugs.

i don't think these two bits of rc should behave any differently:

% rc -c 'echo hello > /fd/4' <>[4] /dev/cons
hello
% {echo hello > /fd/4} <>[4] /dev/cons
/fd/4: rc: can't open: '/fd/4' inappropriate use of fd
%

as it happens, the actual file being opened in the second
instance is '#c/cons' (the original rc's stdin).



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [9fans] rc bug?
       [not found] <<df49a7370911260858w344a5596lb0a030b19bd50a90@mail.gmail.com>
@ 2009-11-27  3:19 ` erik quanstrom
  0 siblings, 0 replies; 2+ messages in thread
From: erik quanstrom @ 2009-11-27  3:19 UTC (permalink / raw)
  To: 9fans

> % rc -c 'echo hello > /fd/4' <>[4] /dev/cons
> hello
> % {echo hello > /fd/4} <>[4] /dev/cons
> /fd/4: rc: can't open: '/fd/4' inappropriate use of fd
> %
>
> as it happens, the actual file being opened in the second
> instance is '#c/cons' (the original rc's stdin).

if you'd used a larger fd, you would have gotten this error
/fd/9: rc (8.out): can't open: '/fd/9' mounted directory forbids creation

this hints at the real problem.  redirections are processed in
two steps.  opening the file is done by X(read|write|append|rdwr).
assigning the proper fd is done by execexec.  (called when running
an external function.)  the problem is that your example requires
step two to be done when executing step 1.  (that's why the rc -c
trick worked, you forced rc to create fd 4 before using it in the
subshell and it also explains why you got the wrong fd.)

also, since the fd assignment is done only by execexec, you'll notice
that
	cd doesnt exist>[2=]
still delivers errors to the console.

i don't know of an easy solution to this.  maybe a few judicious hacks
could solve a large portion of the problem.  byron's shell tended to
solve this problem by forking early.

i've included the rc machine that is generated by code similar
to yours.

- erik

----

broken! <>[9]/dev/cons >/fd/9 echo
1 Xmark(1)
2 Xword(2) /dev/cons
4 Xglob(1)
5 Xrdwr(2) 9
7 Xmark(1)
8 Xword(2) /fd/9
10 Xglob(1)
11 Xwrite(2) 1
13 Xmark(1)
14 Xword(2) echo
16 Xsimple(1)
17 Xpopredir(1)
18 Xpopredir(1)
19 Xreturn(1)
Xrdwr /dev/cons -> fd 5
Xwrite /fd/9 -> -1
/fd/9: rc (8.out): can't open: '/fd/9' mounted directory forbids creation
popredir 5, 9
broken!



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-11-27  3:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-26 16:58 [9fans] rc bug? roger peppe
     [not found] <<df49a7370911260858w344a5596lb0a030b19bd50a90@mail.gmail.com>
2009-11-27  3:19 ` erik quanstrom

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).