linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Need blocking /dev/null
@ 2001-10-29 21:07 Marko Rauhamaa
  2001-10-29 21:24 ` Alan Cox
  2001-10-29 21:45 ` Hugh Dickins
  0 siblings, 2 replies; 21+ messages in thread
From: Marko Rauhamaa @ 2001-10-29 21:07 UTC (permalink / raw)
  To: linux-kernel


I noticed that I need a pseudodevice that opens normally but blocks all
reads (and writes). The only way out would be through a signal. Neither
/dev/zero nor /dev/null block, but is there some other standard device
that would do the job?

If there isn't, writing such a pseudodevice would be trivial. What
should it be called? Any chance of including that in the kernel?


Marko

-- 
Marko Rauhamaa    mailto:marko@pacujo.nu     http://www.pacujo.nu/marko/

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

* Re: Need blocking /dev/null
  2001-10-29 21:07 Need blocking /dev/null Marko Rauhamaa
@ 2001-10-29 21:24 ` Alan Cox
  2001-10-30  3:52   ` Marko Rauhamaa
  2001-10-29 21:45 ` Hugh Dickins
  1 sibling, 1 reply; 21+ messages in thread
From: Alan Cox @ 2001-10-29 21:24 UTC (permalink / raw)
  To: Marko Rauhamaa; +Cc: linux-kernel

> I noticed that I need a pseudodevice that opens normally but blocks all
> reads (and writes). The only way out would be through a signal. Neither

Try using a pipe

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

* Re: Need blocking /dev/null
  2001-10-29 21:07 Need blocking /dev/null Marko Rauhamaa
  2001-10-29 21:24 ` Alan Cox
@ 2001-10-29 21:45 ` Hugh Dickins
  2001-10-29 23:03   ` elko
  1 sibling, 1 reply; 21+ messages in thread
From: Hugh Dickins @ 2001-10-29 21:45 UTC (permalink / raw)
  To: Marko Rauhamaa; +Cc: linux-kernel

On Mon, 29 Oct 2001, Marko Rauhamaa wrote:
> 
> I noticed that I need a pseudodevice that opens normally but blocks all
> reads (and writes). The only way out would be through a signal. Neither
> /dev/zero nor /dev/null block, but is there some other standard device
> that would do the job?
> 
> If there isn't, writing such a pseudodevice would be trivial. What
> should it be called? Any chance of including that in the kernel?

/dev/never


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

* Re: Need blocking /dev/null
  2001-10-29 21:45 ` Hugh Dickins
@ 2001-10-29 23:03   ` elko
  2001-10-29 23:12     ` Mike Fedyk
  0 siblings, 1 reply; 21+ messages in thread
From: elko @ 2001-10-29 23:03 UTC (permalink / raw)
  To: Hugh Dickins, Marko Rauhamaa; +Cc: linux-kernel

On Monday 29 October 2001 22:45, Hugh Dickins wrote:
> On Mon, 29 Oct 2001, Marko Rauhamaa wrote:
> > I noticed that I need a pseudodevice that opens normally but blocks
> > all reads (and writes). The only way out would be through a signal.
> > Neither /dev/zero nor /dev/null block, but is there some other
> > standard device that would do the job?
> >
> > If there isn't, writing such a pseudodevice would be trivial. What
> > should it be called? Any chance of including that in the kernel?
>
> /dev/never

sorry, the bait was too obvious: /dev/microsoft

-- 
ElkOS: 12:01am up 6 days, 9:32, 3 users, load average: 2.54, 2.40, 2.27
bofhX: appears to be a Slow/Narrow SCSI-0 Interface problem
\x04

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

* Re: Need blocking /dev/null
  2001-10-29 23:03   ` elko
