I am writing a compatibility layer for an old school serial terminal in C. It doesn't support normal ANSI escape sequences and such so I am using a program to be a middleman between bash and the terminal, converting the escape codes manually. Termcap didn't help for my Televideo 910.
My code forks, doing an execlp to run bash in the child process. I have connected it to a pty, from which I read and write to the master file descriptor in the parent process to get characters from bash and to send it the keypresses from the terminal.
It largely works, the only issue is that when I use it to try to ssh into another machine, the login prompt is not read in the same way as all other bash outputs, it goes to the controlling terminal for some reason. Trying to be very clear here, on the window I run my executable ./TVI.out on, thats otherwise just for my debug printf's, the password prompt for ssh appears there. I have no code that is mirroring output from bash, it just somehow finds it and puts it there. Entering the ssh password there finishes the connection and the ssh connection appears on the terminal as expected. I just want the password login screen to be on the terminal itself as well.
In gdb I encountered a SIGTTOU signal, which I had guessed could be the culprit, but I put an empty signal handler on it to try and skip it, though this did not work. I also put a SIGTTIN handler just in case, but no. A quick look over other signals did not point me to an obvious signal that still needed to be handled.
I tried writing all output from the bash process to a log file and examining that, the password prompt does not get written to it, but after a login in that controlling terminal window, it does log the last login time and further outputs.
I use openpty to launch a pty for communicating with the child bash process, I am unsure if that could be part of the problem.
So What I found to be the issue was I needed to setsid the child process. I ran into issues doing that however, so I changed the executed process to be "setsid -c /bin/login" instead of just "/bin/login" and that seemed to work.