[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: EINTR
From: |
Bruno Haible |
Subject: |
Re: EINTR |
Date: |
Wed, 6 Jul 2011 02:02:33 +0200 |
User-agent: |
KMail/1.9.9 |
Hi,
More details about this:
> 3) On MacOS X, SIGSTOP and SIGCONT make not only read() fail with EINTR, but
> fread() as well.
>
> Test case: [3]. Run it, type Hello<Return> then Ctrl-Z then fg. Result is:
>
> $ ./a.out
> Hello
> ^Z
> [1]+ Stopped ./a.out
> $ fg
> ./a.out
> fread: Interrupted system call
> Hello
>
> $ ./a.out --unbuffered
> Hello
> Hello
> ^Z
> [1]+ Stopped ./a.out --unbuffered
> $ fg
> ./a.out --unbuffered
> fread: Interrupted system call
>
> This was also reported in [4].
>
> I would expect that EINTR also occurs in write() and fwrite() when writing
> to a pipe that is temporarily full, but I can't easily reproduce this.
Looking at the MacOS X 10.5 kernel, EINTR appears to be generated in these
situations:
- read, write, ioctl only on tty devices,
- select, poll,
- sleep,
- pthread_cond_*,
- connect.
This explaing why I cannot reproduce a malfunction with input from a pipe, only
from a tty.
Let me try a couple of coreutils programs that use fread():
1) base64: affected
$ ./base64
Hello
^Z
[1]+ Stopped ./base64
$ fg
./base64
SGVsbG8K
./base64: read error: Interrupted system call
2) cksum: affected
$ ./cksum
Hello
^Z
[1]+ Stopped ./cksum
$ fg
./cksum
World
./cksum: -: Interrupted system call
3) sha1sum: affected
$ ./sha1sum
Hello
^Z
[1]+ Stopped ./sha1sum
$ fg
./sha1sum
./sha1sum: -: Interrupted system call
4) od: affected
$ ./od -x
Hello
^Z
[1]+ Stopped ./od -x
$ fg
./od -x
./od: standard input: read error: Interrupted system call
0000000 6548 6c6c 0a6f
0000006
5) sort: affected
$ sort
Hello
^Z
[1]+ Stopped sort
$ fg
sort
sort: read failed: -: Interrupted system call
So indeed, many programs are affected. I think an fread() wrapper would be
appropriate. Shall we call it safe_fread or fread?
Bruno
Re: good place for blogging on C/POSIX programming?, Karl Berry, 2011/07/02