@ 2001-10-29 23:12     ` Mike Fedyk
  0 siblings, 0 replies; 21+ messages in thread
From: Mike Fedyk @ 2001-10-29 23:12 UTC (permalink / raw)
  To: elko; +Cc: Hugh Dickins, Marko Rauhamaa, linux-kernel

On Tue, Oct 30, 2001 at 12:03:42AM +0100, elko wrote:
> On Monday 29 October 2001 22:45, Hugh Dickins wrote:
> > On Mon, 29 Oct 2001, Marko Rauhamaa wrote:
> > > I noticed that I need a pseudodevice that opens normally but blocks
> > > all reads (and writes). The only way out would be through a signal.
> > > Neither /dev/zero nor /dev/null block, but is there some other
> > > standard device that would do the job?
> > >
> > > If there isn't, writing such a pseudodevice would be trivial. What
> > > should it be called? Any chance of including that in the kernel?
> >
> > /dev/never
> 
> sorry, the bait was too obvious: /dev/microsoft

No,

cat /dev/microsoft > /dev/never

;)

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

* Re: Need blocking /dev/null
  2001-10-29 21:24 ` Alan Cox
@ 2001-10-30  3:52   ` Marko Rauhamaa
  2001-10-30  7:02     ` Tim Connors
  2001-10-31  0:51     ` Riley Williams
  0 siblings, 2 replies; 21+ messages in thread
From: Marko Rauhamaa @ 2001-10-30  3:52 UTC (permalink / raw)
  To: alan; +Cc: linux-kernel

> > I noticed that I need a pseudodevice that opens normally but blocks all
> > reads (and writes). The only way out would be through a signal. Neither
> 
> Try using a pipe

You're right. This is what I wanted to do:

   while true
   do
       ssh -R a:b:c host
       sleep 10
   done </dev/never >/dev/null

But I could do it like this:

   while true
   do
       sleep 100000
   done |
   while true
   do
       ssh -R a:b:c host
       sleep 10
   done >/dev/null


Thank you.


Marko

PS Are /dev/null and /dev/zero also redundant?

-- 
Marko Rauhamaa    mailto:marko@pacujo.nu     http://www.pacujo.nu/marko/

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

* Re: Need blocking /dev/null
  2001-10-30  3:52   ` Marko Rauhamaa
@ 2001-10-30  7:02     ` Tim Connors
  2001-10-30 16:04       ` Marko Rauhamaa
  2001-10-31  0:51     ` Riley Williams
  1 sibling, 1 reply; 21+ messages in thread
From: Tim Connors @ 2001-10-30  7:02 UTC (permalink / raw)
  To: Marko Rauhamaa; +Cc: linux-kernel

On Mon, 29 Oct 2001, Marko Rauhamaa wrote:

> > > I noticed that I need a pseudodevice that opens normally but blocks all
> > > reads (and writes). The only way out would be through a signal. Neither
> > 
> > Try using a pipe
> 
> You're right. This is what I wanted to do:
> 
>    while true
>    do
>        ssh -R a:b:c host
>        sleep 10
>    done </dev/never >/dev/null
> 
> But I could do it like this:
> 
>    while true
>    do
>        sleep 100000
>    done |
>    while true
>    do
>        ssh -R a:b:c host
>        sleep 10
>    done >/dev/null

Highly elegant :)

How bout just `mkfifo /tmp/blockme`
and read on /tmp/blockme - just don't write to it!

-- 
TimC -- http://www.physics.usyd.edu.au/~tcon/

> cat ~/.signature
CPU time limit exceeded (core dumped)


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

* Re: Need blocking /dev/null
  2001-10-30  7:02     ` Tim Connors
