On Wed, Oct 29, 2025 at 11:53 AM Alyssa M via 9fans <[email protected]> wrote:
> I have a situation where I want to take an already-open file descriptor, and 
> make it become /dev/cons before I start a shell.
> I can't mount it on /dev/cons because it's not a 9p server - just a simple 
> pipe end.
> If it was a named pipe, I could bind that.
> fd2path on a pipe just produces: '#|/data' - not a unique name I could bind 
> to. So no help there...
> I thought I would put it in /srv with a unique name and then bind it over 
> /dev/cons.
> Starting with a shell that already has the file as fd #2, I tried this:
>
> term% echo 2 >/srv/foo
> term% bind /srv/foo /dev/cons
>
> This *almost* works:
>
> term% echo hello >>/dev/cons
> hello
> term%
>
> The problem is that the file in /srv doesn't quite behave like a named pipe 
> end:
>
> term% echo hello >/dev/cons
> /dev/cons: rc: can't open: '/dev/cons' srv file already exists
> term%
>
> I think this is from a check for OTRUNC on open in devsrv in the kernel, 
> which I would guess is being done so people don't accidentally try to use a 
> /srv name that's already in use (I had initially thought it might be a 
> failure from create, or some permissions problem).
> I tried setting the DMAPPEND bit on the /srv file, in the hopes that that 
> would suppress the OTRUNC, but the kernel srv driver masks off that bit of 
> the file mode, unfortunately.
> I still haven't been brave enough to go messing with the plan9 kernel.
>
> I'm thinking at this point that I could make a very small 9p file server, 
> serving a file that essentially forwards to and from a file descriptor that 
> the server is given when it starts. I'd mount that on /dev/cons, and I think 
> I can probably make that work. But it seems clumsy, given that a more direct 
> solution seems so close.
>
> So I wondering: is there a better way to do this?

pipefile(1) does something very close to this already. Perhaps you can
use it directly? If not, perhaps its implementation may be useful as a
source of ideas. It appears that it just finds the pipe device to a
name of its own choosing, and then connects to the ends of that. I
suppose it depends on which namespace it is created in, and where you
want to use it from (useful thing about srvfs is that it allows two
unrelated namespaces to share a named thing).

        - Dan C.

------------------------------------------
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/T4a173cfd35edc215-M8408e85e6405eb809bfd97dc
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

Reply via email to