diff --git a/Sessions/MCPSession.m b/Sessions/MCPSession.m index d1ba31b62..3ec869bd6 100644 --- a/Sessions/MCPSession.m +++ b/Sessions/MCPSession.m @@ -194,15 +194,12 @@ - (BOOL)_runCommand:(NSString *)cmdline skipHistoryRecord: (BOOL) skipHistoryRec [self _runSSHWithArgs:cmdline]; } else if ([cmd isEqualToString:@"ssh-copy-id"]) { [self _runSSHCopyIDWithArgs:cmdline]; - } else { + } else if (![cmd isEqualToString:@""]) { // Manually set raw mode for some commands, as we cannot receive control any other way. + [_device closeReadline]; if ([cmd isEqualToString:@"less"] || [cmd isEqualToString:@"vim"]) { self.device.rawMode = true; - if ([cmd isEqualToString:@"less"]) { - // Less needs a different carriage return. - // This is part of the control by apps that we need to define manually. - self.device.autoCR = TRUE; - } + self.device.autoCR = TRUE; } [self setActiveSession]; _currentCmd = cmdline; @@ -219,7 +216,8 @@ - (BOOL)_runCommand:(NSString *)cmdline skipHistoryRecord: (BOOL) skipHistoryRec _currentCmd = nil; ios_waitpid(_pid); ios_releaseThreadId(_pid); - + self.device.autoCR = FALSE; + fclose(tty); tty = nil; [_cmdStream close]; @@ -340,7 +338,7 @@ - (void)kill return; } else if (_childSession) { [_childSession kill]; - } else { + } else if (_cmdStream) { [self setActiveSession]; ios_kill(); } @@ -374,6 +372,11 @@ - (void)handleControl:(NSString *)control if ([control isEqualToString:ctrlD]) { // We give a chance to the session to capture the new stdin, as it may have changed. [self setActiveSession]; + if (_cmdStream != NULL) { + [_cmdStream close]; + _cmdStream = NULL; + _cmdStream = [_device.stream duplicate]; + } ios_setStreams(_cmdStream.in, _cmdStream.out, _cmdStream.out); return; } @@ -390,6 +393,7 @@ - (void)handleControl:(NSString *)control [_tokioSignals signalCtrlC]; _tokioSignals = nil; } else { + [self setActiveSession]; ios_kill(); } }