@ 2001-10-30 16:04       ` Marko Rauhamaa
  0 siblings, 0 replies; 21+ messages in thread
From: Marko Rauhamaa @ 2001-10-30 16:04 UTC (permalink / raw)
  To: tcon; +Cc: linux-kernel

> How bout just `mkfifo /tmp/blockme`
> and read on /tmp/blockme - just don't write to it!

I don't think that will work, not the same way anyway. The problem is it
will block on open(2) and will never get to read(2).


Marko

-- 
Marko Rauhamaa    mailto:marko@pacujo.nu     http://www.pacujo.nu/marko/

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

* Re: Need blocking /dev/null
  2001-10-30  3:52   ` Marko Rauhamaa
  2001-10-30  7:02     ` Tim Connors
@ 2001-10-31  0:51     ` Riley Williams
  2001-10-31  9:23       ` Ville Herva
  1 sibling, 1 reply; 21+ messages in thread
From: Riley Williams @ 2001-10-31  0:51 UTC (permalink / raw)
  To: Marko Rauhamaa; +Cc: alan, linux-kernel

Hi Marko.

> PS Are /dev/null and /dev/zero also redundant?

I regularly use both...

 1. Find a download that doesn't appear where one expected it...

	find / -name "wanted-but-lost-download" 2> /dev/null

 2. Create a loop-mounted partition to populate as a CD image before
    burning the CD in question.

	dd if=/dev/zero bs=1048576 count=750 of=/tmp/cd.img
	mke2fs /tmp/cd.img
	mount -o loop /tmp/cd.img /img/cd

 3. Create a loop-mounted partition to populate as a floppy image.

	dd if=/dev/zero bs=1024 count=1440 of=/tmp/floppy.img
	mke2fs /tmp/floppy.img
	mount -o loop /tmp/floppy.img /img/floppy

Neither has alternatives that make sense as far as I can see.

Best wishes from Riley.


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

* Re: Need blocking /dev/null
  2001-10-31  0:51     ` Riley Williams
@ 2001-10-31  9:23       ` Ville Herva
  2001-10-31 23:13         ` Riley Williams
  0 siblings, 1 reply; 21+ messages in thread
From: Ville Herva @ 2001-10-31  9:23 UTC (permalink / raw)
  To: Riley Williams; +Cc: linux-kernel

On Wed, Oct 31, 2001 at 12:51:29AM +0000, you [Riley Williams] claimed:
> Hi Marko.
> 
> > PS Are /dev/null and /dev/zero also redundant?
> 
> I regularly use both...
> 
>  1. Find a download that doesn't appear where one expected it...
> 
> 	find / -name "wanted-but-lost-download" 2> /dev/null
> 
>  2. Create a loop-mounted partition to populate as a CD image before
>     burning the CD in question.
> 
> 	dd if=/dev/zero bs=1048576 count=750 of=/tmp/cd.img
> 	mke2fs /tmp/cd.img
> 	mount -o loop /tmp/cd.img /img/cd
> 
>  3. Create a loop-mounted partition to populate as a floppy image.
> 
> 	dd if=/dev/zero bs=1024 count=1440 of=/tmp/floppy.img
> 	mke2fs /tmp/floppy.img
> 	mount -o loop /tmp/floppy.img /img/floppy
> 
> Neither has alternatives that make sense as far as I can see.

Certainly have in the sense that you could theoretically do that in user
space.

find / -name "wanted-but-lost-download" | eat
zerofill | head -c 1440k > /tmp/floppy.img
ssh foo@bar | block

etc.
 
(Implementation of eat, block and zerofill is left as an exercise...)


-- v --

v@iki.fi

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

* Re: Need blocking /dev/null
  2001-10-31  9:23       ` Ville Herva
@ 2001-10-31 23:13         ` Riley Williams
  2001-11-01  0:11           ` Doug McNaught
  2001-11-01  7:24           ` Ville Herva
  0 siblings, 2 replies; 21+ messages in thread
From: Riley Williams @ 2001-10-31 23:13 UTC (permalink / raw)
  To: Ville Herva; +Cc: Linux Kernel

Hi Ville.

>>> PS Are /dev/null and /dev/zero also redundant?

>> I regularly use both...
>> 
>>  1. Find a download that doesn't appear where one expected it...
>> 
>> 	find / -name "wanted-but-lost-download" 2> /dev/null
>> 
>>  2. Create a loop-mounted partition to populate as a CD image before
>>     burning the CD in question.
>> 
>> 	dd if=/dev/zero bs=1048576 count=750 of=/tmp/cd.img
>> 	mke2fs /tmp/cd.img
>> 	mount -o loop /tmp/cd.img /img/cd
>> 
>>  3. Create a loop-mounted partition to populate as a floppy image.
>> 
>> 	dd if=/dev/zero bs=1024 count=1440 of=/tmp/floppy.img
>> 	mke2fs /tmp/floppy.img
>> 	mount -o loop /tmp/floppy.img /img/floppy
>> 
>> Neither has alternatives that make sense as far as I can see.

