registering
06-15-2003, 06:42 PM
Hello all,
I have a problem where my application creates a child before doing anything else and the child resets
terminal settings so it can control a serial device in raw mode. Now, what happens is when my parent
dies, the shell terminal settings are in raw mode, as if the PARENT had reset the settings, or as if
the CHILD reset the parent's terminal!
I have the parent calling setsid, and it does not return error, which I believe means the child has
no controlling terminal. The child then continues to change the terminal settings, control the serial
device, and live happily ever after. However meanwhile in the parent's shell, it's in raw mode which
is ugly, so they must always type "reset", which is not very nice.
My parent does nothing but fork(), make sure no errors occurred, then sleep(1) and return (1).
The problem seems to stem from a mystery I discovered in Linux that might be a UNIX thing, I dunno, but
I found the only way to get my serial port settings correct was to set them, then do this:
tcgetattr(1,&port->ser_old_stdout_tio); // we gotta do this - there is a Linux bug
tcsetattr(1,TCSANOW,&port->ser_newtio); // make stdout settings like serial port settings
tcgetattr(0,&port->ser_oldstdtio); // get stdin settings for restoration ...
tcgetattr(0,&port->ser_newstdtio); // ... and use them as a basis for changes
tcsetattr(0,TCSANOW,&port->ser_newstdtio); // set the new attributes immediately
Now why would the above mess-up the parent's stdin/stdout? If I remove this code the port isn't set-up
properly, but if I keep it in, whoever starts my program must type "reset" after executing it, or the
parent can do a "system("reset");" but there must be a better way. Maybe I misunderstand who controls
whose terminal? I open the serial port in O_NOCTTY and I thought setsid gaurantees the child has no
controlling terminal....
Any ideas?
I have a problem where my application creates a child before doing anything else and the child resets
terminal settings so it can control a serial device in raw mode. Now, what happens is when my parent
dies, the shell terminal settings are in raw mode, as if the PARENT had reset the settings, or as if
the CHILD reset the parent's terminal!
I have the parent calling setsid, and it does not return error, which I believe means the child has
no controlling terminal. The child then continues to change the terminal settings, control the serial
device, and live happily ever after. However meanwhile in the parent's shell, it's in raw mode which
is ugly, so they must always type "reset", which is not very nice.
My parent does nothing but fork(), make sure no errors occurred, then sleep(1) and return (1).
The problem seems to stem from a mystery I discovered in Linux that might be a UNIX thing, I dunno, but
I found the only way to get my serial port settings correct was to set them, then do this:
tcgetattr(1,&port->ser_old_stdout_tio); // we gotta do this - there is a Linux bug
tcsetattr(1,TCSANOW,&port->ser_newtio); // make stdout settings like serial port settings
tcgetattr(0,&port->ser_oldstdtio); // get stdin settings for restoration ...
tcgetattr(0,&port->ser_newstdtio); // ... and use them as a basis for changes
tcsetattr(0,TCSANOW,&port->ser_newstdtio); // set the new attributes immediately
Now why would the above mess-up the parent's stdin/stdout? If I remove this code the port isn't set-up
properly, but if I keep it in, whoever starts my program must type "reset" after executing it, or the
parent can do a "system("reset");" but there must be a better way. Maybe I misunderstand who controls
whose terminal? I open the serial port in O_NOCTTY and I thought setsid gaurantees the child has no
controlling terminal....
Any ideas?