Better handling of fds 0/1/2 #1233
                
     Open
            
            
          
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
I ran into this while working on what is now #1232.
mosh-serverdoes not adequately handle the problem of standard file descriptors being closed. In my development, er, over two years ago, I ran into a situation wheremosh-serverhad started with fd 2 closed, it opened/dev/urandomon fd 2, and then later reopened fd 2 on/dev/null. Then, when it tried to actually read fd 2 to get entropy, it got 0 bytes instead, and got caught in a never-ending loop involving an exception being caught and the action being retried. I don't remember for sure, but I think that left the Mosh session hung inmosh.This work does 3 things:
CryptoExceptionthrown on failure to read fatal-- there's no point in continuing if we can't get a random seed./dev/nullon the closed fd,dup2()it to 0/1/2, and then close the temporary file. Oops.I can't now reproduce the hang, unfortunately. Both Mosh and my OSes have changed since hten. I tried to write a test for this issue, but between not being able to reproduce the problem and
mosh-serverbeing difficult to keep track of because it double-forks, I've given up for now. Should any of you doubt there's a problem,strace -o strace.log -f mosh-server new 2>&-will convince you fairly quickly. And while I didn't experience any actual crypto failure, even the possibility of confused crypto code is a rather bad smell.(Plus, we burned a couple of weeks chasing this problem down at $WORK once.)