> Certainly have in the sense that you could theoretically do that in
> user space.

Are you sure?

> find / -name "wanted-but-lost-download" | eat

Doesn't work - you're piping the stdin there, not stderr as per my
example above. AFAIK, there's no way to pipe stderr without also piping
stdout, hence this sort of solution just doesn't work.

AFAICS, there is no sane alternative to /dev/null in userspace.

> zerofill | head -c 1440k > /tmp/floppy.img

How does zerofill know when to stop writing zeros out? After all, if it
doesn't write enough out for the head call, then it's no longer an
equivalent to /dev/zero, and it could easily be called with just about
ANY positive number of bytes, including an infinite number, as in...

	zerofill | tr '\0' '@' > /dev/ttyS1

...which sends an infinite stream of 0x40 bytes to the serial port.

However...

	zerofill 750M  > /tmp/img.cd
	zerofill 1440k > /tmp/img.floppy

...would be a reasonable userspace equivalent to examples (2) and (3)
respectively, so that certainly could be done in userspace.

> ssh foo@bar | block

Which of my examples is this an equivalent to? I don't recognise it.

> (Implementation of eat, block and zerofill is left as an
> exercise...)

I'll leave that to somebody with more unwanted time than I have...

Best wishes from Riley.


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

* Re: Need blocking /dev/null
  2001-10-31 23:13         ` Riley Williams
@ 2001-11-01  0:11           ` Doug McNaught
  2001-11-01  7:27             ` Ville Herva
                               ` (2 more replies)
  2001-11-01  7:24           ` Ville Herva
  1 sibling, 3 replies; 21+ messages in thread
From: Doug McNaught @ 2001-11-01  0:11 UTC (permalink / raw)
  To: Riley Williams; +Cc: Ville Herva, Linux Kernel

Riley Williams <rhw@MemAlpha.cx> writes:

> Are you sure?
> 
> > find / -name "wanted-but-lost-download" | eat
> 
> Doesn't work - you're piping the stdin there, not stderr as per my
> example above. AFAIK, there's no way to pipe stderr without also piping
> stdout, hence this sort of solution just doesn't work.

The Bourne shell is more perverse than you realize:

$ exec 3>&1; find / -name "wanted-but-lost-download" 2>&1 1>&3 3>&- | eat

[stolen from "Csh Programming Considered Harmful" by Tom Christiansen]

Horrible, but does work.  ;) 

> > zerofill | head -c 1440k > /tmp/floppy.img
> 
> How does zerofill know when to stop writing zeros out?

Easy, it gets EPIPE on the write (or gets killed by SIGPIPE if it's
stupid). 

> > ssh foo@bar | block
> 
> Which of my examples is this an equivalent to? I don't recognise it.

None; he's referring to the /dev/block example that started the
thread.

I'm still happy to keep /dev/null and /dev/zero.  ;)

-Doug
-- 
Let us cross over the river, and rest under the shade of the trees.
   --T. J. Jackson, 1863

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

* Re: Need blocking /dev/null
  2001-10-31 23:13         ` Riley Williams
  2001-11-01  0:11           ` Doug McNaught
@ 2001-11-01  7:24           ` Ville Herva
  1 sibling, 0 replies; 21+ messages in thread
From: Ville Herva @ 2001-11-01  7:24 UTC (permalink / raw)
  To: Riley Williams; +Cc: Linux Kernel

On Wed, Oct 31, 2001 at 11:13:22PM +0000, you [Riley Williams] claimed:
> Hi Ville.
> 
> 
> > Certainly have in the sense that you could theoretically do that in
> > user space.
> 
> Are you sure?

In theory, yes.
 
> > find / -name "wanted-but-lost-download" | eat
> 
> Doesn't work - you're piping the stdin there, not stderr as per my
> example above.

Sorry, I wasn't careful enough.

> AFAIK, there's no way to pipe stderr without also piping
> stdout, hence this sort of solution just doesn't work.

One could argue that is a fault of the shell - which again is a userland
thing.

If anything else fails, you could do

% touch y; rm -f x
% ls x y
ls: x: No such file or directory
y
% mkfifo f           
% ls x y 2> f & wc -c f
y
     33 f
