Zhaoming Luo, le mer. 05 févr. 2025 10:33:04 +0800, a ecrit: > On Tue, Feb 04, 2025 at 09:12:18AM +0100, Samuel Thibault wrote: > > Only out_io and err_io are supposed to be readable. Or did they mean > > from the point of view of the executed process. Again, it means check > > what exactly happens to end up with "all readable fds are closed" > > Try to keep the consistency of the mail list thread so I reply to this > email.
Threads don't have to be linear :) On the contrary, it's useful to answer the mail that you want to answer to, to keep context together. The other small piece of thread will just remain in its own corner. > The investigation shows that the code[0] avoiding closing channel was > not executed because the conditional statement[1] didn't return true as > expected. Ok. > Intead I wrote the following program to reproduce the error: > > ``` > #include <stdio.h> > #include <unistd.h> > #include <fcntl.h> > > int > main () > { > int f; > int is_term; > > f = open ("/dev/ttyp4", 0); Oh, does it really open it with neither O_RDONLY nor WRONLY? > 52<--47(pid8634)->term_getctty () = 0x40000009 (Bad file descriptor) > 52<--47(pid8634)->term_getctty () = 0x40000009 (Bad file descriptor) S_term_getctty's implementation indeed has if (!(cred->po->openmodes & (O_READ|O_WRITE))) err = EBADF; Thus no wonder... It's true that posix only says for EBADF returned by isatty: The fildes argument is not a valid open file descriptor. and doesn't talk about O_RDONLY/WRONLY like it does for read() and write(). So I'd tend to just drop this if to fix the discrepancy with Posix. (and simplify the rest of the code). Samuel