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.

The investigation shows that the code[0] avoiding closing channel was
not executed because the conditional statement[1] didn't return true as
expected.

I tried to run `rpctrace -o rpclog ./vim --clean` and 
`let job = job_start('python3' . ' -c "import time;time.sleep(5)"', {'out_io': 
'null', 'err_io': 'null', 'pty': 1})
to collect the rpc log. However, it just hanged with a lot of 
`rpctrace: get an unknown send right from process 8898` and made my
terminal messy.

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

    if (f == -1)
      {
          printf ("open() failed\n");
          return 0;
      }

    printf ("fd: %d\n", f);

    is_term = isatty (f);
    if (is_term == 1)
        printf ("Its refering to a terminal!\n");
    else
        printf ("Its not refering to a terminal!\n");

    return 0;
}
```

The /dev/ttyp4 is what vim tried to check in mch_isatty:

```
...
10.220000 : Starting job: python3  -c  import time;time.sleep(5)
10.220000 on 0: Created channel
10.220000 on 0: using pty /dev/ttyp4 on fd 4
10.220000 : SafeState: Start triggering
...
```

The rpctrace log is:

```
15<--38(pid8634)->dir_lookup ("dev/ttyp4" 0 0) = 0 1 ""    52<--47(pid8634)
52<--47(pid8634)->term_getctty () = 0x40000009 (Bad file descriptor)
52<--47(pid8634)->term_getctty () = 0x40000009 (Bad file descriptor)
23<--33(pid8634)->io_stat_request () = 0 {14 805 0 0 0 1686195767 0 8397200 1 
1001 5 0 0 1738719524 0 1738719524 0 1738719524 0     512 8 0 0 0 0 0 0 0 0 0 0 
0}
30<--42(pid8634)->io_write_request ("Its not refering to a terminal!\n" -1) = 0 
32
```

So it seems it is from the source code[2].

On GNU/Linux the program successfully opened '/dev/pts/8' (this is what
vim tried to open).

[0]: https://github.com/vim/vim/blob/master/src/channel.c#L1395
[1]: https://github.com/vim/vim/blob/master/src/channel.c#L1394
[2]: https://git.savannah.gnu.org/cgit/hurd/hurd.git/tree/term/users.c#n367

Zhaoming


Reply via email to