Hello all. I am trying to get qemu to spawn a pty terminal in a location which I control without needing to retrieve information of the PTY device a-posteriori from qemu. To this end i inspired myself in the functionality of socat, which allows PTY terminals to be spawned in a location specified by a command line argument. The way socat does is a bit cheating: It requests the PTY terminal the same way that qemu does, through openpty, and creates a symlink between the path specified by the user and the kernel given virtual terminal device.
In the following patch i was able to implement this functionality successfully and it works as intended. The problem is that for some reason when I send Ctrl-a-x through the pty the finalize method of the pty char dev does not get called, thus not removing the symlink. The finalize only is called when there is an error in the creation of the symlink like for example when the symlink already exists. This leads to a dangling symlink when qemu closes and the PTY is released. Is there a better way to guarantee that my unlink of the symlink is called when qemu closes? Am i not familiar with qemu code development so if i am doing something terrible please let me know.