rm f

Which of course isn't pretty, but it's doable. Of course, I'm not arguing
that we should get rid of /dev/null and /dev/zero, but that in theory you
could implement them in userspace.

Come to think of it, the biggest gain from /dev/null and /dev/zero comes
propably when you do memmaps. I'm not actually sure whether you could all
tath without /dev/null and /dev/zero - or you could, but with performance
loss.
 
> AFAICS, there is no sane alternative to /dev/null in userspace.

Sane is relative...

> > zerofill | head -c 1440k > /tmp/floppy.img
> 
> How does zerofill know when to stop writing zeros out? After all, if it
> doesn't write enough out for the head call, then it's no longer an
> equivalent to /dev/zero, and it could easily be called with just about
> ANY positive number of bytes, including an infinite number, as in...
> 
> 	zerofill | tr '\0' '@' > /dev/ttyS1
> 
> ...which sends an infinite stream of 0x40 bytes to the serial port.

Of course it writes infinitely. When head terminates the pipe, it exits.
Just try

yes | head -c 10

Or with any characters. It gets SIGPIPE when the other end closes the pipe.

> However...
> 
> 	zerofill 750M  > /tmp/img.cd
> 	zerofill 1440k > /tmp/img.floppy
> 
> ...would be a reasonable userspace equivalent to examples (2) and (3)
> respectively, so that certainly could be done in userspace.

That's equivalent to 

zerofill | head -c 750M > /tmp/img.cd

Unless I missed something.


 
-- v --

v@iki.fi

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

* Re: Need blocking /dev/null
  2001-11-01  0:11           ` Doug McNaught
@ 2001-11-01  7:27             ` Ville Herva
  2001-11-01  7:52             ` Abramo Bagnara
  2001-11-01 23:51             ` Riley Williams
  2 siblings, 0 replies; 21+ messages in thread
From: Ville Herva @ 2001-11-01  7:27 UTC (permalink / raw)
  To: Doug McNaught; +Cc: Riley Williams, Linux Kernel

On Wed, Oct 31, 2001 at 07:11:47PM -0500, you [Doug McNaught] claimed:
> Riley Williams <rhw@MemAlpha.cx> writes:
> 
> The Bourne shell is more perverse than you realize:
> 
> $ exec 3>&1; find / -name "wanted-but-lost-download" 2>&1 1>&3 3>&- | eat
> 
> [stolen from "Csh Programming Considered Harmful" by Tom Christiansen]

Wow. I actually played a minute with zsh, but didn't find a way... I was
pretty sure, though, that it was doable.
 
> Horrible, but does work.  ;) 
> 
> > > zerofill | head -c 1440k > /tmp/floppy.img
> > 
> > How does zerofill know when to stop writing zeros out?
> 
> Easy, it gets EPIPE on the write (or gets killed by SIGPIPE if it's
> stupid). 

Stupid... Or lazy ;).
 
> > > ssh foo@bar | block
> > 
> > Which of my examples is this an equivalent to? I don't recognise it.
> 
> None; he's referring to the /dev/block example that started the
> thread.

Yep.

> I'm still happy to keep /dev/null and /dev/zero.  ;)

So am I. Perhaps it is better to let this thread die...


-- v --

v@iki.fi

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

* Re: Need blocking /dev/null
  2001-11-01  0:11           ` Doug McNaught
  2001-11-01  7:27             ` Ville Herva
@ 2001-11-01  7:52             ` Abramo Bagnara
  2001-11-01 23:51             ` Riley Williams
  2 siblings, 0 replies; 21+ messages in thread
From: Abramo Bagnara @ 2001-11-01  7:52 UTC (permalink / raw)
  To: Doug McNaught; +Cc: Riley Williams, Ville Herva, Linux Kernel

