I have a question about the 'scope' of the USE command.
I have been digging around in the yottadb source to track down some IO quirks. See my other posts about that. But my initial idea for a fix has revealed some other issues.
In the yottadb code, there is a function called resetterm(), which sends a 'reset' state to the TTY system. This function is called many places, for example before getting user input from the command line, at the time of an interrupt, during rundown code, and when exiting yottadb. With this sense of resetting the terminal it makes sense for resetterm() to hold an INITIAL state (before any yottadb changes), to be used in terminal restoration.
But resetterm() is also called after iott_rdone(), which is code for reading one character (i.e. READ *X), and iott_readfl(), which is code for reading a fixed length (i.e. READ X#3). These forms of reading require special interaction with the IO system, so the TTY system has to be put into a special mode. And to turn off this special mode, resetterm() is used. The problem is that this revokes the last USE command. E.g. see code below:
USE $P:(NOCANONICAL)
READ *X
<----- resetterm() at end of READ puts TTY back to initial state here. USE revoked.
READ Y
In my other message thread, when I detected that resetterm was revoking the last USE command, my solution was to save the state of the last USE command, such that resetterm would use that during resets. But the side effect of this is that those times where one would expect it to be a true reset to state prior to yottadb changes, instead one gets only the last USE state. For example, when exiting yottadb, the initial state is not restored and the linux command line prompt might not have ECHO enabled.
The specified device remains current until such time as a new
USE command is executed.
QUESTION:
Under what circumstances would it be proper to restore the INITIAL state (before any yottadb changes). And what about the following circumstances?
- A program is running and has changed the USE parameters for $P. The user then breaks execution returning to the command prompt. Should USE settings be reset to INITIAL state? I would say "yes".
- What code exits back to the command prompt normally, without crash etc. Should the USE state of the code be continued? I would say "no".
- If the user types a USE command at the command prompt, and presses enter. And then types an additional command. Should that USE settings still be active? Or should a reset be done after each command? I'm not sure on this one.
Right now, I think I am going to leave resetterm() alone, and not change its functionality in the codebase I am editing. Instead, in the special circumstances of iott_rdone() and iott_readfl(), I will save off the TTY state at the beginning of the command, and restore that state at the end of the command instead of calling resetterm().
Comments and feedback will be appreciated.
Kevin