9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* Re: [9fans] dup(3)
       [not found] <<138575260910160858nfc9444fr73e3328d98eac98a@mail.gmail.com>
@ 2009-10-16 16:06 ` erik quanstrom
  0 siblings, 0 replies; 5+ messages in thread
From: erik quanstrom @ 2009-10-16 16:06 UTC (permalink / raw)
  To: 9fans

> @{builtin cd $1 && tar cf /fd/1 .} | @{builtin cd $2 && tar xTf /fd/0}
> instead of
> {builtin cd $1 && tar c .} | {builtin cd $2 && tar xT}

consider,
	; one=/bin; two=/tmp; cd /
	; @{builtin cd $one} | @{builtin cd $two} ; pwd
	/
	; {builtin cd $one} | {builtin cd $two} ; pwd
	/tmp

you don't want to change the cwd of the caller.  that
would be antisocial.

- erik



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

* Re: [9fans] dup(3)
  2009-10-16 17:25 ` Steve Simon
@ 2009-10-19  9:10   ` hugo rivera
  0 siblings, 0 replies; 5+ messages in thread
From: hugo rivera @ 2009-10-19  9:10 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Thanks for your feedback.

--
Hugo



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

* Re: [9fans] dup(3)
  2009-10-16 15:58 hugo rivera
  2009-10-16 16:52 ` Russ Cox
@ 2009-10-16 17:25 ` Steve Simon
  2009-10-19  9:10   ` hugo rivera
  1 sibling, 1 reply; 5+ messages in thread
From: Steve Simon @ 2009-10-16 17:25 UTC (permalink / raw)
  To: 9fans

> @{builtin cd $1 && tar cf /fd/1 .} | @{builtin cd $2 && tar xTf /fd/0}

the /fd/1 and /fd/0 fererences ensure that dircp will work with ape's tar
which doesn't read/write stdin/stdout by default like plan9's does.

-Steve



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

* Re: [9fans] dup(3)
  2009-10-16 15:58 hugo rivera
@ 2009-10-16 16:52 ` Russ Cox
  2009-10-16 17:25 ` Steve Simon
  1 sibling, 0 replies; 5+ messages in thread
From: Russ Cox @ 2009-10-16 16:52 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Fri, Oct 16, 2009 at 8:58 AM, hugo rivera <uair00@gmail.com> wrote:
> I am having a hard time understanding the dircp script and the dup(3)
> device. What's exactly the purpose of writing
> @{builtin cd $1 && tar cf /fd/1 .} | @{builtin cd $2 && tar xTf /fd/0}
> instead of
> {builtin cd $1 && tar c .} | {builtin cd $2 && tar xT}

your version is fine except that you dropped the @.
the author of dircp either didn't realize that tar's default
was to use those files or wanted to be explicit since
older tar commands have other defaults (the tape device).

> What other uses dup(3) might have?

the same as any other file system: it gives a file name
for a resource, making that resource usable in any program
that wants to open a file.

on unix the same need is often met by the lame idiom that
the file name - means standard input or output depending
on context.  /fd is a real file system and more general.

it's not something you need every day, but it's often crucial
when you do need it.  for example, look at the way it gets
used in in exportfs or page.

russ


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

* [9fans] dup(3)
@ 2009-10-16 15:58 hugo rivera
  2009-10-16 16:52 ` Russ Cox
  2009-10-16 17:25 ` Steve Simon
  0 siblings, 2 replies; 5+ messages in thread
From: hugo rivera @ 2009-10-16 15:58 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

I am having a hard time understanding the dircp script and the dup(3)
device. What's exactly the purpose of writing
@{builtin cd $1 && tar cf /fd/1 .} | @{builtin cd $2 && tar xTf /fd/0}
instead of
{builtin cd $1 && tar c .} | {builtin cd $2 && tar xT}
I also had a look to the pdf2ps script, and there, it seems to be
useful given that you must  provide a file trough the option
arguments. But for me this looks like a very narrow application for
the device. What other uses dup(3) might have?
Saludos

--
Hugo



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

end of thread, other threads:[~2009-10-19  9:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <<138575260910160858nfc9444fr73e3328d98eac98a@mail.gmail.com>
2009-10-16 16:06 ` [9fans] dup(3) erik quanstrom
2009-10-16 15:58 hugo rivera
2009-10-16 16:52 ` Russ Cox
2009-10-16 17:25 ` Steve Simon
2009-10-19  9:10   ` hugo rivera

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