Doug McNaught wrote:
> 
> Riley Williams <rhw@MemAlpha.cx> writes:
> 
> > Are you sure?
> >
> > > find / -name "wanted-but-lost-download" | eat
> >
> > Doesn't work - you're piping the stdin there, not stderr as per my
> > example above. AFAIK, there's no way to pipe stderr without also piping
> > stdout, hence this sort of solution just doesn't work.
> 
> The Bourne shell is more perverse than you realize:
> 
> $ exec 3>&1; find / -name "wanted-but-lost-download" 2>&1 1>&3 3>&- | eat
> 
> [stolen from "Csh Programming Considered Harmful" by Tom Christiansen]
> 
> Horrible, but does work.  ;)
 
$ find / -name "wanted-but-lost-download" 2>&1 1>&0 | eat

is simpler although dependent on stdin being a tty

-- 
Abramo Bagnara                       mailto:abramo@alsa-project.org

Opera Unica                          Phone: +39.546.656023
Via Emilia Interna, 140
48014 Castel Bolognese (RA) - Italy

ALSA project               http://www.alsa-project.org
It sounds good!

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

* Re: Need blocking /dev/null
  2001-11-01  0:11           ` Doug McNaught
  2001-11-01  7:27             ` Ville Herva
  2001-11-01  7:52             ` Abramo Bagnara
@ 2001-11-01 23:51             ` Riley Williams
  2001-11-02 19:53               ` Ville Herva
  2001-11-02 20:04               ` John Adams
  2 siblings, 2 replies; 21+ messages in thread
From: Riley Williams @ 2001-11-01 23:51 UTC (permalink / raw)
  To: Doug McNaught; +Cc: Ville Herva, Linux Kernel

Hi Doug.

>> Are you sure?

>>> find / -name "wanted-but-lost-download" | eat

>> Doesn't work - you're piping the stdin there, not stderr as per my
>> example above. AFAIK, there's no way to pipe stderr without also
>> piping stdout, hence this sort of solution just doesn't work.

> The Bourne shell is more perverse than you realize:
>
> $ exec 3>&1; find / -name "wanted-but-lost-download" 2>&1 1>&3 3>&- | eat
>
> [stolen from "Csh Programming Considered Harmful" by Tom Christiansen]
>
> Horrible, but does work.  ;) 

Are you sure that works with BASH ? I've seen it listed (without the
`exec 3>&1;` at the beginning) as a CSH method for doing this, but I've
never had it work under bash, so presume the exec at the beginning is
needed for bash to be able to do this. Is that right?

Also, even if it's true, is that also true with all other possible
shells? Redirecting to /dev/null is independant of the shells, but
piping hacks like that aren't.

I'm not on bash at the moment, and don't have it available, but I'll try
it when I get home...

>>> zerofill | head -c 1440k > /tmp/floppy.img

>> How does zerofill know when to stop writing zeros out?

> Easy, it gets EPIPE on the write (or gets killed by SIGPIPE if it's
> stupid).

So it should be deliberately written to write them out in an infinite
loop? Makes a bizarre sort of sense, but not something I would ever do.

Also, as I've had pointed out to me, one sometimes needs to tell a
program to take input other than stdin from /dev/zero and that often
can't be done using pipes. The friend who pointed this out to me
recently had reason to do precicely this. The following isn't exactly
what he needed, but is similar...

 Q> ebcdic2ascii < /dev/ttyS1 | tr A-Z a-z | bindiff /dev/zero /dev/stdin

...and I would be very interested in a shell script to duplicate that
using the `zerofill` program referred to above.

>>> ssh foo@bar | block

>> Which of my examples is this an equivalent to? I don't recognise it.

> None; he's referring to the /dev/block example that started the
> thread.

> I'm still happy to keep /dev/null and /dev/zero.  ;)

So am I.

Best wishes from Riley.


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

