On Jul 18, 2009, at 6:06 PM, erik quanstrom wrote:
On Sat Jul 18 14:41:02 EDT 2009, r...@sun.com wrote:
In the "mom, why sky is blue" department, here's a silly question:
is there any good reason that read(2) on a hangup channel returns
an error, while write(2) on a hangup channel terminates an
application
(by generating a note, of course, which can be ignored, but still)?
hmm. from a quick read of port/sysfile.c, i think the precise
behavior
might depend on the underlying device. if devtab[m->c->type]->bread/
bwrite
are (ultimately) based on qbread and qbwrite, i read qio as saying
that neither should
generate a note.
perhaps i've been asleep at the swtch, but i don't recall seing writes
on closed channels terminate programs with a note.
Observe:
cpu% cat test2.c
#include <u.h>
#include <libc.h>
#include <stdio.h>
void notary(void *v, char* s)
{
fprintf(stderr, "NOTE: %s\n", s);
noted(NCONT);
}
int main()
{
notify(¬ary);
while (1) {
fprintf(stderr, "%d\n", write(1, "roman", 5));
sleep(5000);
}
return 0;
}
cpu% 8c test2.c
cpu% 8l test2.8
cpu% { ./8.out | cat } & { sleep 10 ; slay cat | rc }
5
roman5
romanNOTE: sys: write on closed pipe pc=0x00001525
-1
NOTE: sys: write on closed pipe pc=0x00001525
-1
NOTE: sys: write on closed pipe pc=0x00001525
-1
Thanks,
Roman.