* Re: Need blocking /dev/null
  2001-11-01 23:51             ` Riley Williams
@ 2001-11-02 19:53               ` Ville Herva
  2001-11-02 20:04               ` John Adams
  1 sibling, 0 replies; 21+ messages in thread
From: Ville Herva @ 2001-11-02 19:53 UTC (permalink / raw)
  To: Riley Williams; +Cc: Doug McNaught, Linux Kernel

On Thu, Nov 01, 2001 at 11:51:39PM +0000, you [Riley Williams] claimed:

  (Piping only stderr to a program)
  
> Also, even if it's true, is that also true with all other possible
> shells? 

I think the point is it can be made to work in userland, not that a
particular shell isn't able to do that.  In fact, I'm a bit dissapointed
that shells such as zsh and bash seem to lack an easy way to do that. But
really, this is theoretical, I think nobody is really advocating getting rid
of /dev/null and /dev/zero.

> Redirecting to /dev/null is independant of the shells, but piping hacks
> like that aren't.

The way I see it piping is independent from shells just because it can be
accomplished in userland using the present linux system calls.
 
> So it should be deliberately written to write them out in an infinite
> loop? Makes a bizarre sort of sense, but not something I would ever do.

Why is that? I see nothing bizarre in that.
 
> Also, as I've had pointed out to me, one sometimes needs to tell a
> program to take input other than stdin from /dev/zero and that often
> can't be done using pipes. The friend who pointed this out to me
> recently had reason to do precicely this. The following isn't exactly
> what he needed, but is similar...
> 
>  Q> ebcdic2ascii < /dev/ttyS1 | tr A-Z a-z | bindiff /dev/zero /dev/stdin

Again, I think it can be done in userland. Some shells even give you
convenient syntax for that. This works in zsh:

head -2 <(yes) <(uname)
==> /proc/self/fd/11 <==
y
y

==> /proc/self/fd/12 <==
Linux

So you can pipe arbitrary program output as a filename argument.

I guess you example could be written as

ebcdic2ascii < /dev/ttyS1 | tr A-Z a-z | bindiff <(zerofill) /dev/stdin
 
but I'm not sure since I have no idea your example does ;) ;).

> > I'm still happy to keep /dev/null and /dev/zero.  ;)
> 
> So am I.


-- v --

v@iki.fi

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

* Re: Need blocking /dev/null
  2001-11-01 23:51             ` Riley Williams
  2001-11-02 19:53               ` Ville Herva
@ 2001-11-02 20:04               ` John Adams
  2001-11-02 20:32                 ` Ville Herva
  1 sibling, 1 reply; 21+ messages in thread
From: John Adams @ 2001-11-02 20:04 UTC (permalink / raw)
  To: linux-kernel

On Thursday 01 November 2001 18:51, Riley Williams wrote:
> Hi Doug.
>
> >> Are you sure?
> >>
> >>> find / -name "wanted-but-lost-download" | eat
> >>
> >> Doesn't work - you're piping the stdin there, not stderr as per my
> >> example above. AFAIK, there's no way to pipe stderr without also
> >> piping stdout, hence this sort of solution just doesn't work.
> >
> > The Bourne shell is more perverse than you realize:
> >
> > $ exec 3>&1; find / -name "wanted-but-lost-download" 2>&1 1>&3 3>&- |
> > eat
> >
> > [stolen from "Csh Programming Considered Harmful" by Tom Christiansen]
> >
> > Horrible, but does work.  ;)

You really do take the hard way.  Try this to pipe just stderr:
command_that_outputs_on_1_and_2   2>/dev/stdout 1>/dev/null | eat

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

* Re: Need blocking /dev/null
  2001-11-02 20:04               ` John Adams
@ 2001-11-02 20:32                 ` Ville Herva
  2001-11-02 20:46                   ` Tim Walberg
  0 siblings, 1 reply; 21+ messages in thread
From: Ville Herva @ 2001-11-02 20:32 UTC (permalink / raw)
  To: John Adams; +Cc: linux-kernel

On Fri, Nov 02, 2001 at 04:04:13PM -0400, you [John Adams] claimed:
> > >
> > > $ exec 3>&1; find / -name "wanted-but-lost-download" 2>&1 1>&3 3>&- |
> > > eat
> > >
> > > [stolen from "Csh Programming Considered Harmful" by Tom Christiansen]
> > >
> > > Horrible, but does work.  ;)
> 
> You really do take the hard way.  Try this to pipe just stderr:
> command_that_outputs_on_1_and_2   2>/dev/stdout 1>/dev/null | eat

Hmm.

The initial question was how to do

find / -name foo 2> /dev/null 

or similar if /dev/null is not present. (Eat is a place holder for a
imaginary progrom acting as /dev/null replacement).

I guess 

find / -name foo 2>/dev/stdout 1>/dev/stderr | eat

would (kinda) work, but it fails if you want to do

find / -name foo 2> /dev/null | less

Can be done with named pipes, though.


-- v --

v@iki.fi

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

* Re: Need blocking /dev/null
  2001-11-02 20:32                 ` Ville Herva
@ 2001-11-02 20:46                   ` Tim Walberg
  2001-11-05 22:08                     ` Andreas Schwab
  0 siblings, 1 reply; 21+ messages in thread
From: Tim Walberg @ 2001-11-02 20:46 UTC (permalink / raw)
  To: Ville Herva; +Cc: John Adams, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1297 bytes --]

I think that

find / -name foo 2>&-

should do the trick (under ksh, anyway, and
probably zsh or bash as well). Csh variants
IIRC don't have the concept of closing a
file descriptor...

		tw

>>	
>>	The initial question was how to do
>>	
>>	find / -name foo 2> /dev/null 
>>	
>>	or similar if /dev/null is not present. (Eat is a place holder for a
>>	imaginary progrom acting as /dev/null replacement).
>>	
>>	I guess 
>>	
>>	find / -name foo 2>/dev/stdout 1>/dev/stderr | eat
>>	
>>	would (kinda) work, but it fails if you want to do
>>	
>>	find / -name foo 2> /dev/null | less
>>	
>>	Can be done with named pipes, though.
>>	
>>	
>>	-- v --
>>	
>>	v@iki.fi
>>	-
>>	To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>>	the body of a message to majordomo@vger.kernel.org
>>	More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>	Please read the FAQ at  http://www.tux.org/lkml/
End of included message



-- 
+--------------------------+------------------------------+
| Tim Walberg              | twalberg@mindspring.com      |
| 830 Carriage Dr.         | www.concentric.net/~twalberg |
| Algonquin, IL 60102      |                              |
+--------------------------+------------------------------+

[-- Attachment #2: Type: application/pgp-signature, Size: 175 bytes --]

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

* Re: Need blocking /dev/null
  2001-11-02 20:46                   ` Tim Walberg
@ 2001-11-05 22:08                     ` Andreas Schwab
  0 siblings, 0 replies; 21+ messages in thread
From: Andreas Schwab @ 2001-11-05 22:08 UTC (permalink / raw)
  To: Tim Walberg; +Cc: Ville Herva, John Adams, linux-kernel

Tim Walberg <twalberg@mindspring.com> writes:

|> I think that
|> 
|> find / -name foo 2>&-
|> 
|> should do the trick (under ksh, anyway, and
|> probably zsh or bash as well).

This is different since the process now gets an error when trying to write
to fd 2, and a good implementation with check for errors.

Andreas.

-- 
Andreas Schwab                                  "And now for something
Andreas.Schwab@suse.de				completely different."
SuSE Labs, SuSE GmbH, Schanzäckerstr. 10, D-90443 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5

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

end of thread, other threads:[~2001-11-05 22:09 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-29 21:07 Need blocking /dev/null Marko Rauhamaa
2001-10-29 21:24 ` Alan Cox
2001-10-30  3:52   ` Marko Rauhamaa
2001-10-30  7:02     ` Tim Connors
2001-10-30 16:04       ` Marko Rauhamaa
2001-10-31  0:51     ` Riley Williams
2001-10-31  9:23       ` Ville Herva
2001-10-31 23:13         ` Riley Williams
2001-11-01  0:11           ` Doug McNaught
2001-11-01  7:27             ` Ville Herva
2001-11-01  7:52             ` Abramo Bagnara
2001-11-01 23:51             ` Riley Williams
2001-11-02 19:53               ` Ville Herva
2001-11-02 20:04               ` John Adams
2001-11-02 20:32                 ` Ville Herva
2001-11-02 20:46                   ` Tim Walberg
2001-11-05 22:08                     ` Andreas Schwab
2001-11-01  7:24           ` Ville Herva
2001-10-29 21:45 ` Hugh Dickins
2001-10-29 23:03   ` elko
2001-10-29 23:12     ` Mike Fedyk

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